Hi all,
I have used the win32com libraries to set up a service called
MyService under Windows. So far, so good. Now I need to run multiple
copies of the service on the same machine. I also have that working.
For monitoring and logging, I'd like each instance of the service to
know it's own identity (MyService1, MyService2, etc.)
But I can't quite seem to grasp how to do this. In the code below,
the command line parameter "-i" gives the service an identity, but how
do I get the service to understand it's identity when it is started?
Many thanks!
class MyService(win32 serviceutil.Ser viceFramework):
"""NT Service."""
_svc_name_ = "MyService"
_svc_display_na me_ = "My Service"
_id_ = ''
def SvcDoRun(self):
provider = MyServiceClass( identifier=self ._id_)
provider.start( )
# now, block until our event is set...
win32event.Wait ForSingleObject (self.stop_even t,
win32event.INFI NITE)
# __init__ and SvcStop snipped
############### ############### ############### ############### ###############
if __name__ == '__main__':
import optparse
parser = optparse.Option Parser()
parser.add_opti on("-i", "--identifier", dest="identifie r")
(opts, args) = parser.parse_ar gs()
if opts.number is not None:
MyService._svc_ name_ += opts.identifier
MyService._svc_ display_name_ += opts.identifier
MyService._prov ider_id_ = opts.identifier
win32serviceuti l.HandleCommand Line(MyService,
customInstallOp tions="i:")
I have used the win32com libraries to set up a service called
MyService under Windows. So far, so good. Now I need to run multiple
copies of the service on the same machine. I also have that working.
For monitoring and logging, I'd like each instance of the service to
know it's own identity (MyService1, MyService2, etc.)
But I can't quite seem to grasp how to do this. In the code below,
the command line parameter "-i" gives the service an identity, but how
do I get the service to understand it's identity when it is started?
Many thanks!
class MyService(win32 serviceutil.Ser viceFramework):
"""NT Service."""
_svc_name_ = "MyService"
_svc_display_na me_ = "My Service"
_id_ = ''
def SvcDoRun(self):
provider = MyServiceClass( identifier=self ._id_)
provider.start( )
# now, block until our event is set...
win32event.Wait ForSingleObject (self.stop_even t,
win32event.INFI NITE)
# __init__ and SvcStop snipped
############### ############### ############### ############### ###############
if __name__ == '__main__':
import optparse
parser = optparse.Option Parser()
parser.add_opti on("-i", "--identifier", dest="identifie r")
(opts, args) = parser.parse_ar gs()
if opts.number is not None:
MyService._svc_ name_ += opts.identifier
MyService._svc_ display_name_ += opts.identifier
MyService._prov ider_id_ = opts.identifier
win32serviceuti l.HandleCommand Line(MyService,
customInstallOp tions="i:")
Comment