Windows service template added
--HG-- branch : aspn
This commit is contained in:
25
src/winsc.py
Normal file
25
src/winsc.py
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
# http://code.activestate.com/recipes/59872-manipulating-windows-services/
|
||||||
|
|
||||||
|
import win32serviceutil
|
||||||
|
|
||||||
|
def service_info(action, service):
|
||||||
|
if action == 'stop':
|
||||||
|
win32serviceutil.StopService(service)
|
||||||
|
print '%s stopped successfully' % service
|
||||||
|
elif action == 'start':
|
||||||
|
win32serviceutil.StartService(service)
|
||||||
|
print '%s started successfully' % service
|
||||||
|
elif action == 'restart':
|
||||||
|
win32serviceutil.RestartService(service)
|
||||||
|
print '%s restarted successfully' % service
|
||||||
|
elif action == 'status':
|
||||||
|
if win32serviceutil.QueryServiceStatus(service)[1] == 4:
|
||||||
|
print "%s is running normally" % service
|
||||||
|
else:
|
||||||
|
print "%s is *not* running" % service
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
machine = 'cr582427-a'
|
||||||
|
service = 'Zope23'
|
||||||
|
action = 'start'
|
||||||
|
service_info(action, service)
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
# winservice.py
|
# winservice.py
|
||||||
|
# Recipe 551780 revision 3
|
||||||
|
|
||||||
from os.path import splitext, abspath
|
from os.path import splitext, abspath
|
||||||
from sys import modules
|
from sys import modules
|
||||||
@@ -45,8 +46,7 @@ class Service(win32serviceutil.ServiceFramework):
|
|||||||
def stop(self): pass
|
def stop(self): pass
|
||||||
|
|
||||||
def instart(cls, name, display_name=None, stay_alive=True):
|
def instart(cls, name, display_name=None, stay_alive=True):
|
||||||
'''
|
''' Install and Start (auto) a Service
|
||||||
Install and Start (auto) a Service
|
|
||||||
|
|
||||||
cls : the class (derived from Service) that implement the Service
|
cls : the class (derived from Service) that implement the Service
|
||||||
name : Service name
|
name : Service name
|
||||||
@@ -90,6 +90,7 @@ def instart(cls, name, display_name=None, stay_alive=True):
|
|||||||
#
|
#
|
||||||
|
|
||||||
# winservice_test.py
|
# winservice_test.py
|
||||||
|
|
||||||
from winservice import Service, instart
|
from winservice import Service, instart
|
||||||
|
|
||||||
class Test(Service):
|
class Test(Service):
|
||||||
|
|||||||
Reference in New Issue
Block a user