def SvcDoRun(self): import servicemanager self._log.info("%s - Starting" % self._svc_name_) servicemanager.LogInfoMsg("%s - Starting" % self._svc_name_) try: # Config file name is hardcoded config_file = "config.cfg" # Try to find the configuration file looking up # from the script file # It's a messy kludge but I couldn't find better import os.path path = os.path.abspath(os.path.dirname(__file__)) last_path = path self._log.info("%s - Searching for config in (%s)" % (self._svc_name_, last_path)) while not os.access(path + "/" + config_file, os.R_OK): (path, _) = os.path.split(path) if path == last_path: last_path = None print "Not found aborting" break last_path = path self._log.info("%s - Searching for config in (%s)" % (self._svc_name_, last_path)) if last_path == None: self._log.error( "%s - Unable to locate configuration file (%s)" % (self._svc_name_, config_file)) servicemanager.LogErrorMsg( "%s - Unable to locate configuration file (%s)" % (self._svc_name_, config_file)) return # Change working directory os.chdir(last_path) # init python logging (Anything logged before that had been lost) logging.config.fileConfig(config_file) self._log.info("%s - Changing working directory to (%s)" % (self._svc_name_, last_path)) # Start self._log.info("%s - Starting Moniteur" % self._svc_name_) self.application = Moniteur(config_file) self.application.start() self._log.info("%s - Started" % self._svc_name_) servicemanager.LogInfoMsg("%s - Started" % self._svc_name_) while self.isAlive: time.sleep(5) self._log.info("%s - Stopping" % self._svc_name_) servicemanager.LogInfoMsg("%s - Stopping" % self._svc_name_) except: pass