From 3bca49214c2ccba5dbbf839e424a314a49110438 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Mon, 29 Jan 2018 14:04:31 +0100 Subject: [PATCH] Added 'sats.main' to manage all SATS debug (out) routines + added instance service to enable/disable --- sats-debug@.service | 13 +++++++++++++ sats/main | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 sats-debug@.service create mode 100644 sats/main diff --git a/sats-debug@.service b/sats-debug@.service new file mode 100644 index 0000000..966fb16 --- /dev/null +++ b/sats-debug@.service @@ -0,0 +1,13 @@ +[Unit] +Description=[::SATS::] Debugger (to %i) + +[Service] +Type=simple +Restart=always +User=pi +Group=pi +ExecStart=/usr/bin/git clone -b master ssh://smmp-server/satsd/git /service/debug; +ExecStart=/bin/bash /service/debug/sats/main %i + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/sats/main b/sats/main new file mode 100644 index 0000000..d4f8aa4 --- /dev/null +++ b/sats/main @@ -0,0 +1,43 @@ +#!/bin/bash + +# (1) Primary init. +#--------------------------------------------------------# +# (1) Get absolute folder # +ROOT=$(dirname `realpath $0`); +ROOT=`dirname $ROOT`; + +# (2) Check config file # +test ! -f $ROOT/com/config/sats && echo "Daemon not started" && exit 1; + +# (3) Fetch BUFFERS # +source $ROOT/com/config/sats; + +# (4) Check required arguments +test $# -lt 1 && echo -e "ERR: Missing argument\n\n\tSATS_ID\tThe id for the bash-socket\n" && exit 1; + + +# (2) Start server in background +#--------------------------------------------------------# +# (1) Start server # +$ROOT/com/launch sats $1 44441 44440 9999& + +# (2) Save PID for later # +SERV_PID=$!; + + +# (3) Start daemons +#--------------------------------------------------------# +# (1) GPIO daemon # +$ROOT/sats/gpio&; +GPIO_PID=$!; + +# (2) SYSTEMD daemon # +$ROOT/sats/sysd&; +SYSD_PID=$!; + + + +# (4) Attach processes to itself +#--------------------------------------------------------# +trap "kill -9 $SERV_PID 2>/dev/null; kill -9 $GPIO_PID 2>/dev/null; kill -9 $SYSD_PID 2>/dev/null; exit 1;" INT; +trap "kill -9 $SERV_PID 2>/dev/null; kill -9 $GPIO_PID 2>/dev/null; kill -9 $SYSD_PID 2>/dev/null; exit 1;" KILL;