在systemd下无人值守更新后自动重新启动服务

时间:2018-01-28 17:01:02

标签: linux ubuntu service auto-update systemd

我已经添加了一项服务(在这种情况下是Seafile),我希望它一直运行到systemd with a service file。它运行良好,但每次无人值守更新运行时,服务都会正常关闭 - 但永远不会重新启动。

这是服务文件的样子:

[Unit]
Description=Seafile
Requires=mysql.service
After=mysql.service

[Install]
WantedBy=multi-user.target

[Service]
Type=forking
User=root
Group=root
PermissionsStartOnly=true
ExecStart=/srv/start-seafile
TimeoutSec=600
Restart=on-failure

/ srv / start-seafile看起来像这样:

#!/bin/bash

cd /srv/seafile/XXXX/seafile-server-latest && nohup ./seafile.sh start

就像我说的 - 这完美无缺 - systemd可以启用/禁用/启动/停止服务,实现它是否已启动/运行 - 所以我必须正确地做某事。 / p>

# systemctl start seafile
# systemctl status seafile
* seafile.service - Seafile
   Loaded: loaded (/etc/systemd/system/seafile.service; enabled; vendor preset: enabled)
   Active: active (running) since Sun 2018-01-28 17:53:51 CET; 8s ago
  Process: 6569 ExecStart=/srv/start-seafile (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/seafile.service
       |-6598 /srv/seafile/XXXX/seafile-server-5.1.4/seafile/bin/seafile-controller -c /srv/seafile/XXXX/ccnet -d /volume1/Seafile -F /srv/seafile/XXXX/conf
       |-6600 ccnet-server -F /srv/seafile/XXXX/conf -c /srv/seafile/XXXX/ccnet -f /srv/seafile/XXXX/logs/ccnet.log -d -P /srv/seafile/XXXX/pids/ccnet.pid
       `-6602 seaf-server -F /srv/seafile/XXXX/conf -c /srv/seafile/XXXX/ccnet -d /volume1/Seafile -l /srv/seafile/XXXX/logs/seafile.log -P /srv/seafile/XXXX/pids/seaf-server.pid

Jan 28 17:53:48 XXXX systemd[1]: Starting Seafile...
Jan 28 17:53:48 XXXX start-seafile[6569]: [01/28/18 17:53:48] ../common/session.c(132): using config file /srv/seafile/XXXX/conf/ccnet.conf
Jan 28 17:53:48 XXXX start-seafile[6569]: Starting seafile server, please wait ...
Jan 28 17:53:51 XXXX start-seafile[6569]: Seafile server started
Jan 28 17:53:51 XXXX start-seafile[6569]: Done.
Jan 28 17:53:51 XXXX systemd[1]: Started Seafile.

但是,每次无人参与的更新发生时,都会发生这种情况:

Jan 23 06:38:08 XXXX systemd[1]: Starting Daily apt activities...
Jan 23 06:40:13 XXXX systemd[1]: Reloading.
Jan 23 06:40:13 XXXX systemd[1]: Stopping Seahub...
Jan 23 06:40:14 XXXX systemd[1]: Stopped Seahub.
Jan 23 06:40:14 XXXX systemd[1]: Stopping Seafile...
Jan 23 06:40:15 XXXX systemd[1]: Stopped Seafile.
Jan 23 06:40:15 XXXX systemd[1]: Stopping MySQL Community Server...
Jan 23 06:40:16 XXXX systemd[1]: Stopped MySQL Community Server.
Jan 23 06:40:17 XXXX systemd[1]: Reloading.
Jan 23 06:40:17 XXXX systemd[1]: Stopped MySQL Community Server.
...
Jan 23 06:40:43 XXXX systemd[1]: Reloading.
Jan 23 06:40:44 XXXX systemd[1]: Stopped MySQL Community Server.
Jan 23 06:40:44 XXXX systemd[1]: Reloading.
Jan 23 06:40:44 XXXX systemd[1]: Reloading.
Jan 23 06:40:44 XXXX systemd[1]: Starting MySQL Community Server...
Jan 23 06:40:45 XXXX systemd[1]: Started MySQL Community Server.
Jan 23 06:40:47 XXXX systemd[1]: Reloading.
Jan 23 06:40:48 XXXX systemd[1]: Stopping MySQL Community Server...
Jan 23 06:40:49 XXXX systemd[1]: Stopped MySQL Community Server.
Jan 23 06:40:49 XXXX systemd[1]: Starting MySQL Community Server...
Jan 23 06:40:50 XXXX systemd[1]: Started MySQL Community Server.
(... continues with unrelated services )

因此它意识到Seafile需要在MySQL之前停止,并且这样做,但在重启MySQL之后不再启动它。

有没有人有任何可能导致这种情况的经验?即。在哪种情况下,系统服务将在更新期间停止,但不会重新启动?

1 个答案:

答案 0 :(得分:1)

如果您希望它始终运行,请使用Restart=always。发生mysql服务更新时,此服务会执行干净stop,因此systemd不会重新启动它。您设置了Restart=on-failure,只有在停靠点的回复代码不是0时才会重新启动。

Restart = always
RestartSec = 10
  

RestartSec
    配置重新启动服务之前的睡眠时间(使用Restart =配置)。以秒为单位获取无单位值,或以“5分20秒”为单位获取时间跨度值。默认为100毫秒。