]> git.sesse.net Git - cubemap/commitdiff
Use libsystemd to inform systemd accurately about when the service is up and running.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Mon, 10 Aug 2015 22:13:39 +0000 (00:13 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Mon, 10 Aug 2015 22:15:12 +0000 (00:15 +0200)
Makefile
cubemap.service.in
main.cpp

index d426bc1bae2469f08b367a39965edbecce05b4f5..abadaf7fa2de44975af958092cb7ef94572de514 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -2,8 +2,8 @@ CC=gcc
 CXX=g++
 INSTALL=install
 PROTOC=protoc
-CXXFLAGS=-Wall -O2 -g -pthread $(shell getconf LFS_CFLAGS)
-LDLIBS=-lprotobuf -pthread -lrt
+CXXFLAGS=-Wall -O2 -g -pthread $(shell getconf LFS_CFLAGS) $(shell pkg-config --cflags libsystemd)
+LDLIBS=-lprotobuf -pthread -lrt $(shell pkg-config --libs libsystemd)
 
 OBJS=main.o client.o server.o stream.o udpstream.o serverpool.o mutexlock.o input.o input_stats.o httpinput.o udpinput.o parse.o config.o acceptor.o stats.o accesslog.o thread.o util.o log.o metacube2.o sa_compare.o state.pb.o
 
index 442e01961952bd6487c49035f0ec89afa53923a4..9fe97eddf26e2bfca252b413f223750863d5bf44 100644 (file)
@@ -2,7 +2,7 @@
 Description=Cubemap stream relay
 
 [Service]
-Type=simple
+Type=notify
 ExecStart=@prefix@/bin/cubemap @sysconfdir@/cubemap.config
 User=cubemap
 ExecReload=/bin/kill -HUP $MAINPID
index 98d0948de80f9acd835ee5dbea56e8290b15acda..eccf6d707b40b76ba7231af7dc32b9aec76c1865 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -9,6 +9,7 @@
 #include <string.h>
 #include <sys/time.h>
 #include <sys/wait.h>
+#include <systemd/sd-daemon.h>
 #include <unistd.h>
 #include <algorithm>
 #include <map>
@@ -541,10 +542,18 @@ start:
                log(INFO, "Re-exec happened in approx. %.0f ms.", glitch_time * 1000.0);
        }
 
+       sd_notify(0, "READY=1");
+
        while (!hupped) {
                usleep(100000);
        }
 
+       if (stopped) {
+               sd_notify(0, "STOPPING=1");
+       } else {
+               sd_notify(0, "RELOADING=1");
+       }
+
        // OK, we've been HUPed. Time to shut down everything, serialize, and re-exec.
        err = clock_gettime(CLOCK_MONOTONIC, &serialize_start);
        assert(err != -1);