@@ -506,12 +506,17 @@ instance_timeout(struct uloop_timeout *t)
in = container_of(t, struct service_instance, timeout);
- if (in->halt) {
- 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)
- instance_start(in);
+ if (!in->proc.pending) {
+ if (in->respawn) {
+ instance_start(in);
+ }
+ } else {
+ if (in->halt) {
+ 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);
+ }
+ }
}
static void
@@ -545,6 +550,7 @@ instance_exit(struct uloop_process *p, int ret)
service_stopped(s);
}
} else if (in->restart) {
+ /* can never happen */
instance_start(in);
} else if (in->respawn) {
if (runtime < in->respawn_threshold)
@@ -554,8 +560,8 @@ instance_exit(struct uloop_process *p, int ret)
if (in->respawn_count > in->respawn_retry && in->respawn_retry > 0 ) {
LOG("Instance %s::%s s in a crash loop %d crashes, %ld seconds since last crash\n",
in->srv->name, in->name, in->respawn_count, runtime);
- in->restart = in->respawn = 0;
- in->halt = 1;
+ in->restart = false;
+ in->halt = true;
service_event("instance.fail", in->srv->name, in->name);
} else {
service_event("instance.respawn", in->srv->name, in->name);
@@ -570,7 +576,7 @@ instance_stop(struct service_instance *in)
if (!in->proc.pending)
return;
in->halt = true;
- in->restart = in->respawn = false;
+ in->restart = false;
kill(in->proc.pid, SIGTERM);
uloop_timeout_set(&in->timeout, in->term_timeout * 1000);
}