如何使用setuptools打包Python守护程序 [英] How to package a Python daemon with setuptools
问题描述
如何将Python应用程序与setuptools打包在一起,以便在安装时(例如,通过setup.py或pip)将守护程序脚本放置在适当的位置,将其启动,并将其标记为在启动时自动启动?
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?
就我而言,我的代码仅适用于Linux,因此我只关心在Linux环境(特别是Ubuntu)中安装守护程序.
In my case, my code only works with Linux, so I only care about installing the daemon in Linux environments (specifically Ubuntu).
我发现几个 描述如何轻松地创建Python守护程序,但是我似乎找不到任何描述您如何将它们安装在生产环境中以便将它们视为其他任何正常方法的内容.守护程序或服务.
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.
我知道Ubuntu和其他发行版将其守护程序保留在/etc/init.d中,并且我知道如何使用setuptools将文件复制到文件系统上的特定位置,因此将脚本复制或符号链接到它会安全吗? /etc/init.d,然后运行chkconfig设置运行时,还是有一种更安全的与分发无关的方式来安装守护程序?
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?
推荐答案
通过为发行版创建适当的程序包(在Ubuntu中为.deb),可以更好地解决此问题,因为您不能保证其中的位置.发行版中的启动脚本.例如,arch linux使用/etc/rc.d/.另外,复制到类似位置将需要root用户访问权限(我认为安装python软件包并不一定需要该访问权限),并且在卸载时可能不容易逆转.
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.
我建议您创建一个普通的setupttools安装,然后将其打包到带有/etc/init.d链接的deb中.
I would suggest that you create a normal setupttools installation and then package it into a deb with a link to /etc/init.d.
这篇关于如何使用setuptools打包Python守护程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!