我被困住了,需要帮助。
我正在使用 python-daemon 包来守护程序。问题是我不知道如何启动和停止守护进程。
当我跑
python myscript.py start
一个新的进程被创建。但是,当我运行 stop 时,什么也没有发生。
# Setting logging configuration
logger = logging.getLogger("MyScript")
logger.setLevel(logging.DEBUG)
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
handler = logging.FileHandler("/tmp/myscript.log")
handler.setFormatter(formatter)
logger.addHandler(handler)
pid = daemon.pidlockfile.TimeoutPIDLockFile("/tmp/myscript.pid", 10)
context = daemon.DaemonContext(
#working_directory='/var/lib/foo',
umask=0o002,
pidfile=pid,
files_preserve=[handler.stream],
)
loop = True
def program_cleanup_test():
logger.info("Stopping loop")
loop = False
context.signal_map = {
signal.SIGTERM: program_cleanup_test,
signal.SIGHUP: 'terminate',
#signal.SIGUSR1: reload_program_config,
}
print "Running as a daemon"
with context:
while loop:
logger.info("0255")
time.sleep(5)