我已设法在etc / systemd / system中安装守护进程服务,但我不确定两件事:
1.如果守护程序服务应该驻留在那里
2.如何在systemd中优雅地检查是否安装了守护程序服务?
1.如果守护程序服务应该驻留在那里
是的,它是.service位置。你应该放在这里的文件是:
mydeamon.service
[Unit]
Description=ROT13 demo service
After=network.target
StartLimitIntervalSec=0
[Service]
Type=simple
Restart=always
RestartSec=1
User=**YourUser**
ExecStart=**pathToYourScript**
[Install]
WantedBy=multi-user.target
你需要:
creating-a-linux-service-with-systemd
2.如何在systemd中优雅地检查是否安装了守护程序服务?
systemctl有一个is-active子命令:
systemctl is-active --quiet service
如果服务处于活动状态,则将退出状态为零,否则为非零,使其成为脚本的理想选择:
systemctl is-active --quiet service && echo Service is running