chiark / gitweb /
units: add an easy-to-use unit template file systemd-nspawn@.service for running...
authorLennart Poettering <lennart@poettering.net>
Tue, 30 Apr 2013 00:11:37 +0000 (21:11 -0300)
committerLennart Poettering <lennart@poettering.net>
Tue, 30 Apr 2013 11:36:02 +0000 (08:36 -0300)
Makefile.am
src/nspawn/nspawn.c
units/.gitignore
units/systemd-nspawn@.service.in [new file with mode: 0644]

index ff70223395b1e3e9c9d0376de30870deded29325..9e0f5fb20ea14036c8ff697062db668be94a8c66 100644 (file)
@@ -442,7 +442,8 @@ nodist_systemunit_DATA = \
        units/initrd-parse-etc.service \
        units/initrd-cleanup.service \
        units/initrd-udevadm-cleanup-db.service \
        units/initrd-parse-etc.service \
        units/initrd-cleanup.service \
        units/initrd-udevadm-cleanup-db.service \
-       units/initrd-switch-root.service
+       units/initrd-switch-root.service \
+       units/systemd-nspawn@.service
 
 dist_userunit_DATA = \
        units/user/default.target \
 
 dist_userunit_DATA = \
        units/user/default.target \
@@ -489,6 +490,7 @@ EXTRA_DIST += \
        units/initrd-cleanup.service.in \
        units/initrd-udevadm-cleanup-db.service.in \
        units/initrd-switch-root.service.in \
        units/initrd-cleanup.service.in \
        units/initrd-udevadm-cleanup-db.service.in \
        units/initrd-switch-root.service.in \
+       units/systemd-nspawn@.service.in \
        introspect.awk
 
 CLEANFILES += \
        introspect.awk
 
 CLEANFILES += \
index 0a46313636bd0183739fb6607dd20bb6345c2131..d772b478fd8fd3cc6f51defcb32e771f2778b967 100644 (file)
@@ -1231,9 +1231,13 @@ int main(int argc, char *argv[]) {
         log_parse_environment();
         log_open();
 
         log_parse_environment();
         log_open();
 
-        r = parse_argv(argc, argv);
-        if (r <= 0)
+        k = parse_argv(argc, argv);
+        if (k < 0)
                 goto finish;
                 goto finish;
+        else if (k == 0) {
+                r = EXIT_SUCCESS;
+                goto finish;
+        }
 
         if (arg_directory) {
                 char *p;
 
         if (arg_directory) {
                 char *p;
@@ -1321,8 +1325,8 @@ int main(int argc, char *argv[]) {
                 goto finish;
         }
 
                 goto finish;
         }
 
-        r = cg_is_empty_recursive(SYSTEMD_CGROUP_CONTROLLER, newcg, false);
-        if (r <= 0 && r != -ENOENT) {
+        k = cg_is_empty_recursive(SYSTEMD_CGROUP_CONTROLLER, newcg, true);
+        if (k <= 0 && k != -ENOENT) {
                 log_error("Container already running.");
 
                 free(newcg);
                 log_error("Container already running.");
 
                 free(newcg);
@@ -1366,6 +1370,8 @@ int main(int argc, char *argv[]) {
                 goto finish;
         }
 
                 goto finish;
         }
 
+        sd_notify(0, "READY=1");
+
         assert_se(sigemptyset(&mask) == 0);
         sigset_add_many(&mask, SIGCHLD, SIGWINCH, SIGTERM, SIGINT, -1);
         assert_se(sigprocmask(SIG_BLOCK, &mask, NULL) == 0);
         assert_se(sigemptyset(&mask) == 0);
         sigset_add_many(&mask, SIGCHLD, SIGWINCH, SIGTERM, SIGINT, -1);
         assert_se(sigprocmask(SIG_BLOCK, &mask, NULL) == 0);
@@ -1701,8 +1707,8 @@ int main(int argc, char *argv[]) {
                 if (saved_attr_valid)
                         tcsetattr(STDIN_FILENO, TCSANOW, &saved_attr);
 
                 if (saved_attr_valid)
                         tcsetattr(STDIN_FILENO, TCSANOW, &saved_attr);
 
-                r = wait_for_terminate(pid, &status);
-                if (r < 0) {
+                k = wait_for_terminate(pid, &status);
+                if (k < 0) {
                         r = EXIT_FAILURE;
                         break;
                 }
                         r = EXIT_FAILURE;
                         break;
                 }
index d2f3eb40d63d989b68daa538f118535b94107eca..606d947634adc1de98f2fe70f0ff155d5cb47336 100644 (file)
@@ -57,3 +57,4 @@
 /initrd-parse-etc.service
 /initrd-switch-root.service
 /initrd-udevadm-cleanup-db.service
 /initrd-parse-etc.service
 /initrd-switch-root.service
 /initrd-udevadm-cleanup-db.service
+/systemd-nspawn@.service
diff --git a/units/systemd-nspawn@.service.in b/units/systemd-nspawn@.service.in
new file mode 100644 (file)
index 0000000..c0d5886
--- /dev/null
@@ -0,0 +1,18 @@
+#  This file is part of systemd.
+#
+#  systemd is free software; you can redistribute it and/or modify it
+#  under the terms of the GNU Lesser General Public License as published by
+#  the Free Software Foundation; either version 2.1 of the License, or
+#  (at your option) any later version.
+
+[Unit]
+Description=Container %i
+Documentation=man:systemd-nspawn(1)
+
+[Service]
+ExecStart=@bindir@/systemd-nspawn -bjD /var/lib/container/%i
+ControlGroup=%R/machine/%i.nspawn cpu:/
+Type=notify
+
+[Install]
+Also=multi-user.target