Centos 配置自定义 service

iBit程序猿 2020年12月02日 969次浏览

配置 demo.service

# vim /etc/systemd/system/demo.service

配置模板如下所示:

[Unit]
Description=Demo Service
Documentation=Your documentation location
After=network-online.target
Wants=network-online.target

[Service]
User=demo
Type=simple
ExecStart=Your startup script
ExecStop=/bin/kill -s QUIT $MAINPID
Restart=always
StandOutput=syslog

StandError=inherit

[Install]
WantedBy=multi-user.target

补充一下启动脚本 ExecStartDocumentation,修改并保存。

刷新 Systemd

# systemctl daemon-reload

开启启动 demo

# systemctl enable demo

启动 demo

# systemctl start demo

重启 demo

# systemctl restart demo

停止 demo

# systemctl stop demo

查看 demo 的运行状态

# systemctl status demo