nan*_*tor 15 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
Run Code Online (Sandbox Code Playgroud)
这是我的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
Run Code Online (Sandbox Code Playgroud)
由于某种原因,服务没有出现,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
Run Code Online (Sandbox Code Playgroud)
一直想弄清楚过去2天出了什么问题.有人可以帮我吗?
问候,nandanator
Mar*_*erg 21
Type=Forking,但您的服务无效.尝试
Type=oneshotExecStart线,这是没有必要的.disabled,这意味着它不是enabled在启动时启动.您应该运行systemctl enable hello以将其设置为在启动时启动.您可以检查man systemd.directives以查找可在unit文件中使用的所有指令的索引.
几点:
如果使用Type=forking,建议指定PidFile。
在您的情况下,Type=simple和,则ExecStart &不起作用。
用于systemctl start service-name启动服务
然后使用systemctl status service-name来检查其状态。如果未启动服务,则状态将为非活动/无效。
| 归档时间: |
|
| 查看次数: |
43200 次 |
| 最近记录: |