If salt-minion is run with elevated privileges, then run the service installer directly

This is in anticipation of a Windows installer setting up the salt-service
This commit is contained in:
David Boucha 2012-01-08 17:14:33 -07:00
parent d7c1e37b6b
commit 4b815b1804
2 changed files with 56 additions and 2 deletions

View File

@ -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:

View File

@ -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)