summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--service.c39
1 files changed, 32 insertions, 7 deletions
diff --git a/service.c b/service.c
index 39ce60e..0607f80 100644
--- a/service.c
+++ b/service.c
@@ -127,21 +127,46 @@ void serviceDrop(size_t index) {
 	services.ptr[index] = services.ptr[--services.len];
 }
 
+static const char *humanize(struct timespec uptime) {
+	static char buf[256];
+	int days = uptime.tv_sec / (24 * 60 * 60);
+	uptime.tv_sec %= (24 * 60 * 60);
+	int hours = uptime.tv_sec / (60 * 60);
+	uptime.tv_sec %= (60 * 60);
+	int mins = uptime.tv_sec / 60;
+	uptime.tv_sec %= 60;
+	int d, h, m, s;
+	snprintf(
+		buf, sizeof(buf), "%n%dd %n%dh %n%dm %n%ds",
+		&d, days, &h, hours, &m, mins, &s, (int)uptime.tv_sec
+	);
+	if (days) return &buf[d];
+	if (hours) return &buf[h];
+	if (mins) return &buf[m];
+	return &buf[s];
+}
+
 void serviceStatus(struct Service *service) {
+	struct timespec now;
+	clock_gettime(CLOCK_MONOTONIC, &now);
 	if (service->state == Stop && service->intent == Stop) {
 		syslog(LOG_NOTICE, "%s[] is stopped", service->name);
 	} else if (service->state == Stop && service->intent == Start) {
-		struct timespec now, timeleft;
-		clock_gettime(CLOCK_MONOTONIC, &now);
+		struct timespec timeleft;
 		timespecsub(&service->restartDeadline, &now, &timeleft);
 		syslog(
-			LOG_NOTICE, "%s[] is restarting in %lds",
-			service->name, (long)timeleft.tv_sec
+			LOG_NOTICE, "%s[] is restarting in %ds",
+			service->name, (int)timeleft.tv_sec
 		);
 	} else if (service->state == Stop && service->intent == Restart) {
 		syslog(LOG_NOTICE, "%s[] is restarting", service->name);
 	} else if (service->state == Start && service->intent == Start) {
-		syslog(LOG_NOTICE, "%s[%d] is started", service->name, service->pid);
+		struct timespec uptime;
+		timespecsub(&now, &service->startTime, &uptime);
+		syslog(
+			LOG_NOTICE, "%s[%d] is started (up %s)",
+			service->name, service->pid, humanize(uptime)
+		);
 	} else if (service->state == Start && service->intent == Stop) {
 		syslog(LOG_NOTICE, "%s[%d] is stopping", service->name, service->pid);
 	} else if (service->state == Start && service->intent == Restart) {
@@ -324,8 +349,8 @@ void serviceReap(pid_t pid, int status) {
 		}
 		setDeadline(service);
 		syslog(
-			LOG_NOTICE, "%s[%d] restarting in %lds",
-			service->name, pid, (long)service->restartInterval.tv_sec
+			LOG_NOTICE, "%s[%d] restarting in %ds",
+			service->name, pid, (int)service->restartInterval.tv_sec
 		);
 	} else {
 		syslog(LOG_NOTICE, "%s[%d] stopped", service->name, pid);
in/man1/imbox.1?id=6aa7f2f6bf47fa9df9c749ce665171fa30800937&follow=1'>Add first working version of imboxJune McEnroe 2019-12-20Respect mailmap in gl pretty formatJune McEnroe 2019-12-20Set LANG in cgit filtersJune McEnroe ttpre needs to know about UTF-8 too so it can bold/italic non-ASCII chars. 2019-12-20Source .editrc before applying -v or -eJune McEnroe Otherwise a bind -v in .editrc will take precedence and overwrite the ^I binding for sh-complete. 2019-12-20Disable signing commitsJune McEnroe Why did I ever turn this on? This gets me nothing but inconvenience. RIP to all the wasted bytes in my git repos. 2019-12-19Ignore about-filterJune McEnroe 2019-12-19Fix matching make tags with no sourcesJune McEnroe 2019-12-19Avoid matching := assignments as tagsJune McEnroe 2019-12-18Hide line numbers when rendering mdocJune McEnroe Hack: output an extra <td> after rendering mdoc so that line numbers can be hidden based on there being three. This required splitting source-filter and about-filter since on about pages there is no table. 2019-12-18Customize cgit CSSJune McEnroe 2019-12-18Use :target rather than :focus pseudo-classJune McEnroe :target persists after you click on something else. 2019-12-18Copy cgit auxiliary binaries properlyJune McEnroe 2019-12-18Add git.causal.agency cgit configJune McEnroe 2019-12-18Bail from hi if input is binaryJune McEnroe NULs in the input cause an infinite loop in htmlEscape, not to mention regexes obviously not working, etc. 2019-12-16Post "cgit setup"June McEnroe