chiark / gitweb /
nspawn: when running in a service unit, use systemd for restarts
authorLennart Poettering <lennart@poettering.net>
Thu, 3 Jul 2014 10:50:11 +0000 (12:50 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 3 Jul 2014 10:51:07 +0000 (12:51 +0200)
THis way we can remove cgroup priviliges after setup, but get them back
for the next restart, as we need it.

src/nspawn/nspawn.c
units/systemd-nspawn@.service.in

index 656c1bf..0d538c2 100644 (file)
@@ -3342,6 +3342,21 @@ int main(int argc, char *argv[]) {
                         break;
 
                 /* CONTAINER_REBOOTED, loop again */
+
+                if (arg_keep_unit) {
+                        /* Special handling if we are running as a
+                         * service: instead of simply restarting the
+                         * machine we want to restart the entire
+                         * service, so let's inform systemd about this
+                         * with the special exit code 133. The service
+                         * file uses RestartForceExitStatus=133 so
+                         * that this results in a full nspawn
+                         * restart. This is necessary since we might
+                         * have cgroup parameters set we want to have
+                         * flushed out. */
+                        r = 133;
+                        break;
+                }
         }
 
 finish:
index e373628..574d0de 100644 (file)
@@ -13,6 +13,8 @@ Documentation=man:systemd-nspawn(1)
 ExecStart=@bindir@/systemd-nspawn --quiet --keep-unit --boot --link-journal=guest --directory=/var/lib/container/%i
 KillMode=mixed
 Type=notify
+RestartForceExitStatus=133
+SuccessExitStatus=133
 
 [Install]
 WantedBy=multi-user.target