diff --git a/salt/utils/__init__.py b/salt/utils/__init__.py index ff3044e352..132d4ee7c4 100644 --- a/salt/utils/__init__.py +++ b/salt/utils/__init__.py @@ -80,10 +80,28 @@ def daemonize(): 0, 'runas', executablepath, - os.path.join(pypath[0], os.sep, pypath[1], 'Lib\\site-packages\\salt\\utils\\salt-minion-service.py'), + os.path.join(pypath[0], os.sep, pypath[1], 'Lib\\site-packages\\salt\\utils\\saltminionservice.py'), os.path.join(pypath[0], os.sep, pypath[1]), 0 ) - sys.exit(0) + sys.exit(0) + else: + import saltminionservice + import win32serviceutil + import win32service + import winerror + servicename = 'salt-minion' + try: + status = win32serviceutil.QueryServiceStatus(servicename) + except win32service.error, details: + if details[0]==winerror.ERROR_SERVICE_DOES_NOT_EXIST: + saltminionservice.instart(saltminionservice.MinionService, servicename, 'Salt Minion') + sys.exit(0) + if status[1] == win32service.SERVICE_RUNNING: + win32serviceutil.StopServiceWithDeps(servicename) + win32serviceutil.StartService(servicename) + else: + win32serviceutil.StartService(servicename) + sys.exit(0) try: pid = os.fork() if pid > 0: diff --git a/salt/utils/saltminionservice.py b/salt/utils/saltminionservice.py new file mode 100644 index 0000000000..49c907e10f --- /dev/null +++ b/salt/utils/saltminionservice.py @@ -0,0 +1,36 @@ +from winservice import Service, instart +import win32serviceutil +import win32service +import winerror +import os +import salt +import sys + +class MinionService(Service): + def start(self): + self.runflag=True + self.log("Starting the Salt Minion") + minion = salt.Minion() + minion.start() + while self.runflag: + pass + #self.sleep(10) + #self.log("I'm alive ...") + def stop(self): + self.runflag=False + self.log("Shutting down the Salt Minion") + +if __name__ == '__main__': + servicename = 'salt-minion' + try: + status = win32serviceutil.QueryServiceStatus(servicename) + except win32service.error, details: + if details[0]==winerror.ERROR_SERVICE_DOES_NOT_EXIST: + instart(MinionService, servicename, 'Salt Minion') + sys.exit(0) + if status[1] == win32service.SERVICE_RUNNING: + win32serviceutil.StopServiceWithDeps(servicename) + win32serviceutil.StartService(servicename) + else: + win32serviceutil.StartService(servicename) +