service: add reload_signal property
authorJo-Philipp Wich <jo@mein.io>
Tue, 13 Dec 2016 16:27:13 +0000 (17:27 +0100)
committerJo-Philipp Wich <jo@mein.io>
Tue, 13 Dec 2016 16:51:20 +0000 (17:51 +0100)
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 <jo@mein.io>
service/instance.c
service/instance.h

index 88380499d56f34ccf07f063c9f63e9e3a6a19ebf..018db3c689eb3c5cecf9d58c4e4754ec6c1fac2f 100644 (file)
@@ -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);
index 6f95a2aab819a63f8e827296aae8b4cc3bd228ff..3cc20093f810176e842920e197e2d336b4b712fe 100644 (file)
@@ -49,6 +49,7 @@ struct service_instance {
        bool restart;
        bool respawn;
        int respawn_count;
+       int reload_signal;
        struct timespec start;
 
        bool trace;