]> git.proxmox.com Git - mirror_lxc.git/commitdiff
add lxc.haltsignal for soft shutdown
authorDwight Engen <dwight.engen@oracle.com>
Mon, 6 Jan 2014 17:30:02 +0000 (12:30 -0500)
committerStéphane Graber <stgraber@ubuntu.com>
Mon, 6 Jan 2014 17:49:44 +0000 (12:49 -0500)
- use this in the busybox template since busybox's init expects
  to receive SIGUSR1 to halt

- fix lxc.stopsignal to be output by write_config so lxcapi_clone()
  and lxcapi_save_config() will output it

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
doc/lxc-stop.sgml.in
doc/lxc.conf.sgml.in
src/lxc/conf.h
src/lxc/confile.c
src/lxc/lxccontainer.c
templates/lxc-busybox.in

index bdb0ef5d832a53dc63e94369990b3c8adc7d4b66..dc002c551e3df5351656bf9c1d518b15dc4ebd81 100644 (file)
@@ -65,13 +65,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
     <para>
       <command>lxc-stop</command> reboots, cleanly shuts down, or kills
       all the processes inside the container.  By default, it will
-      request a clean shutdown of the container (by sending SIGPWR to
-      the container), wait 60 seconds for the container to exit, and
-      returns.  If the container fails to cleanly exit, then after 60
-      seconds the container will be sent the
-      <command>lxc.stopsignal</command> to force it to shut down. If
-      <command>lxc.stopsignal</command> is not specified, the signal sent is
-      SIGKILL.
+      request a clean shutdown of the container by sending
+      <command>lxc.haltsignal</command> (defaults to SIGPWR) to
+      the container's init process, waiting up to 60 seconds for the container
+      to exit, and then returning. If the container fails to cleanly exit in
+      60 seconds, it will be sent the <command>lxc.stopsignal</command>
+      (defaults to SIGKILL) to force it to shut down.
     </para>
        <para>
        The <optional>-W</optional>, <optional>-r</optional>,
index e6d96891f9bd7b70acfeceb0269d1e36282fba8c..1350c634180d06593eb4fb890850b942ff6a8729 100644 (file)
@@ -155,14 +155,37 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
       </variablelist>
     </refsect2>
 
+    <refsect2>
+      <title>Halt signal</title>
+      <para>
+    Allows one to specify signal name or number, sent by lxc-stop to the
+    container's init process to cleanly shutdown the container. Different
+    init systems could use different signals to perform clean shutdown
+    sequence. This option allows the signal to be specified in kill(1)
+    fashion, e.g. SIGPWR, SIGRTMIN+14, SIGRTMAX-10 or plain number. The
+    default signal is SIGPWR.
+      </para>
+      <variablelist>
+    <varlistentry>
+      <term>
+        <option>lxc.haltsignal</option>
+      </term>
+      <listitem>
+        <para>
+          specify the signal used to halt the container
+        </para>
+      </listitem>
+    </varlistentry>
+      </variablelist>
+    </refsect2>
+
     <refsect2>
       <title>Stop signal</title>
       <para>
-    Allows one to specify signal name or number, sent by lxc-stop to
-    shutdown the container. Different init systems could use
-    different signals to perform clean shutdown sequence. Option
-    allows signal to be specified in kill(1) fashion, e.g.
-    SIGKILL, SIGRTMIN+14, SIGRTMAX-10 or plain number.
+    Allows one to specify signal name or number, sent by lxc-stop to forcibly
+    shutdown the container. This option allows signal to be specified in
+    kill(1) fashion, e.g. SIGKILL, SIGRTMIN+14, SIGRTMAX-10 or plain number.
+    The default signal is SIGKILL.
       </para>
       <variablelist>
     <varlistentry>
