How to package a Python daemon with setuptools

自古美人都是妖i 提交于 2019-12-18 15:51:54

问题


How do you package a Python app with setuptools so that when it's installed (e.g. via setup.py or pip), it places a daemon script in the appropriate location, starts it, and marks it to automatically start at boot time?

In my case, my code only works with Linux, so I only care about installing the daemon in Linux environments (specifically Ubuntu).

I've found several posts describing how to easily create Python daemons, but I can't seem to find anything describing how you'd install them in a production environment so that they'd be treated as any other normal daemon or service.

I know Ubuntu and some other distros keep their daemons in /etc/init.d, and I know how to use setuptools to copy files to specific locations on the filesystem, so would it be safe to copy or symlink my script to /etc/init.d and then run chkconfig to set it's runtime, or is there a more safe distribution-neutral way of installing daemons?


回答1:


This would be better handled by creating an appropriate package for the distro (in the case of Ubuntu, a .deb) since you can't guarantee the location of the startup scripts across distros. For example, arch linux uses /etc/rc.d/. Also, copying to locations like that will require root access (which I don't believe is necessarily required to install python packages) and may not be easily reversible when uninstalling.

I would suggest that you create a normal setupttools installation and then package it into a deb with a link to /etc/init.d.



来源:https://stackoverflow.com/questions/9722455/how-to-package-a-python-daemon-with-setuptools

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!