systemctl状态显示无效死机 [英] systemctl status shows inactive dead

查看:48
本文介绍了systemctl状态显示无效死机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写自己的(简单)systemd服务,该服务可以完成一些简单操作(例如,使用shell脚本将数字1到10写入文件).我的服务文件如下所示.

I am trying to write my own (simple) systemd service which does something simple.( Like writing numbers 1 to 10 to a file, using the shell script). My service file looks like below.

[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脚本.

This is my shell script.

#!/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显示以下输出.

For some reason, the service doesn't come up and systemctl is showing the below output.

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

曾经试图找出过去两天出了什么问题.

Been trying to figure out what went wrong for the last 2 days.

推荐答案

  • 您已经设置了 Type = Forking ,但是您的服务无法正常工作.尝试Type = oneshot
  • 您有一个&"您的 ExecStart 行,这不是必需的.
  • 该服务已被 disabled 禁用,这意味着它没有启用在启动时启动.您应该运行 systemctl enable hello 将其设置为在启动时启动.
    • You have set Type=Forking, but your service doesn't work. Try Type=oneshot
    • You have a "&" your ExecStart line, which is not necessary.
    • The service is disabled, which means it was not enabled to start at boot. You should run systemctl enable hello to set it to start at boot.
    • 您可以检查 man systemd.directives 来查找可以在 unit 文件中使用的所有指令的索引.

      You can check man systemd.directives to find an index of all the directives that you can use in your unit files.

      这篇关于systemctl状态显示无效死机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