Ubuntu服务Upstart或SystemD,Django开发服务器即服务 [英] Ubuntu service Upstart or SystemD, Django development server as Service
问题描述
我一直在研究Python&使用Ubuntu 16.01的Django框架已有一段时间.由于我将Django与Q系统(Celery)和其他一些Enhancement Apps一起使用.每次尝试运行所有应用程序时,都需要运行开发服务器"{python manage.py runserver}",然后运行Celery Worker"{celery -A filename worker -l info}".每次工作时,我都会花几分钟时间进入目录并启动它.我四处浏览并提出将其设置为服务的想法.例如,服务名称:"pyd".我只需要运行"{sudo pyd start}"-> Django Development Server和Celery即可启动,如果我运行"{sudo pyd stop}"-> Django&芹菜会停止.
I've been working around with Python & Django Framework for a while with Ubuntu 16.01. Since I used Django with Q system (Celery) and some others Enhancement Apps. When I try to run all the apps each time, I need to run development server "{python manage.py runserver}", then running Celery Worker "{celery -A filename worker -l info}". Each time I working, it takes me minutes to enter the directory and start it up. I surf around and come up with the idea of setup it as service. Example, service name: "pyd". I just need to run "{sudo pyd start}" -> then Django Development Server and Celery will start, and if I run "{sudo pyd stop}" -> then Django & Celery will stop.
我尝试四处搜索,结果让我在"Upstart"和"Systemd"之间感到困惑.
I try to search around, and things start to confuse me between "Upstart" and "Systemd".
有人可以建议我如何使Django和Celery as Service在Ubuntu中运行吗?在新贵"和"Systemd"哪个更好?
Could any one suggest, me how to make both Django and Celery as Service run in Ubuntu ? between "Upstart" & "Systemd" which one is better ??
表示喜欢示例的源代码.
Source code to indicate sample is appreciated.
谢谢
推荐答案
您可以使用Upstart来做到这一点.
You can use Upstart to do this.
安装后,转到目录/etc/init/
.创建文件 xyz.conf
并添加以下行:
Post installation, go to the directory /etc/init/
.
Create a file xyz.conf
and add the lines:
cd /path/to/your/manage.py/file
exec python manage.py runserver & celery -A filename worker -l info
如果您使用的是virtualenv,请在上述内容之前添加以下几行:
If you are using a virtualenv, add the following lines before the above:
pre-start script
#activate virtual environment
source env-name/bin/activate
end script
现在,您可以通过发出命令 sudo start xyz
来启动Django Dev Server和Celery作为服务,通过发出 sudo stop xyz
来停止它并检查其状态发出 sudo status xyz
.
Now, you can start Django Dev Server and Celery as a service by issuing the commands, sudo start xyz
, stop it by issuing sudo stop xyz
and check status of your service by issuing sudo status xyz
.
xyz.conf
将登录到/var/log/upstart/xyz.log
.您可以使用以下命令查看日志: sudo tail -f/var/log/upstart/xyz.log
.
xyz.conf
will log into /var/log/upstart/xyz.log
. You can view logs with the following command: sudo tail -f /var/log/upstart/xyz.log
.
这篇关于Ubuntu服务Upstart或SystemD,Django开发服务器即服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!