Python on Windows Help
msmith at carilion.com
msmith at carilion.com
Thu Feb 21 11:09:10 EST 2008
I've written the following script based on information I have found on
the web. The purpose of the script is to start an HTTP listener on
the machine it's running on that will give status on a particular
service running on that system. I've tried to create this as a
service on the windows server it's running on, and it will install
fine. The problem I'm having is that the service will not stop when I
tell it to. Any help that anyone could provide would be greatly
appreciated. I'm new to python so please let me know if there is a
more efficient way to do what I'm trying to do. The code follows:
import win32service
import win32serviceutil
import wmi
from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler
class BlobCheck(win32serviceutil.ServiceFramework):
_svc_name_ = "BlobCheck"
_svc_display_name_ = "Epic Blob Checker"
_svc_description_ = "Checks the Epic Blob Service and Creates an HTTP
listener that can be polled for status"
def __init__(self,args):
win32serviceutil.ServiceFramework.__init__(self,args)
self.isAlive = True
def SvcDoRun(self):
import servicemanager
c = wmi.WMI()
while self.isAlive:
class RequestHandler(BaseHTTPRequestHandler):
def _writeheaders(self):
self.send_response(200)
self.send_header('Content-type', 'text/html')
self.end_headers()
def do_HEAD(self):
self._writeheaders()
def do_GET(self):
self._writeheaders()
running = c.Win32_Process (name="notepad.exe")
if running:
self.wfile.write("""<HTML><HEAD><TITLE>Monitor</TITLE></HEAD>
<BODY>Kool-Aid!!!</BODY></HTML>""")
else:
self.wfile.write("""<HTML><HEAD><TITLE>Monitor</TITLE></HEAD>
<BODY>Oh No!!!</BODY></HTML>""")
serveraddr = ('', 12345)
srvr = HTTPServer(serveraddr, RequestHandler)
srvr.handle_request()
def SvcStop(self):
import servicemanager
servicemanager.LogInfoMsg("aservice - Recieved stop signal")
self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
self.isAlive = False
if __name__ == '__main__':
win32serviceutil.HandleCommandLine(BlobCheck)
More information about the Python-list
mailing list