Python win32serviceutil.HandleCommandLine() Examples

The following are 6 code examples of win32serviceutil.HandleCommandLine(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module win32serviceutil , or try the search function .
Example #1
Source File: DaemonCmd.py    From grease with MIT License 6 votes vote down vote up
def start(self):
        """Starting the daemon based on platform

        Returns:
            bool: start success

        """
        plat = platform.system().lower()
        if plat.startswith("win"):
            # Windows
            win32serviceutil.HandleCommandLine(AppServerSvc, argv=['grease', 'start'])
            return True
        elif plat.startswith("dar"):
            # MacOS
            if subprocess.call(["sudo", "launchctl", "load", "/Library/LaunchDaemons/net.grease.daemon.plist"]) != 0:
                return False
            return True
        elif plat.startswith("lin"):
            # Linux
            if subprocess.call(["sudo", "systemctl", "start", "grease"]) != 0:
                return False
            return True
        else:
            self.ioc.getLogger().error("Unrecognized operating system [{0}]".format(platform))
            return False 
Example #2
Source File: DaemonCmd.py    From grease with MIT License 6 votes vote down vote up
def stop(self):
        """Stopping the daemon based on the platform

        Returns:
            bool: stop success

        """
        plat = platform.system().lower()
        if plat.startswith("win"):
            # Windows
            win32serviceutil.HandleCommandLine(AppServerSvc, argv=['grease', 'stop'])
            return True
        elif plat.startswith("dar"):
            if subprocess.call(["sudo", "launchctl", "unload", "/Library/LaunchDaemons/net.grease.daemon.plist"]) != 0:
                return False
            # MacOS
            return True
        elif plat.startswith("lin"):
            # Linux
            if subprocess.call(["sudo", "systemctl", "stop", "grease"]) != 0:
                return False
            return True
        else:
            self.ioc.getLogger().error("Unrecognized operating system [{0}]".format(platform))
            return False 
Example #3
Source File: SMWinservice.py    From biometric-attendance-sync-tool with GNU General Public License v3.0 5 votes vote down vote up
def parse_command_line(cls):
        '''
        ClassMethod to parse the command line
        '''
        win32serviceutil.HandleCommandLine(cls) 
Example #4
Source File: resilient_circuits_cmd.py    From resilient-python-api with MIT License 5 votes vote down vote up
def windows_service(service_args, res_circuits_args):
    """Register a windows service"""
    try:
        import win32serviceutil
        from resilient_circuits.bin import service_wrapper

        if res_circuits_args:
            # Set the command line arguments to pass to "resilient-circuits.exe run"
            service_wrapper.irms_svc.setResilientArgs(res_circuits_args)

        sys.argv = sys.argv[0:1] + service_args
        win32serviceutil.HandleCommandLine(service_wrapper.irms_svc)
    except ImportError:
        LOG.error("Requires PYWIN32 Package. Please download and install from: "
                  "https://sourceforge.net/projects/pywin32/files/pywin32/") 
Example #5
Source File: cli.py    From opsbro with MIT License 5 votes vote down vote up
def __call_service_handler():
    def __ctrlHandler(ctrlType):
        return True
    
    
    from opsbro.windows_service.windows_service import Service
    win32api.SetConsoleCtrlHandler(__ctrlHandler, True)
    win32serviceutil.HandleCommandLine(Service) 
Example #6
Source File: windows_service.py    From opsbro with MIT License 5 votes vote down vote up
def ctrlHandler(ctrlType):
    return True

# if __name__ == '__main__':
#    win32api.SetConsoleCtrlHandler(ctrlHandler, True)
#    win32serviceutil.HandleCommandLine(Service)