class EnvironmentEmulationService(object): ## constructor # @param host The host to connect # @param user The login user # @param password The login password def __init__(self, host=None, user=None, password=None): ## environment emulation runner self.__runner = EnvironmentEmulationRunner(EnvironmentEmulationServiceDaemon(host, user, password)) ## execute action # @param self The object pointer def action(self): self.__runner.do_action()
## TestDaemon # # The test daemon class class TestDaemon(object): ## constructor def __init__(self): self.stdin_path = self.stdout_path = self.stderr_path = "/dev/null" self.pidfile_timeout = 3 self.directory = os.path.expanduser("~/.dockerEE/") if not os.path.isdir(self.directory): os.mkdir(self.directory) self.pidfile_path = os.path.join(self.directory, "test_service_environment_emulation_runner.pid") ## the implementation of running application # @param self The object pointer def run(self): while True: time.sleep(1) ## the implementation of displaying status # @param self The object pointer # @return The status message def getStatus(self): return "OK" ## the implementation of reloading # @param self The object pointer def reload(self): print "reloaded" if __name__ == "__main__": daemon_runner = EnvironmentEmulationRunner(TestDaemon()) daemon_runner.do_action()
def _initApp(self): # initialize check variable self.__counter = 0 self.__check_del_app_file = file(os.path.expanduser("~/.dockerEE/test_service_service_daemon.check"), "w") ## the implementation of application specific destruction before service stop # @param self The object pointer def _delApp(self): os.remove(self.__check_del_app_file.name) ## exposed method of getting counter # @param self The object pointer # @return counter def getCount(self): return self.__counter ## exposed method of counting up counter # @param self The object pointer def countUp(self): self.__counter += 1 ## the implementation of displaying status # @param self The object pointer # @return The status message def getStatus(self): return "counter = " + str(self._getInstance().getCount()) ## the implementation of reloading # @param self The object pointer def reload(self): self._getInstance().countUp() if __name__ == "__main__": service = EnvironmentEmulationRunner(TestService()) service.do_action()