linux - systemctl status 显示 inactive dead

标签 linux sh systemd systemctl

我正在尝试编写我自己的(简单的)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/

相关文章:

linux - systemd: "Environment"指令设置 PATH

linux - waitpid() 是做什么的?

bash - vim 红色高亮 $( )

用于在 28 个内核上运行查询的 Bash 脚本

带有 --git-dir= 的 git 结果为 'not a git repository'

systemd - systemd的 'oneshot'和 'simple'服务类型有什么区别?

python - uWSGI 闲置后不重启

linux - 从标准输出和管道中提取参数

linux - 如何将用户输入解析为 bash 脚本

c - sendto 在发送时没有给出错误