我正在尝试编写我自己的(简单的)systemd 服务来做一些简单的事情。(比如使用 shell 脚本将数字 1 到 10 写入文件)。 我的服务文件如下所示。
[Unit]
Description=NandaGopal
Documentation=https://google.com
After=multi-user.target
[Service]
Type=forking
RemainAfterExit=yes
ExecStart=/usr/bin/hello.sh &
[Install]
RequiredBy = multi-user.target
这是我的 shell 脚本。
#!/usr/bin/env bash
source /etc/profile
a=0
while [ $a -lt 10 ]
do
echo $a >> /var/log//t.txt
a=`expr $a + 1`
done
由于某种原因,服务没有启动,systemctl 显示以下输出。
root@TARGET:~ >systemctl status -l hello
* hello.service - NandaGopal
Loaded: loaded (/usr/lib/systemd/system/hello.service; disabled; vendor preset: enabled)
Active: inactive (dead)
Docs: https://google.com
过去 2 天一直在尝试找出问题所在。
最佳答案
- 您已设置
Type=Forking
,但您的服务无法正常工作。尝试Type=oneshot
- 您的
ExecStart
行有一个“&”,这不是必需的。 - 该服务
已禁用
,这意味着它未启用
以在引导时启动。您应该运行systemctl enable hello
将其设置为开机启动。
您可以检查 man systemd.directives
以找到您可以在 unit
文件中使用的所有指令的索引。
关于linux - systemctl status 显示 inactive dead,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39871883/