我正在尝试编写自己的(简单)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
一直试图找出最近两天出了什么问题。

最佳答案

  • 您已经设置了Type=Forking,但是您的服务无效。尝试Type=oneshot
  • 您的ExecStart行带有“&”,这不是必需的。
  • 服务是disabled,这意味着它不是在启动时启动的enabled。您应该运行systemctl enable hello将其设置为在启动时启动。

  • 您可以检查man systemd.directives来找到可以在unit文件中使用的所有指令的索引。

    关于linux - systemctl状态显示无效死机,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39871883/

    10-11 06:37