使用Systemd确保引导时启动Gunicorn

记录下这次实践,避免以后遗忘

确保服务器引导时自动启动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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值