diff --git a/ambed/cambeserver.cpp b/ambed/cambeserver.cpp index 9ce1da2..ce25b8b 100644 --- a/ambed/cambeserver.cpp +++ b/ambed/cambeserver.cpp @@ -27,6 +27,7 @@ #include "ccontroller.h" #include "cvocodecs.h" #include "cambeserver.h" +#include //////////////////////////////////////////////////////////////////////////////////////// @@ -81,6 +82,7 @@ bool CAmbeServer::Start(void) { // m_pThread = new std::thread(CAmbeServer::Thread, this); + sd_notify(0, "READY=1"); } // done diff --git a/ambed/cvocodecs.cpp b/ambed/cvocodecs.cpp index c9e4643..d3fe698 100644 --- a/ambed/cvocodecs.cpp +++ b/ambed/cvocodecs.cpp @@ -25,6 +25,7 @@ #include "main.h" #include #include "cvocodecs.h" +#include //////////////////////////////////////////////////////////////////////////////////////// // global object @@ -243,10 +244,12 @@ bool CVocodecs::Init(void) if ( ok ) { std::cout << "Codec interfaces initialized successfully : " << iNbCh << " channels available" << std::endl; + sd_notifyf(0, "STATUS=Codec interfaces initialized successfully : %i channels available", iNbCh); } else { std::cout << "At least one codec interfaces failed to initialize : " << iNbCh << " channels availables" << std::endl; + sd_notifyf(0, "STATUS=At least one codec interfaces failed to initialize : %i channels availables", iNbCh); } // done return ok; diff --git a/ambed/makefile b/ambed/makefile index c556a28..ce8912d 100644 --- a/ambed/makefile +++ b/ambed/makefile @@ -8,7 +8,8 @@ EXECUTABLE=ambed all: $(SOURCES) $(EXECUTABLE) $(EXECUTABLE): $(OBJECTS) - $(CC) $(LDFLAGS) $(OBJECTS) -lftd2xx -Wl,-rpath,/usr/local/lib -o $@ + $(CC) $(LDFLAGS) $(OBJECTS) -lftd2xx -Wl,-rpath,/usr/local/lib -lsystemd -o $@ + .cpp.o: $(CC) $(CFLAGS) $< -o $@ diff --git a/dashboard/pgs/class.reflector.php b/dashboard/pgs/class.reflector.php index 099599c..9bf1f8c 100755 --- a/dashboard/pgs/class.reflector.php +++ b/dashboard/pgs/class.reflector.php @@ -109,6 +109,18 @@ class xReflector { else { $this->ProcessIDFile = null; $this->ServiceUptime = null; + + exec('/usr/bin/systemctl show --property=ActiveEnterTimestamp xlxd.service', $out, $code); + if ($code == 0) { + if (is_array($out) && count($out) > 0) { + $out = $out[0]; + } + if (is_string($out)) { + $out = explode('=', $out, 2)[1]; + $out = strtotime($out); + $this->ServiceUptime = time() - $out; + } + } } } diff --git a/scripts/ambed.service b/scripts/ambed.service index 8332fae..2ee0895 100644 --- a/scripts/ambed.service +++ b/scripts/ambed.service @@ -1,9 +1,10 @@ [Unit] Description=AMBE Transcoder Daemon After=network.target +Requires=network-online.target [Service] -Type=simple +Type=notify User=root Group=root ExecStartPre=-/sbin/rmmod ftdi_sio diff --git a/scripts/ambedwatchdog b/scripts/ambedwatchdog new file mode 100644 index 0000000..4953802 --- /dev/null +++ b/scripts/ambedwatchdog @@ -0,0 +1,5 @@ +#!/bin/sh +if journalctl -u ambed.service --since "5min ago" --grep 'Device .* is unresponsive'; then + systemctl restart ambed.service + systemctl restart xlxd.service +fi diff --git a/scripts/ambedwatchdog.service b/scripts/ambedwatchdog.service new file mode 100644 index 0000000..83a898f --- /dev/null +++ b/scripts/ambedwatchdog.service @@ -0,0 +1,7 @@ +[Unit] +Description=Check ambedwatchdog +After=network.target + +[Service] +Type=simple +ExecStart=/usr/bin/ambedwatchdog diff --git a/scripts/ambedwatchdog.timer b/scripts/ambedwatchdog.timer new file mode 100644 index 0000000..6ceb90f --- /dev/null +++ b/scripts/ambedwatchdog.timer @@ -0,0 +1,10 @@ +[Unit] +Description=Contiously monitor ambed if it crashes +Requires=xlxd.service ambed.service + +[Timer] +OnCalendar=*-*-* *:*:0/5 +Unit=ambedwatchdog.service + +[Install] +WantedBy=multi-user.target diff --git a/scripts/xlxapi-update b/scripts/xlxapi-update new file mode 100755 index 0000000..ff45d13 --- /dev/null +++ b/scripts/xlxapi-update @@ -0,0 +1,3 @@ +#!/bin/bash +/usr/bin/wget -q -O- http://localhost/index.php?callhome=1 > /dev/null + diff --git a/scripts/xlxapi-update.service b/scripts/xlxapi-update.service new file mode 100644 index 0000000..9e5aa85 --- /dev/null +++ b/scripts/xlxapi-update.service @@ -0,0 +1,9 @@ +[Unit] +Description=XLX API Service +After=network.target + +[Service] +Type=simple +ExecStart=/usr/bin/xlxapi-update + + diff --git a/scripts/xlxapi-update.timer b/scripts/xlxapi-update.timer new file mode 100644 index 0000000..73570ae --- /dev/null +++ b/scripts/xlxapi-update.timer @@ -0,0 +1,9 @@ +[Unit] +Description=Run xlx api call every day (if nobody opens the dashboard) + +[Timer] +OnCalendar=*-*-* 1:0:0 +Unit=xlxapi-update.service + +[Install] +WantedBy=multi-user.target diff --git a/scripts/xlxd.service b/scripts/xlxd.service new file mode 100644 index 0000000..362aece --- /dev/null +++ b/scripts/xlxd.service @@ -0,0 +1,16 @@ +[Unit] +Description=XLX Reflector (XLX999) +After=network.target ambed.service +Requires=network-online.target + +[Service] +Type=notify +User=xlxd +Group=xlxd +AmbientCapabilities=CAP_NET_RAW +ExecStart=/xlxd/xlxd XLX999 1.2.3.4 127.0.0.1 +Restart=on-abnormal +RestartSec=30 + +[Install] +WantedBy=multi-user.target diff --git a/src/creflector.cpp b/src/creflector.cpp index a813df9..8431203 100644 --- a/src/creflector.cpp +++ b/src/creflector.cpp @@ -31,6 +31,7 @@ #include "ctranscoder.h" #include "cysfnodedirfile.h" #include "cysfnodedirhttp.h" +#include //////////////////////////////////////////////////////////////////////////////////////// // constructor @@ -132,6 +133,7 @@ bool CReflector::Start(void) #ifdef JSON_MONITOR m_JsonReportThread = new std::thread(CReflector::JsonReportThread, this); #endif + sd_notify(0, "READY=1"); } else { diff --git a/src/makefile b/src/makefile index 2d7b587..89304c9 100644 --- a/src/makefile +++ b/src/makefile @@ -1,6 +1,6 @@ CC=g++ CFLAGS=-c -std=c++11 -pthread -LDFLAGS=-std=c++11 -pthread +LDFLAGS=-std=c++11 -pthread -lsystemd SOURCES=$(wildcard *.cpp) OBJECTS=$(SOURCES:.cpp=.o) EXECUTABLE=xlxd