service文件创建
nginx为例:新建 nginx.service
1
| vim /usr/lib/systemd/system/nginx.service
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| [Unit]
Description=nginx - high performance web server Documentation=https://nginx.org After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
ExecStart=/usr/local/nginx-1.24.0/sbin/nginx
ExecReload=/usr/local/nginx-1.24.0/sbin/nginx -s reload
ExecStop=/usr/local/nginx-1.24.0/sbin/nginx -s stop
ExecQuit=/usr/local/nginx-1.24.0/sbin/nginx -s quit
PrivateTmp=true
RestartSec=5s
[Install]
WantedBy=multi-user.target
|
完成后重新加载 systemd
守护进程配置文件
systemctl常用运行命令
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| systemctl daemon-reload
systemctl start xxx.service systemctl stop xxx.service systemctl enable xxx.service systemctl disable xxx.service systemctl restart xxx.service systemctl status xxx.service
systemctl list-units --type=service systemctl --failed systemctl list-unit-files|grep enabled systemctl reset-failed
|
参考文档
https://www.freedesktop.org/software/systemd/man/latest/systemd.unit.html
https://www.ruanyifeng.com/blog/2016/03/systemd-tutorial-commands.html