index e88163545bdb5881f17992ca97b7ed854ceaa4b2..8efd0f3c89f5f823e735d5daad3d77e2718aa30f 100644 (file)
@@ -307,7 +307,8 @@ struct lxc_conf {
 #endif
        int maincmd_fd;
        int autodev;  // if 1, mount and fill a /dev at start
-       int stopsignal; // signal used to stop container
+       int haltsignal; // signal used to halt container
+       int stopsignal; // signal used to hard stop container
        int kmsg;  // if 1, create /dev/kmsg symlink
        char *rcfile;   // Copy of the top level rcfile we read
 
index 0982b3e0aad55f865adb2d9f3c5cfe3520f70df9..d21fbec2fe06d1e830a744acae6f74570911cc54 100644 (file)
@@ -90,6 +90,7 @@ static int config_seccomp(const char *, const char *, struct lxc_conf *);
 static int config_includefile(const char *, const char *, struct lxc_conf *);
 static int config_network_nic(const char *, const char *, struct lxc_conf *);
 static int config_autodev(const char *, const char *, struct lxc_conf *);
+static int config_haltsignal(const char *, const char *, struct lxc_conf *);
 static int config_stopsignal(const char *, const char *, struct lxc_conf *);
 static int config_start(const char *, const char *, struct lxc_conf *);
 static int config_group(const char *, const char *, struct lxc_conf *);
@@ -142,6 +143,7 @@ static struct lxc_config_t config[] = {
        { "lxc.seccomp",              config_seccomp              },
        { "lxc.include",              config_includefile          },
        { "lxc.autodev",              config_autodev              },
+       { "lxc.haltsignal",           config_haltsignal           },
        { "lxc.stopsignal",           config_stopsignal           },
        { "lxc.start.auto",           config_start                },
        { "lxc.start.delay",          config_start                },
@@ -1108,6 +1110,16 @@ static int rt_sig_num(const char *signame)
        return sig_n;
 }
 
+static const char *sig_name(int signum) {
+       int n;
+
+       for (n = 0; n < sizeof(signames) / sizeof((signames)[0]); n++) {
+               if (n == signames[n].num)
+                       return signames[n].name;
+       }
+       return "";
+}
+
 static int sig_parse(const char *signame) {
        int n;
 
@@ -1125,6 +1137,18 @@ static int sig_parse(const char *signame) {
        return -1;
 }
 
+static int config_haltsignal(const char *key, const char *value,
+                            struct lxc_conf *lxc_conf)
+{
+       int sig_n = sig_parse(value);
+
+       if (sig_n < 0)
+               return -1;
+       lxc_conf->haltsignal = sig_n;
+
+       return 0;
+}
+
 static int config_stopsignal(const char *key, const char *value,
                          struct lxc_conf *lxc_conf)
 {
@@ -2119,6 +2143,10 @@ void write_config(FILE *fout, struct lxc_conf *c)
                fprintf(fout, "lxc.pts = %d\n", c->pts);
        if (c->ttydir)
                fprintf(fout, "lxc.devttydir = %s\n", c->ttydir);
+       if (c->haltsignal)
+               fprintf(fout, "lxc.haltsignal = SIG%s\n", sig_name(c->haltsignal));
+       if (c->stopsignal)
+               fprintf(fout, "lxc.stopsignal = SIG%s\n", sig_name(c->stopsignal));
        #if HAVE_SYS_PERSONALITY_H
        switch(c->personality) {
        case PER_LINUX32: fprintf(fout, "lxc.arch = x86\n"); break;
index 132f1a3557dd0b5495be186d3147d8095b36a97e..353b733918d0ea35f259b070ac797b26ce78e87c 100644 (file)
@@ -1307,6 +1307,7 @@ static bool lxcapi_shutdown(struct lxc_container *c, int timeout)
 {
        bool retv;
        pid_t pid;
+       int haltsignal = SIGPWR;
 
        if (!c)
                return false;
@@ -1318,7 +1319,9 @@ static bool lxcapi_shutdown(struct lxc_container *c, int timeout)
        pid = c->init_pid(c);
        if (pid <= 0)
                return true;
-       kill(pid, SIGPWR);
+       if (c->lxc_conf->haltsignal)
+               haltsignal = c->lxc_conf->haltsignal;
+       kill(pid, haltsignal);
        retv = c->wait(c, "STOPPED", timeout);
        if (!retv && timeout > 0) {
                c->stop(c);
index 8232334494302eb8910b45d871c6e5bc3ba278d1..974377d0765b17491d34a6aeb76f5511bbf417da 100644 (file)
@@ -272,6 +272,7 @@ copy_configuration()
 
 grep -q "^lxc.rootfs" $path/config 2>/dev/null || echo "lxc.rootfs = $rootfs" >> $path/config
 cat <<EOF >> $path/config
+lxc.haltsignal = SIGUSR1
 lxc.utsname = $name
 lxc.tty = 1
 lxc.pts = 1