记录下这次实践,避免以后遗忘
确保服务器引导时自动启动Gunicorn,如果Gunicorn崩溃则自动重启
#gunicorn可执行文件所在位置
/root/venv/pythonTDD-env/bin/gunicorn
#Systemd脚本保存位置,所写的脚本要以.service结尾
/etc/systemd/system/
编写脚本:pythonTDD.service
[Unit]
Description=Gunicorn server for pythonTDD
[Service]
Restart=on-failure #指明在进程崩溃时自动重启进程
User=tu #指明启动进程的用户身份
#项目的工作目录,manage.py所在的目录
WorkingDirectory=/project/pythonTDD/PythonTDD/superlists
#要执行的进程
ExecStart=/root/venv/pythonTDD-env/bin/gunicorn --bind unix:/tmp/pythonTDD.socket superlists.wsgi:application
[Install]
#告诉systemd,在引导时启动这个服务
WantedBy=multi-user.target
了解systemd可以看这篇文章:
centos7的systemd服务详解
#必须先执行这个命令,让systemd加载新的配置文件
(pythonTDD-env) [root@bogon superlists]# systemctl daemon-reload
#这个命令让systemd在引导时加载服务
(pythonTDD-env) [root@bogon superlists]# systemctl enable pythonTDD.service
Created symlink from /etc/systemd/system/multi-user.target.wants/pythonTDD.service to /etc/systemd/system/pythonTDD.service.
#这个命令启动服务
(pythonTDD-env) [root@bogon superlists]# systemctl start pythonTDD.service