我有一个脚本来更新我的谷歌驱动器。我制作了一个系统单元来运行这个脚本,还有一个计时器,它每10秒运行一次,两者都能工作。然而,当我与互联网断开连接时,脚本就会失败,即使互联网恢复运行,系统也会停止运行。是否有任何方法可以使systemd继续运行脚本,或者是否有方法让systemd只在有互联网连接的情况下运行脚本?
这是文件
/etc/system/system/grive.service:
[Unit]
Description=Syncronize google drive folder
[Service]
User=my_name
ExecStart=/home/my_name/bin/update-grive/etc/systemd/system/grive.timer:
[Unit]
Description=Timer for how often to syncronize google drive folder
[Timer]
OnUnitActiveSec=10s
OnBootSec=10s
[Install]
WantedBy=timers.target/home/my_name/bin/update-grive:
#!/usr/bin/env bash
cd /home/my_name/gdrive
grive发布于 2017-03-30 05:21:46
将Restart=always添加到服务单元,这样systemd将在服务崩溃时继续打开服务。
另外,您应该使用OnUnitInactiveSec而不是OnUnitActiveSec。
OnUnitInactiveSec=10s (或20多岁)将在服务停止10秒后启动。这样你就可以确保它不会被打两次电话,并可能避免被禁止为DOSing谷歌。
发布于 2018-03-03 12:26:45
确保将准确度设置为秒,如下所示:
AccuracySec=1s根据文件:
AccuracySec=指定计时器所需的精度。默认为1s。来源:https://www.freedesktop.org/software/systemd/man/systemd.timer.html#Description
在您的.timer文件中执行此操作。
我和这件事斗争了很久了。
发布于 2017-03-30 05:21:20
在[Service]下添加:
Restart=always
RestartSec=10https://unix.stackexchange.com/questions/354729
复制相似问题