diff options
-rw-r--r-- | doc/s6-svc.html | 3 | ||||
-rw-r--r-- | src/supervision/s6-supervise.c | 46 | ||||
-rw-r--r-- | src/supervision/s6-svc.c | 5 |
3 files changed, 29 insertions, 25 deletions
diff --git a/doc/s6-svc.html b/doc/s6-svc.html index 24b139d..7c2e30a 100644 --- a/doc/s6-svc.html +++ b/doc/s6-svc.html @@ -79,6 +79,9 @@ and stdout redirected to <tt>/dev/null</tt>. </li> <li> <tt>-O</tt> : mark the service to run once at most. iow: do not restart the supervised process when it dies. If it is down when the command is received, do not even start it. </li> + <li> <tt>-Q</tt> : once at most, and create a <tt>./down</tt> file. +Like <tt>-D</tt>, but do not terminate the service if it is currently +running. </li> <li> <tt>-r</tt> : If the service is up, restart it, by sending it a signal to kill it and letting <a href="s6-supervise.html">s6-supervise</a> start it again. By default, the signal is a SIGTERM; this can be configured diff --git a/src/supervision/s6-supervise.c b/src/supervision/s6-supervise.c index fa96a02..5611b98 100644 --- a/src/supervision/s6-supervise.c +++ b/src/supervision/s6-supervise.c @@ -40,7 +40,7 @@ enum trans_e { V_TIMEOUT, V_CHLD, V_TERM, V_HUP, V_QUIT, V_INT, V_a, V_b, V_q, V_h, V_k, V_t, V_i, V_1, V_2, V_p, V_c, V_y, V_r, - V_o, V_d, V_u, V_D, V_U, V_x, V_O + V_o, V_d, V_u, V_D, V_U, V_x, V_O, V_Q } ; typedef enum state_e state_t, *state_t_ref ; @@ -416,6 +416,18 @@ static void wantup (void) announce() ; } +static void wantDOWN (void) +{ + adddown() ; + wantdown() ; +} + +static void wantUP (void) +{ + deldown() ; + wantup() ; +} + static void downtimeout (void) { if (status.flagwantup) trystart() ; @@ -434,16 +446,10 @@ static void down_u (void) trystart() ; } -static void down_D (void) -{ - adddown() ; - wantdown() ; -} - static void down_U (void) { - deldown() ; - down_u() ; + wantUP() ; + trystart() ; } static int uplastup_z (void) @@ -559,12 +565,6 @@ static void up_D (void) up_d() ; } -static void up_U (void) -{ - deldown() ; - wantup() ; -} - static void up_x (void) { state = LASTUP ; @@ -607,23 +607,23 @@ static void lastfinish_z (void) bail() ; } -static action_t_ref const actions[5][26] = +static action_t_ref const actions[5][27] = { { &downtimeout, &nop, &bail, &bail, &bail, &bail, &nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop, - &down_o, &wantdown, &down_u, &down_D, &down_U, &bail, &wantdown }, + &down_o, &wantdown, &down_u, &wantDOWN, &down_U, &bail, &wantdown, &wantDOWN }, { &uptimeout, &up_z, &up_term, &up_x, &bail, &sigint, &killa, &killb, &killq, &killh, &killk, &killt, &killi, &kill1, &kill2, &killp, &killc, &killy, &killr, - &wantdown, &up_d, &wantup, &up_D, &up_U, &up_x, &wantdown }, + &wantdown, &up_d, &wantup, &up_D, &wantUP, &up_x, &wantdown, &wantDOWN }, { &finishtimeout, &finish_z, &finish_x, &finish_x, &bail, &sigint, &nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop, - &wantdown, &wantdown, &wantup, &down_D, &up_U, &finish_x, &wantdown }, + &wantdown, &wantdown, &wantup, &wantDOWN, &wantUP, &finish_x, &wantdown, &wantDOWN }, { &uptimeout, &lastup_z, &up_d, &closethem, &bail, &sigint, &killa, &killb, &killq, &killh, &killk, &killt, &killi, &kill1, &kill2, &killp, &killc, &killy, &killr, - &wantdown, &up_d, &wantup, &up_D, &up_U, &closethem, &wantdown }, + &wantdown, &up_d, &wantup, &up_D, &wantUP, &closethem, &wantdown, &wantDOWN }, { &finishtimeout, &lastfinish_z, &nop, &closethem, &bail, &sigint, &nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop, - &wantdown, &wantdown, &wantup, &down_D, &up_U, &closethem, &wantdown } + &wantdown, &wantdown, &wantup, &wantDOWN, &wantUP, &closethem, &wantdown, &wantDOWN } } ; @@ -706,8 +706,8 @@ static inline void handle_control (int fd) else if (!r) break ; else { - size_t pos = byte_chr("abqhkti12pcyroduDUxO", 20, c) ; - if (pos < 20) (*actions[state][V_a + pos])() ; + size_t pos = byte_chr("abqhkti12pcyroduDUxOQ", 21, c) ; + if (pos < 21) (*actions[state][V_a + pos])() ; } } } diff --git a/src/supervision/s6-svc.c b/src/supervision/s6-svc.c index 4485248..1586056 100644 --- a/src/supervision/s6-svc.c +++ b/src/supervision/s6-svc.c @@ -13,7 +13,7 @@ #include <s6/config.h> #include <s6/supervise.h> -#define USAGE "s6-svc [ -wu | -wU | -wd | -wD | -wr | -wR ] [ -T timeout ] [ -abqhkti12pcyroduDUxO ] servicedir" +#define USAGE "s6-svc [ -wu | -wU | -wd | -wD | -wr | -wR ] [ -T timeout ] [ -abqhkti12pcyroduDUxOQ ] servicedir" #define dieusage() strerr_dieusage(100, USAGE) #define DATASIZE 63 @@ -30,7 +30,7 @@ int main (int argc, char const *const *argv) subgetopt l = SUBGETOPT_ZERO ; for (;;) { - int opt = subgetopt_r(argc, argv, "abqhkti12pcyroduDUxOT:w:", &l) ; + int opt = subgetopt_r(argc, argv, "abqhkti12pcyroduDUxOQT:w:", &l) ; if (opt == -1) break ; switch (opt) { @@ -54,6 +54,7 @@ int main (int argc, char const *const *argv) case 'U' : case 'x' : case 'O' : + case 'Q' : { if (datalen >= DATASIZE) strerr_dief1x(100, "too many commands") ; data[datalen++] = opt ; |