Implement service status
This commit is contained in:
parent
b7e36c72a6
commit
92d27e09c3
2
daemon.c
2
daemon.c
@ -134,7 +134,7 @@ static void parseControl(char *command) {
|
||||
} else if (!strcmp(action, "restart")) {
|
||||
fn = serviceRestart;
|
||||
} else if (!strcmp(action, "status")) {
|
||||
// TODO
|
||||
fn = serviceStatus;
|
||||
} else {
|
||||
for (int i = 1; i < NSIG; ++i) {
|
||||
if (strcasecmp(action, sys_signame[i])) continue;
|
||||
|
1
daemon.h
1
daemon.h
@ -129,6 +129,7 @@ extern struct Services {
|
||||
} services;
|
||||
|
||||
int serviceAdd(const char *name, const char *command);
|
||||
void serviceStatus(struct Service *service);
|
||||
void serviceStart(struct Service *service);
|
||||
void serviceStop(struct Service *service);
|
||||
void serviceRestart(struct Service *service);
|
||||
|
31
service.c
31
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(
|
||||
|
Loading…
Reference in New Issue
Block a user