title: Automatically restart a service after unattended updates under systemd
body: <p>I've added a service (Seafile, in this case) that I want to have running at all times to systemd with a service file. It works great, but every time the unattended updates run, the service gets shutdown properly - but never restarted.</p>
  
  <p>Here's what the service file looks like:</p>
  
  <pre><code>[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
  </code></pre>
  
  <p>/srv/start-seafile looks like this:</p>
  
  <pre><code>#!/bin/bash
  
  cd /srv/seafile/XXXX/seafile-server-latest &amp;&amp; nohup ./seafile.sh start
  </code></pre>
  
  <p>Like I said - this works perfectly - systemd can enable / disable / start / stop the service, realize if it's started / running - so I must be doing <em>something</em> right.</p>
  
  <pre><code># 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.
  </code></pre>
  
  <p>However, every time the unattended updates come, this happens:</p>
  
  <pre><code>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 )
  </code></pre>
  
  <p>So it realizes that Seafile needs to be stopped before MySQL, and does so, but no longer starts it after it restarts MySQL.</p>
  
  <p>Does anyone have any experience as to what could be causing this? ie. under which circumstances systemd services will be stopped during an update, but not restarted?</p>