-
Notifications
You must be signed in to change notification settings - Fork 544
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[pebble][init] Add pebble service manager #3453
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# Copyright (C) 2024 Canonical Ltd., Arif Ali <[email protected]> | ||
|
||
# This file is part of the sos project: https://github.com/sosreport/sos | ||
# | ||
# This copyrighted material is made available to anyone wishing to use, | ||
# modify, copy, or redistribute it subject to the terms and conditions of | ||
# version 2 of the GNU General Public License. | ||
# | ||
# See the LICENSE file in the source distribution for further information. | ||
|
||
from sos.policies.init_systems import InitSystem | ||
from sos.utilities import shell_out | ||
|
||
|
||
class PebbleInit(InitSystem): | ||
"""InitSystem abstraction for Pebble systems""" | ||
|
||
def __init__(self, chroot=None): | ||
super(PebbleInit, self).__init__( | ||
init_cmd='pebble', | ||
list_cmd='services', | ||
query_cmd='pebble services', | ||
chroot=chroot | ||
) | ||
self.load_all_services() | ||
|
||
def parse_query(self, output): | ||
for line in output.splitlines()[1:]: | ||
if line.split()[2] == 'active': | ||
return 'active' | ||
return 'unknown' | ||
|
||
def load_all_services(self): | ||
svcs = shell_out(self.list_cmd, chroot=self.chroot).splitlines()[1:] | ||
for line in svcs: | ||
try: | ||
name = line.split()[0] | ||
config = line.split()[1] | ||
self.services[name] = { | ||
'name': name, | ||
'config': config, | ||
} | ||
except IndexError: | ||
pass | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To keep CodeQL happy, let's add a comment here explaining either how we got to this exception (header/foooter output?) or some similar note to future-us. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure, it was a copy-paste from the systemd one. So, I think we ought to fix tat one too ;) |
||
|
||
def is_running(self, name, default=False): | ||
try: | ||
svc = self.get_service_status(name) | ||
return svc['status'] == 'active' | ||
except Exception: | ||
return default | ||
|
||
# vim: set et ts=4 sw=4 : |
Check notice
Code scanning / CodeQL
Empty except Note