diff options
author | June McEnroe <june@causal.agency> | 2020-08-15 15:29:58 -0400 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2020-08-15 15:29:58 -0400 |
commit | 92d27e09c3a6c66e6a14b35a3666a04eaa54813a (patch) | |
tree | 046ee579b3a5a189ce7d9d3c6cde6757537439e3 /service.c | |
parent | Parse control commands (diff) | |
download | catsit-92d27e09c3a6c66e6a14b35a3666a04eaa54813a.tar.gz catsit-92d27e09c3a6c66e6a14b35a3666a04eaa54813a.zip |
Implement service status
Diffstat (limited to '')
-rw-r--r-- | service.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/service.c b/service.c index 718397d..45a05d2 100644 --- a/service.c +++ b/service.c @@ -112,6 +112,37 @@ err: return -1; } +void serviceStatus(struct Service *service) { + if (service->state == Stop && service->intent == Stop) { + syslog(LOG_INFO, "%s is stopped", service->name); + } else if (service->state == Stop && service->intent == Start) { + struct timespec now, timeleft; + clock_gettime(CLOCK_MONOTONIC, &now); + timespecsub(&service->restartDeadline, &now, &timeleft); + syslog( + LOG_INFO, "%s is restarting in %jds", + service->name, (intmax_t)timeleft.tv_sec + ); + } else if (service->state == Stop && service->intent == Restart) { + syslog(LOG_INFO, "%s is restarting", service->name); + } else if (service->state == Start && service->intent == Start) { + syslog( + LOG_INFO, "%s[%jd] is started", + service->name, (intmax_t)service->pid + ); + } else if (service->state == Start && service->intent == Stop) { + syslog( + LOG_INFO, "%s[%jd] is stopping", + service->name, (intmax_t)service->pid + ); + } else if (service->state == Start && service->intent == Restart) { + syslog( + LOG_INFO, "%s[%jd] is stopping for restart", + service->name, (intmax_t)service->pid + ); + } +} + static void setDeadline(struct Service *service) { clock_gettime(CLOCK_MONOTONIC, &service->restartDeadline); timespecadd( |