From 8e7d0a473364286b782e1d2a85357c70c83f44ca Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Mon, 29 Jan 2018 18:25:09 +0100 Subject: [PATCH] minupdate --- sats-debug@.service | 2 +- sats/daemon | 61 +++++++++++++++++++++++++++++++++++++++++++++ sats/main | 2 ++ 3 files changed, 64 insertions(+), 1 deletion(-) create mode 100755 sats/daemon mode change 100755 => 100644 sats/main diff --git a/sats-debug@.service b/sats-debug@.service index 1d8b5b4..ed87222 100644 --- a/sats-debug@.service +++ b/sats-debug@.service @@ -6,7 +6,7 @@ Type=simple Restart=always User=pi Group=pi -ExecStart=/usr/bin/git clone --recursive -b master ssh://smmp-server/satsd/debug /service/debug +ExecStartPre=/usr/bin/sudo -u sats git clone --recursive -b master ssh://smmp-server/satsd/debug /service/debug ExecStart=/bin/bash /service/debug/sats/main %i ExecStop=/bin/sleep 10 diff --git a/sats/daemon b/sats/daemon new file mode 100755 index 0000000..54941e1 --- /dev/null +++ b/sats/daemon @@ -0,0 +1,61 @@ +#!/bin/bash + +# (1) Primary init. +#--------------------------------------------------------# +# (1) Get absolute folder # +ROOT=$(dirname `realpath $0`); +ROOT=`dirname $ROOT`; + +# (2) 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 (keep PID) +#--------------------------------------------------------# +# (1) Start server # +$ROOT/com/launch sats $1 44441 44440 9999& +SERV_PID=$!; + + + +# (3) Start daemons +#--------------------------------------------------------# +# (1) GPIO daemon # +$ROOT/sats/gpio sats& +GPIO_PID=$!; + +# (2) SYSTEMD daemon # +$ROOT/sats/sysd sats& +SYSD_PID=$!; + + + +# (4) Manage ending proccess +#--------------------------------------------------------# +# (1) Kill subprocesses if Ctrl+C # +on_exit(){ + echo 'sats.main.kill'; + + ## {1} Kill GPIO logger ## + echo 'sats.main.gpio.kill'; + kill -9 $GPIO_PID 2>/dev/null; + + ## {2} Kill SYSD logger ## + echo 'sats.main.sysd.kill'; + kill -9 $SYSD_PID 2>/dev/null; + + ## {3} Kill com server ## + echo 'sats.server.kill'; + kill -9 $SERV_PID 2>/dev/null; + + exit 0; +} + +trap "on_exit" INT KILL; + + + +# (5) Bind server to 'main' (this file) +#--------------------------------------------------------# +wait $SERV_PID; +on_exit; \ No newline at end of file diff --git a/sats/main b/sats/main old mode 100755 new mode 100644 index 54941e1..15d89bd --- a/sats/main +++ b/sats/main @@ -9,6 +9,8 @@ ROOT=`dirname $ROOT`; # (2) 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) Create config dir (if doesn't exist) # +test ! -d $ROOT/config && sudo -u sats ( mkdir $ROOT/config; chown sats:pi $ROOT/config; chmod 770 $ROOT/config ); # (2) Start server in background (keep PID) #--------------------------------------------------------#