summary refs log tree commit diff
path: root/service.c
diff options
context:
space:
mode:
Diffstat (limited to 'service.c')
-rw-r--r--service.c31
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(