How to use the aj.plugins.services.api.Service function in aj

To help you get started, we’ve selected a few aj examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ajenti / ajenti / plugins / services / managers / systemd_manager.py View on Github external
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
github ajenti / ajenti / plugins / services / managers / upstart_manager.py View on Github external
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
github ajenti / ajenti / plugins / services / managers / sysv_manager.py View on Github external
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
github ajenti / ajenti / plugins / supervisor / api.py View on Github external
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