linux 7 自定义systemctl服务启动卡住,查询状态显示Active: activating (start) since Tue 2018-08-21 21:59:11 CST; 39s a
linux-dash
A beautiful web dashboard for Linux
项目地址:https://gitcode.com/gh_mirrors/li/linux-dash
免费下载资源
·
编写自定义systemctl脚本启动进程,卡顿了
查询进程状态时,显示
[root@VM67-redhat7 sfy]# systemctl status simple
● simple.service - sfy test
Loaded: loaded (/usr/lib/systemd/system/simple.service; disabled; vendor preset: disabled)
Active: activating (start) since Tue 2018-08-21 22:04:31 CST; 19s ago
Control: 28287 (bash)
CGroup: /system.slice/simple.service
├─28287 /usr/bin/bash -c /home/sfy/sfy.sh
└─28329 sleep 1
Aug 21 22:04:31 VM67-redhat7.2 systemd[1]: Starting sfy test...
经查找资料发现simple.service脚本存在一些问题,type类型存在问题,现将正确的脚本,2种方式贴在下面
simple.service
[Unit]
Description=sfy test
After=syslog.target network.target
[Service]
Type=simple
ExecStart=/usr/bin/bash -c "/home/sfy/simple.sh"
[Install]
WantedBy=multi-user.target
simple.sh
while :
do
echo `date` >> /home/sfy/log
sleep 1
done
执行启动并查询结果如下
[root@VM67-redhat7 system]# systemctl start simple
[root@VM67-redhat7 system]# systemctl status simple
● simple.service - sfy test
Loaded: loaded (/usr/lib/systemd/system/simple.service; disabled; vendor preset: disabled)
Active: active (running) since Tue 2018-08-21 22:09:25 CST; 10s ago
Main PID: 28927 (bash)
CGroup: /system.slice/simple.service
├─28927 /usr/bin/bash -c /home/sfy/simple.sh
└─28949 sleep 1
Aug 21 22:09:25 VM67-redhat7.2 systemd[1]: Started sfy test.
Aug 21 22:09:25 VM67-redhat7.2 systemd[1]: Starting sfy test...
第二种方式 fork.service
[Unit]
Description=sfy test
After=syslog.target network.target
[Service]
Type=forking
ExecStart=/usr/bin/bash -c "/home/sfy/fork.sh"
PrivateTmp=true
SuccessExitStatus=143
fork.sh
echo `date` >> /home/sfy/log
sleep 1
systemctl脚本放在 /usr/lib/systemd/system 目录下,生效执行 systemctl daemon-reload 命令
总结:主要是service脚本中Type参数设置不同导致的(脚本是否循环)
GitHub 加速计划 / li / linux-dash
10.39 K
1.2 K
下载
A beautiful web dashboard for Linux
最近提交(Master分支:2 个月前 )
186a802e
added ecosystem file for PM2 4 年前
5def40a3
Add host customization support for the NodeJS version 4 年前
更多推荐
已为社区贡献3条内容
所有评论(0)