Python on Windows Help

M

msmith

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

Mike Driscoll

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)

I would recommend cross-posting this to the PyWin32 mailing list.
They'll either know what to do or tell you you can't. You can sign up
here: http://mail.python.org/mailman/listinfo/python-win32

Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,962
Messages
2,570,134
Members
46,692
Latest member
JenniferTi

Latest Threads

Top