问题描述
限时送ChatGPT账号..我想弄清楚如何发布我编写的 Python 程序,并让它能够在 Ubuntu 中作为服务运行.很像 Nginx,你可以在其中调用 sudo service nginx stop
和 sudo service nginx restart
.
I am trying to figure out how to release a Python program I wrote and have it be able to be run as a service in Ubuntu. Much like Nginx, where you can call sudo service nginx stop
and sudo service nginx restart
.
有没有办法让人们像这样安装我的程序?也许制作一个为他们做的 install.py
文件?我希望人们能够为这个项目克隆我的 Github 存储库,并通过几个步骤来安装该程序.
Is there any way to allow people to install my program like this? Perhaps making an install.py
file that does it for them? I want people to be able to clone my Github repository for this project and walk through a few steps to install the program.
推荐答案
您可以让它作为守护程序运行.这样做将允许您运行您提到的停止和重新启动命令.
You could have it run as a daemon. Doing this would allow you to run the stop and restart commands you mentioned.
例如:
python program.py 停止
python program.py restart
在 Ubuntu 中安装 python-daemon 包.
Install the python-daemon package in Ubuntu.
sudo apt-get install python-daemon
from daemon import Daemon
class YourDaemon(Daemon):
def run(self):
# Your code here
另一种方法是使用 supervisord 过程控制系统.
An alternative is to use the supervisord process control system.
这篇关于在 Ubuntu 中安装我的 Python 程序作为服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论