Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def list(self, units=None):
if not units:
units = [x.split()[0] for x in subprocess.check_output(['systemctl', 'list-unit-files', '--no-legend', '--no-pager', '-la']).splitlines() if x]
units = [x for x in units if x.endswith(b'.service') and b'@' not in x]
units = list(set(units))
cmd = ['systemctl', 'show', '-o', 'json', '--full', '--all'] + units
used_names = set()
unit = {}
for l in subprocess.check_output(cmd).splitlines() + [None]:
if not l:
if len(unit) > 0:
svc = Service(self)
svc.id = unit[b'Id']
svc.name, type = svc.id.rsplit(b'.', 1)
svc.name = svc.name.replace(b'\\x2d', b'\x2d')
svc.running = unit[b'SubState'] == b'running'
svc.state = b'running' if svc.running else b'stopped'
if svc.name not in used_names:
yield svc
used_names.add(svc.name)
unit = {}
elif b'=' in l:
k, v = l.split(b'=', 1)
unit[k] = v
def get_service(self, _id):
job = UpstartJob(_id, bus=self.bus)
svc = Service(self)
svc.id = _id
svc.name = self.__fix_name(_id)
try:
svc.state = job.get_status()['state']
svc.running = svc.state == 'running'
except:
svc.running = False
return svc
def get_service(self, _id):
svc = Service(self)
svc.id = svc.name = _id
try:
svc.running = self._run_action(_id, 'status')
svc.state = 'running' if svc.running else 'stopped'
except:
svc.running = False
return svc
def __make_service(self, info):
svc = Service(self)
svc.id = info['name']
svc.name = info['name']
svc.state = info['statename']
svc.running = svc.state == 'RUNNING'
return svc