Re: [lxc-devel] [PATCH 2/2] add lxc.haltsignal for soft shutdown
-Original Message- From: lxc-devel-boun...@lists.linuxcontainers.org [mailto:lxc-devel- boun...@lists.linuxcontainers.org] On Behalf Of Dwight Engen Sent: Friday, January 03, 2014 9:37 PM To: lxc-devel@lists.linuxcontainers.org Subject: [lxc-devel] [PATCH 2/2] add lxc.haltsignal for soft shutdown - use this in the busybox template since busybox's init expects to receive SIGUSR1 to halt Just as a FYI, patch [1] makes busybox init respond to SIGPWR as well. Best regards, Bogdan P. [1] http://git.busybox.net/busybox/commit/?id=760fc6debcba8cb5ca8d8e2252fac3757c453e11 - 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.en...@oracle.com --- doc/lxc-stop.sgml.in | 13 ++--- src/lxc/conf.h | 3 ++- src/lxc/confile.c| 28 src/lxc/lxccontainer.c | 5 - templates/lxc-busybox.in | 1 + 5 files changed, 41 insertions(+), 9 deletions(-) diff --git a/doc/lxc-stop.sgml.in b/doc/lxc-stop.sgml.in index bdb0ef5..dc002c5 100644 --- a/doc/lxc-stop.sgml.in +++ b/doc/lxc-stop.sgml.in @@ -65,13 +65,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA para commandlxc-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 - commandlxc.stopsignal/command to force it to shut down. If - commandlxc.stopsignal/command is not specified, the signal sent is - SIGKILL. + request a clean shutdown of the container by sending + commandlxc.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 commandlxc.stopsignal/command + (defaults to SIGKILL) to force it to shut down. /para para The optional-W/optional, optional-r/optional, diff --git a/src/lxc/conf.h b/src/lxc/conf.h index e881635..8efd0f3 100644 --- a/src/lxc/conf.h +++ b/src/lxc/conf.h @@ -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 diff --git a/src/lxc/confile.c b/src/lxc/confile.c index 0982b3e..d21fbec 100644 --- a/src/lxc/confile.c +++ b/src/lxc/confile.c @@ -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
Re: [lxc-devel] [PATCH 2/2] add lxc.haltsignal for soft shutdown
On Mon, 6 Jan 2014 09:48:37 -0500 Stéphane Graber stgra...@ubuntu.com wrote: On Fri, Jan 03, 2014 at 02:36:50PM -0500, Dwight Engen wrote: - 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.en...@oracle.com The change looks fine but can you update your patch to include the matching manpage (lxc.conf) entry? Sure, forgot about that one, thanks good catch. --- doc/lxc-stop.sgml.in | 13 ++--- src/lxc/conf.h | 3 ++- src/lxc/confile.c| 28 src/lxc/lxccontainer.c | 5 - templates/lxc-busybox.in | 1 + 5 files changed, 41 insertions(+), 9 deletions(-) diff --git a/doc/lxc-stop.sgml.in b/doc/lxc-stop.sgml.in index bdb0ef5..dc002c5 100644 --- a/doc/lxc-stop.sgml.in +++ b/doc/lxc-stop.sgml.in @@ -65,13 +65,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA para commandlxc-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 - commandlxc.stopsignal/command to force it to shut down. If - commandlxc.stopsignal/command is not specified, the signal sent is - SIGKILL. + request a clean shutdown of the container by sending + commandlxc.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 commandlxc.stopsignal/command + (defaults to SIGKILL) to force it to shut down. /para para The optional-W/optional, optional-r/optional, diff --git a/src/lxc/conf.h b/src/lxc/conf.h index e881635..8efd0f3 100644 --- a/src/lxc/conf.h +++ b/src/lxc/conf.h @@ -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 diff --git a/src/lxc/confile.c b/src/lxc/confile.c index 0982b3e..d21fbec 100644 --- a/src/lxc/confile.c +++ b/src/lxc/confile.c @@ -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)
Re: [lxc-devel] [PATCH 2/2] add lxc.haltsignal for soft shutdown
On Mon, 6 Jan 2014 10:05:28 + bogdan.purcare...@freescale.com bogdan.purcare...@freescale.com wrote: -Original Message- From: lxc-devel-boun...@lists.linuxcontainers.org [mailto:lxc-devel- boun...@lists.linuxcontainers.org] On Behalf Of Dwight Engen Sent: Friday, January 03, 2014 9:37 PM To: lxc-devel@lists.linuxcontainers.org Subject: [lxc-devel] [PATCH 2/2] add lxc.haltsignal for soft shutdown - use this in the busybox template since busybox's init expects to receive SIGUSR1 to halt Just as a FYI, patch [1] makes busybox init respond to SIGPWR as well. Hi Bogdan, seeing your patch is what reminded me that busybox not shutting down nicely has been bothering me for a while. Its great that your change will fix busybox in the future, but I also wanted older busybox versions to shut down clean now, so that is why I submitted this. Best regards, Bogdan P. [1] http://git.busybox.net/busybox/commit/?id=760fc6debcba8cb5ca8d8e2252fac3757c453e11 - 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.en...@oracle.com --- doc/lxc-stop.sgml.in | 13 ++--- src/lxc/conf.h | 3 ++- src/lxc/confile.c| 28 src/lxc/lxccontainer.c | 5 - templates/lxc-busybox.in | 1 + 5 files changed, 41 insertions(+), 9 deletions(-) diff --git a/doc/lxc-stop.sgml.in b/doc/lxc-stop.sgml.in index bdb0ef5..dc002c5 100644 --- a/doc/lxc-stop.sgml.in +++ b/doc/lxc-stop.sgml.in @@ -65,13 +65,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA para commandlxc-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 - commandlxc.stopsignal/command to force it to shut down. If - commandlxc.stopsignal/command is not specified, the signal sent is - SIGKILL. + request a clean shutdown of the container by sending + commandlxc.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 commandlxc.stopsignal/command + (defaults to SIGKILL) to force it to shut down. /para para The optional-W/optional, optional-r/optional, diff --git a/src/lxc/conf.h b/src/lxc/conf.h index e881635..8efd0f3 100644 --- a/src/lxc/conf.h +++ b/src/lxc/conf.h @@ -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 diff --git a/src/lxc/confile.c b/src/lxc/confile.c index 0982b3e..d21fbec 100644 --- a/src/lxc/confile.c +++ b/src/lxc/confile.c @@ -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
[lxc-devel] [PATCH 2/2] add lxc.haltsignal for soft shutdown
- 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.en...@oracle.com --- doc/lxc-stop.sgml.in | 13 ++--- src/lxc/conf.h | 3 ++- src/lxc/confile.c| 28 src/lxc/lxccontainer.c | 5 - templates/lxc-busybox.in | 1 + 5 files changed, 41 insertions(+), 9 deletions(-) diff --git a/doc/lxc-stop.sgml.in b/doc/lxc-stop.sgml.in index bdb0ef5..dc002c5 100644 --- a/doc/lxc-stop.sgml.in +++ b/doc/lxc-stop.sgml.in @@ -65,13 +65,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA para commandlxc-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 - commandlxc.stopsignal/command to force it to shut down. If - commandlxc.stopsignal/command is not specified, the signal sent is - SIGKILL. + request a clean shutdown of the container by sending + commandlxc.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 commandlxc.stopsignal/command + (defaults to SIGKILL) to force it to shut down. /para para The optional-W/optional, optional-r/optional, diff --git a/src/lxc/conf.h b/src/lxc/conf.h index e881635..8efd0f3 100644 --- a/src/lxc/conf.h +++ b/src/lxc/conf.h @@ -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 diff --git a/src/lxc/confile.c b/src/lxc/confile.c index 0982b3e..d21fbec 100644 --- a/src/lxc/confile.c +++ b/src/lxc/confile.c @@ -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