我已经玩了一小段时间了,但是我仍然坚持创建一个服务来运行一个脚本。我试图运行的脚本如下所示。
#!/bin/sh
while true
do
sudo bbb-record --rebuildall
sleep 300
done我尝试为这个程序创建一个守护进程,运行如下:
[Unit]
Description=bbb-rebuild
[Service]
ExecStart=/home/sysadmin/rebuild
Restart=always
[Install]
WantedBy=multi-user.target
exit=0 我得到了错误信息
==== AUTHENTICATION COMPLETE ===
Failed to start rebuild.service: Unit rebuild.service is not loaded properly: Invalid argument.
See system logs and 'systemctl status rebuild.service' for details.
after checking status
Apr 22 16:46:55 bbb2 systemd[1]: rebuild.service: Unit entered failed state.
Apr 22 16:46:55 bbb2 systemd[1]: rebuild.service: Failed with result 'exit-code'.
Apr 22 16:46:55 bbb2 systemd[1]: rebuild.service: Service hold-off time over, scheduling restart.
Apr 22 16:46:55 bbb2 systemd[1]: Stopped bbb-rebuild.
Apr 22 16:46:55 bbb2 systemd[1]: rebuild.service: Start request repeated too quickly.
Apr 22 16:46:55 bbb2 systemd[1]: Failed to start bbb-rebuild.
Apr 22 16:46:55 bbb2 systemd[1]: rebuild.service: Unit entered failed state.
Apr 22 16:46:55 bbb2 systemd[1]: rebuild.service: Failed with result 'start-limit-hit'.
Apr 22 16:47:22 bbb2 systemd[1]: [/etc/systemd/system/rebuild.service:12] Missing '='.发布于 2020-04-22 16:47:04
您最好使用系统定时器来实现这一点。
创建一个名为systemd服务rebuild.timer的计时器
# nano /etc/systemd/system/rebuild.timer
[Unit]
Description=Start script every hour
[Timer]
OnCalendar=hourly
[Install]
WantedBy=timers.target将脚本编辑为以下内容
#!/bin/sh
bbb-record --rebuildall确保脚本是可运行的chmod +x /home/sysadmin/rebuild
编辑系统d服务以删除restart=always和exit 0
[Unit]
Description=bbb-rebuild
[Service]
ExecStart=/home/sysadmin/rebuild
[Install]
WantedBy=multi-user.target 然后,只需使用systemctl enable rebuild.timer启用系统定时器即可。
然后用systemctl status rebuild.timer检查计时器是否启用。
https://askubuntu.com/questions/1229509
复制相似问题