Пример #1
0
 def __init__(self, context):
     self.bus = None
     try:
         self.upstart = UpstartSystem()
     except:
         self.bus = DirectUpstartBus()
         self.upstart = UpstartSystem(bus=self.bus)
Пример #2
0
 def __init__(self, context):
     self.bus = None
     try:
         self.upstart = UpstartSystem()
     except:
         self.bus = DirectUpstartBus()
         self.upstart = UpstartSystem(bus=self.bus)
Пример #3
0
 def __verify__(cls):
     try:
         UpstartSystem()
         return True
     except:
         try:
             UpstartSystem(bus=DirectUpstartBus())
             return True
         except:
             return False
Пример #4
0
class UpstartServiceManager(ServiceManager):
    id = 'upstart'
    name = 'Upstart'

    @classmethod
    def __verify__(cls):
        try:
            UpstartSystem()
            return True
        except Exception as e:
            try:
                UpstartSystem(bus=DirectUpstartBus())
                return True
            except Exception as e:
                return False

    def __init__(self, context):
        self.bus = None
        try:
            self.upstart = UpstartSystem()
        except Exception as e:
            self.bus = DirectUpstartBus()
            self.upstart = UpstartSystem(bus=self.bus)

    def __fix_name(self, name):
        return name.replace('_2d', '-').replace('_2e', '.')

    def list(self):
        for job_name in self.upstart.get_all_jobs():
            yield self.get_service(job_name)

    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 Exception as e:
            svc.running = False
        return svc

    def start(self, _id):
        try:
            UpstartJob(_id).start()
        except DBusException as e:
            raise ServiceOperationError(e)

    def stop(self, _id):
        try:
            UpstartJob(_id).stop()
        except DBusException as e:
            raise ServiceOperationError(e)

    def restart(self, _id):
        try:
            UpstartJob(_id).restart()
        except DBusException as e:
            raise ServiceOperationError(e)
Пример #5
0
class UpstartServiceManager(ServiceManager):
    id = 'upstart'
    name = 'Upstart'

    @classmethod
    def __verify__(cls):
        try:
            UpstartSystem()
            return True
        except:
            try:
                UpstartSystem(bus=DirectUpstartBus())
                return True
            except:
                return False

    def __init__(self, context):
        self.bus = None
        try:
            self.upstart = UpstartSystem()
        except:
            self.bus = DirectUpstartBus()
            self.upstart = UpstartSystem(bus=self.bus)

    def __fix_name(self, name):
        return name.replace('_2d', '-').replace('_2e', '.')

    def list(self):
        for job_name in self.upstart.get_all_jobs():
            yield self.get_service(job_name)

    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 start(self, _id):
        try:
            UpstartJob(_id).start()
        except DBusException as e:
            raise ServiceOperationError(e)

    def stop(self, _id):
        try:
            UpstartJob(_id).stop()
        except DBusException as e:
            raise ServiceOperationError(e)

    def restart(self, _id):
        try:
            UpstartJob(_id).restart()
        except DBusException as e:
            raise ServiceOperationError(e)
Пример #6
0
    def __verify__(cls):
        """
        Test if upstart system is used.

        :return: Response from Python module upstart.
        :rtype: bool
        """

        try:
            UpstartSystem()
            return True
        except Exception as e:
            try:
                UpstartSystem(bus=DirectUpstartBus())
                return True
            except Exception as e:
                return False
Пример #7
0
class UpstartServiceManager(ServiceManager):
    """
    Manager for deprecated upstart system.
    """

    id = 'upstart'
    name = 'Upstart'

    @classmethod
    def __verify__(cls):
        """
        Test if upstart system is used.

        :return: Response from Python module upstart.
        :rtype: bool
        """

        try:
            UpstartSystem()
            return True
        except Exception as e:
            try:
                UpstartSystem(bus=DirectUpstartBus())
                return True
            except Exception as e:
                return False

    def __init__(self, context):
        self.bus = None
        try:
            self.upstart = UpstartSystem()
        except Exception as e:
            self.bus = DirectUpstartBus()
            self.upstart = UpstartSystem(bus=self.bus)

    def __fix_name(self, name):
        return name.replace('_2d', '-').replace('_2e', '.')

    def list(self):
        """
        Generator of all jobs in upstart.

        :return: Service object
        :rtype: Service
        """

        for job_name in self.upstart.get_all_jobs():
            yield self.get_service(job_name)

    def get_service(self, _id):
        """
        Get informations from module upstart for one specified job.

        :param _id: Job name
        :type _id: string
        :return: Service object
        :rtype: Service
        """

        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 Exception as e:
            svc.running = False
        return svc

    def start(self, _id):
        """
        Basically start a job.

        :param _id: job name
        :type _id: string
        """

        try:
            UpstartJob(_id).start()
        except DBusException as e:
            raise ServiceOperationError(e)

    def stop(self, _id):
        """
        Basically stop a job.

        :param _id: job name
        :type _id: string
        """

        try:
            UpstartJob(_id).stop()
        except DBusException as e:
            raise ServiceOperationError(e)

    def restart(self, _id):
        """
        Basically restart a job.

        :param _id: job name
        :type _id: string
        """

        try:
            UpstartJob(_id).restart()
        except DBusException as e:
            raise ServiceOperationError(e)
Пример #8
0
def test_system():
    from upstart.system import UpstartSystem

    s = UpstartSystem()

    print("Version: %s" % (s.get_version()))

    current_priority = s.get_log_priority()
    print("Current priority: %s" % (current_priority))

    new_priority = 'debug'
    s.set_log_priority(new_priority)

    updated_priority = s.get_log_priority()
    print("Updated priority: %s" % (updated_priority))

    s.set_log_priority(current_priority)

    restored_priority = s.get_log_priority()
    print("Restored priority: %s" % (restored_priority))

    #    print(list(s.get_all_jobs()))
    s.emit('foo', {'aa': 55})
Пример #9
0
def show_upstart_jobs():
    s = UpstartSystem()
    return list(s.get_all_jobs())
Пример #10
0
def test_system():
    from upstart.system import UpstartSystem

    s = UpstartSystem()

    print("Version: %s" % (s.get_version()))

    current_priority = s.get_log_priority()
    print("Current priority: %s" % (current_priority))

    new_priority = 'debug'
    s.set_log_priority(new_priority)

    updated_priority = s.get_log_priority()
    print("Updated priority: %s" % (updated_priority))

    s.set_log_priority(current_priority)

    restored_priority = s.get_log_priority()
    print("Restored priority: %s" % (restored_priority))

#    print(list(s.get_all_jobs()))
    s.emit('foo', { 'aa': 55 })