From f800ecf860addd4fc7f1acde76a9adbd4b1f50e7 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Tue, 13 Dec 2016 17:27:13 +0100 Subject: [PATCH] service: add reload_signal property Introduce a new optional property "reload_signal" which - if set - instructs procd to not terminate and restart supervised processes upon changes, but to send them a kill() signal instead. This is useful for services which fully support native config reload upon receipt of a signal. Signed-off-by: Jo-Philipp Wich --- service/instance.c | 14 ++++++++++++++ service/instance.h | 1 + 2 files changed, 15 insertions(+) diff --git a/service/instance.c b/service/instance.c index 8838049..018db3c 100644 --- a/service/instance.c +++ b/service/instance.c @@ -54,6 +54,7 @@ enum { INSTANCE_ATTR_TRACE, INSTANCE_ATTR_SECCOMP, INSTANCE_ATTR_PIDFILE, + INSTANCE_ATTR_RELOADSIG, __INSTANCE_ATTR_MAX }; @@ -77,6 +78,7 @@ static const struct blobmsg_policy instance_attr[__INSTANCE_ATTR_MAX] = { [INSTANCE_ATTR_TRACE] = { "trace", BLOBMSG_TYPE_BOOL }, [INSTANCE_ATTR_SECCOMP] = { "seccomp", BLOBMSG_TYPE_STRING }, [INSTANCE_ATTR_PIDFILE] = { "pidfile", BLOBMSG_TYPE_STRING }, + [INSTANCE_ATTR_RELOADSIG] = { "reload_signal", BLOBMSG_TYPE_INT32 }, }; enum { @@ -551,6 +553,12 @@ instance_restart(struct service_instance *in) { if (!in->proc.pending) return; + + if (in->reload_signal) { + kill(in->proc.pid, in->reload_signal); + return; + } + in->halt = false; in->restart = true; kill(in->proc.pid, SIGTERM); @@ -854,6 +862,9 @@ instance_config_parse(struct service_instance *in) in->pidfile = pidfile; } + if (tb[INSTANCE_ATTR_RELOADSIG]) + in->reload_signal = blobmsg_get_u32(tb[INSTANCE_ATTR_RELOADSIG]); + if (!in->trace && tb[INSTANCE_ATTR_JAIL]) in->has_jail = instance_jail_parse(in, tb[INSTANCE_ATTR_JAIL]); @@ -1021,6 +1032,9 @@ void instance_dump(struct blob_buf *b, struct service_instance *in, int verbose) blobmsg_close_table(b, e); } + if (in->reload_signal) + blobmsg_add_u32(b, "reload_signal", in->reload_signal); + if (in->respawn) { void *r = blobmsg_open_table(b, "respawn"); blobmsg_add_u32(b, "threshold", in->respawn_threshold); diff --git a/service/instance.h b/service/instance.h index 6f95a2a..3cc2009 100644 --- a/service/instance.h +++ b/service/instance.h @@ -49,6 +49,7 @@ struct service_instance { bool restart; bool respawn; int respawn_count; + int reload_signal; struct timespec start; bool trace; -- 2.11.0