systemd中的守护进程服务

问题描述 投票:-1回答:1

我已设法在etc / systemd / system中安装守护进程服务,但我不确定两件事:

1.如果守护程序服务应该驻留在那里

2.如何在systemd中优雅地检查是否安装了守护程序服务?

linux systemd
1个回答
-1
投票

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

你需要:

  • 在User =之后设置您的实际用户名
  • 在ExecStart =中设置脚本的正确路径(通常是/ usr / bin /你可以把你的脚本放在这里)

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

test Service is running

© www.soinside.com 2019 - 2024. All rights reserved.