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