Python Daemon Packaging Best Practices

后端 未结 10 1462
没有蜡笔的小新
没有蜡笔的小新 2021-01-30 09:48

I have a tool which I have written in python and generally should be run as a daemon. What are the best practices for packaging this tool for distribution, particularly how sho

10条回答
  •  佛祖请我去吃肉
    2021-01-30 10:03

    There are many snippets on the internet offering to write a daemon in pure python (no bash scripts)

    http://www.jejik.com/articles/2007/02/a_simple_unix_linux_daemon_in_python/ looks clean...

    If you want to write your own,
    the principle is the same as with the bash daemon function.

    Basically:

    On start:

    • you fork to another process
    • open a logfile to redirect your stdout and stderr
    • Save the pid somewhere.

    On stop:

    • You send SIGTERM to the process with pid stored in your pidfile.
    • With signal.signal(signal.SIGTERM, sigtermhandler) you can bind a stopping procedure to the SIGTERM signal.

    I don't know any widely used package doing this though.

提交回复
热议问题