about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--daemon.c2
-rw-r--r--daemon.h1
-rw-r--r--service.c31
3 files changed, 33 insertions, 1 deletions
diff --git a/daemon.c b/daemon.c
index 13098af..faf9150 100644
--- a/daemon.c
+++ b/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;
diff --git a/daemon.h b/daemon.h
index b8b288b..b8bcb9b 100644
--- a/daemon.h
+++ b/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);
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(