1、在/etc/systemd/system下建立.service文件,用于启动守护进程;
例如:
[Unit]
Description=gunicorn deamon
After=network.target
[Service]
Type=simple
User=root
Group=root
WorkingDirectory=/data/flask/task/spider_one/
ExecStart=/usr/bin/gunicorn get_price_api:server -w 4 -b 127.0.0.1:3652 --pid /data/flask/task/spider_one/log/gunicorn.pid --access-logfile /data/flask/task/spider_one/log/flaskaccess.log
#注意,这里的gunicorn命令不能是gunicorn配置文件,不能这样:gunicorn -c gunicorn.conf flask:app,这样无法启动守护进程,暂时还未找到原因
Restart=always
[Install]
WantedBy=multi-user.target
2、启动:systemctl start *.service
停止:systemctl stop *.service
重启:systemctl restart *.service(根据提示重启命令systemctl daemon-reload)
查看状态:systemctl status *.service