Ejemplo n.º 1
0
def signal_child(service, command):
    if command == 'stop':
        win32serviceutil.StopService(service)
    elif command == 'restart':
        win32serviceutil.RestartService(service)
    else:
        win32serviceutil.ControlService(service, control_codes[command])
Ejemplo n.º 2
0
    def Start(cls):
        state = cls.__CurrentState()
        if state is None:
            print("Service %s is not installed." % cls._svc_name_)
            return
        if state == win32service.SERVICE_RUNNING:
            print("Service %s started already." % cls._svc_name_)
            return

        if state == win32service.SERVICE_STOP_PENDING:
            win32serviceutil.WaitForServiceStatus(cls._svc_name_,
                                                  win32service.SERVICE_STOPPED,
                                                  30)
            state = win32service.SERVICE_STOPPED
        elif state == win32service.SERVICE_PAUSE_PENDING:
            win32serviceutil.WaitForServiceStatus(cls._svc_name_,
                                                  win32service.SERVICE_PAUSED,
                                                  30)
            state = win32service.SERVICE_PAUSED

        if state == win32service.SERVICE_STOPPED:
            win32serviceutil.StartService(cls._svc_name_)
        elif state == win32service.SERVICE_PAUSED:
            win32serviceutil.ControlService(
                cls._svc_name_, win32service.SERVICE_CONTROL_CONTINUE)

        win32serviceutil.WaitForServiceStatus(cls._svc_name_,
                                              win32service.SERVICE_RUNNING, 30)
        print("Service %s started successfully." % cls._svc_name_)
Ejemplo n.º 3
0
    def request_agent_status(self):
        """Invoked by a process that is not the agent to request the current agent dump the current detail
        status to the status file.

        This is used to implement the 'scalyr-agent-2 status -v' feature.

        @return: If there is an error, an errno that describes the error.  errno.EPERM indicates the current does not
            have permission to request the status.  errno.ESRCH indicates the agent is not running.
        """
        try:
            win32serviceutil.ControlService(_SCALYR_AGENT_SERVICE_,
                                            _SERVICE_CONTROL_DETAILED_REPORT_)
        except win32api.error as e:
            if e[0] == winerror.ERROR_SERVICE_NOT_ACTIVE:
                return errno.ESRCH
            elif e[0] == winerror.ERROR_SERVICE_DOES_NOT_EXIST:
                raise AgentNotRunning(
                    "The operating system indicates the Scalyr Agent Service is not installed.  "
                    "This indicates a failed installation.  Try reinstalling the agent."
                )
            else:
                raise e