我正在尝试编写自己的(简单)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
files.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)