我正在尝试编写我自己的(简单的) 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
我在试着找出前两天哪里出了问题。
发布于 2016-10-05 21:09:43
Type=Forking
,但您的服务不起作用。尝试让您的ExecStart
行有一个"&“,这是不必要的。disabled
,这意味着它不是enabled
启动时启动。您应该运行systemctl enable hello
以将其设置为在引导时启动。您可以检查man systemd.directives
,查找可以在unit
文件中使用的所有指令的索引。
发布于 2017-05-11 12:44:26
几点:
Type=forking
,建议指定PidFile,您使用的是Type=simple
,ExecStart不带&
即可。systemctl start service-name
启动服务systemctl status service-name
查看服务状态。如果服务未启动,状态将为inactive/dead。https://stackoverflow.com/questions/39871883
复制相似问题