fiss

Friedel's Initialization and Service Supervision
Log | Files | Refs | LICENSE

commit a6f62f6d531fdbcb4cffaac14a732a5e88ea92d9
parent 3fd47336b2b5b470aeeb41da0fb1500be3741eab
Author: Friedel Schön <[email protected]>
Date:   Tue, 23 May 2023 09:08:43 +0200

revive -> reset

Diffstat:
Minclude/service.h | 2+-
Msrc/exec/fsvc.c | 18++++++++++++++++--
Msrc/handle_command.c | 14+++++++++-----
3 files changed, 26 insertions(+), 8 deletions(-)

diff --git a/include/service.h b/include/service.h @@ -19,7 +19,7 @@ typedef enum { S_SEND = 'k', // + signal | send signal to service S_PAUSE = 'p', // pause service (send SIGSTOP) S_RESUME = 'c', // unpause service (send SIGCONT) - S_REVIVE = 'v', // revive died service + S_RESET = 'v', // revive died service S_EXIT = 'x', // kill the fsvs instance S_STATUS = 'a', // get status of all services S_SWITCH = 'l', // change runlevel diff --git a/src/exec/fsvc.c b/src/exec/fsvc.c @@ -77,8 +77,14 @@ void print_service(service_t* s) { print_status(s, state, sizeof(state)); printf("- %s (%s)\n", s->name, state); - printf(" [ %c ] restart on exit\n", s->restart_file || s->restart_manual ? 'x' : ' '); - printf(" [%3d] last return code (%s)\n", s->return_code, s->last_exit == EXIT_SIGNALED ? "signaled" : "exited"); + printf(" [ %c ] restart on exit\n", s->restart_final ? 'x' : ' '); + if (s->return_code > 0) + printf(" [%3d] last return code (%s)\n", s->return_code, s->last_exit == EXIT_SIGNALED ? "signaled" : "exited"); + printf(" [%3d] fail count\n", s->fail_count); + printf(" [ %c ] has log service\n", s->is_log_service ? '-' + : s->log_service ? 'x' + : ' '); + printf(" [ %c ] is paused\n", s->paused ? 'x' : ' '); printf("\n"); } @@ -248,6 +254,14 @@ int main(int argc, char** argv) { } command = streq(command_str, "pause") ? S_PAUSE : S_RESUME; + } else if (streq(command_str, "reset")) { + if (!service) { + printf("service omitted\n"); + return 1; + } + + command = S_RESET; + extra = 0; } else if (streq(command_str, "switch")) { if (!service) { printf("runlevel omitted\n"); diff --git a/src/handle_command.c b/src/handle_command.c @@ -108,7 +108,7 @@ int service_handle_command(void* argv, sv_command_t command, unsigned char extra if (s == NULL) return -ENOSV; - if (s->state == STATE_INACTIVE || !s->paused) + if (s->state == STATE_INACTIVE || s->state == STATE_DEAD || s->pid == 0 || !s->paused) return 0; s->paused = false; @@ -120,14 +120,18 @@ int service_handle_command(void* argv, sv_command_t command, unsigned char extra response[0] = s; return 1; - case S_REVIVE: + case S_RESET: if (s == NULL) return -ENOSV; - if (s->state != STATE_DEAD) - return 0; + if (s->paused) { + s->paused = false; + service_kill(s, SIGCONT); + } - s->state = STATE_INACTIVE; + s->fail_count = 0; + if (s->state == STATE_DEAD) + s->state = STATE_INACTIVE; s->status_change = time(NULL); service_update_status(s);