service: re-run init script "running" command after instance restart
authorFelix Fietkau <[email protected]>
Thu, 13 Mar 2025 10:02:22 +0000 (11:02 +0100)
committerFelix Fietkau <[email protected]>
Thu, 13 Mar 2025 10:02:23 +0000 (11:02 +0100)
This ensures that init scripts that use this command for applying the
config via ubus work properly.

Signed-off-by: Felix Fietkau <[email protected]>
service/instance.c

index 1c363fcb364142ed7a995951c6d954c76c9323c2..1d04041e44f0a0720aa6c8179e13b9615688865f 100644 (file)
@@ -32,6 +32,7 @@
 #include <libubox/md5.h>
 
 #include "../procd.h"
+#include "../rcS.h"
 
 #include "service.h"
 #include "instance.h"
@@ -786,8 +787,10 @@ instance_timeout(struct uloop_timeout *t)
                LOG("Instance %s::%s pid %d not stopped on SIGTERM, sending SIGKILL instead\n",
                                in->srv->name, in->name, in->proc.pid);
                kill(in->proc.pid, SIGKILL);
-       } else if (in->restart || in->respawn)
+       } else if (in->restart || in->respawn) {
                instance_start(in);
+               rc(in->srv->name, "running");
+       }
 }
 
 static void
@@ -822,6 +825,7 @@ static void
 instance_exit(struct uloop_process *p, int ret)
 {
        struct service_instance *in;
+       bool restart = false;
        struct timespec tp;
        long runtime;
 
@@ -840,11 +844,11 @@ instance_exit(struct uloop_process *p, int ret)
        if (in->halt) {
                instance_removepid(in);
                if (in->restart)
-                       instance_start(in);
+                       restart = true;
                else
                        instance_delete(in);
        } else if (in->restart) {
-               instance_start(in);
+               restart = true;
        } else if (in->respawn) {
                if (runtime < in->respawn_threshold)
                        in->respawn_count++;
@@ -861,6 +865,11 @@ instance_exit(struct uloop_process *p, int ret)
                        uloop_timeout_set(&in->timeout, in->respawn_timeout * 1000);
                }
        }
+
+       if (restart) {
+               instance_start(in);
+               rc(in->srv->name, "running");
+       }
 }
 
 void