From b34844d3dc5e104fe3551a7735a780093c0a75f1 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Tue, 30 Jan 2018 22:53:40 +0100 Subject: [PATCH] updated all sats/ structure according to new 'com' lib --- sats/daemon | 61 ------------------------------------- sats/{ => daemon}/gpio | 9 +----- sats/{ => daemon}/sysd | 14 +++------ sats/main | 69 +++++------------------------------------- 4 files changed, 13 insertions(+), 140 deletions(-) delete mode 100755 sats/daemon rename sats/{ => daemon}/gpio (54%) rename sats/{ => daemon}/sysd (71%) diff --git a/sats/daemon b/sats/daemon deleted file mode 100755 index 54941e1..0000000 --- a/sats/daemon +++ /dev/null @@ -1,61 +0,0 @@ -#!/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/gpio b/sats/daemon/gpio similarity index 54% rename from sats/gpio rename to sats/daemon/gpio index 313c62e..8dd1994 100755 --- a/sats/gpio +++ b/sats/daemon/gpio @@ -6,18 +6,11 @@ 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; - - # (2) Start daemon #--------------------------------------------------------# while sleep 1; do - $ROOT/com/write sats "GPIO`cat /home/sats/satsd/conf/machine.state`\n"; + echo "GPIO`cat /home/sats/satsd/conf/machine.state`"; done; \ No newline at end of file diff --git a/sats/sysd b/sats/daemon/sysd similarity index 71% rename from sats/sysd rename to sats/daemon/sysd index 197183b..4682e08 100755 --- a/sats/sysd +++ b/sats/daemon/sysd @@ -6,12 +6,6 @@ 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; - # (2) Start daemon @@ -27,16 +21,16 @@ while sleep 1; do status="`systemctl is-active $serv_name`"; if [ "$status" = "failed" ]; then - echo "SYSD0$serv_name" >> $BUF_OUT; + echo "SYSD0$serv_name"; elif [ "$status" = "inactive" ]; then - echo "SYSD1$serv_name" >> $BUF_OUT; + echo "SYSD1$serv_name"; elif [ "$status" = "activating" ]; then - echo "SYSD2$serv_name" >> $BUF_OUT; + echo "SYSD2$serv_name"; elif [ "$status" = "active" ]; then - echo "SYSD3$serv_name" >> $BUF_OUT; + echo "SYSD3$serv_name"; fi; diff --git a/sats/main b/sats/main index 028b005..ba3b45a 100644 --- a/sats/main +++ b/sats/main @@ -7,68 +7,15 @@ 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; +test $# -lt 2 && echo -e "error: too few arguments\n\n\e[1mUSAGE\e[0m\n\tmain \n\n\e[1mARGUMENTS\e[0m\n\t\tThe key of the pool\n\t\tThe host where the pool is hosted\n" && exit 1; + +# (3) Store arguments # +POOL_KEY="$1"; +POOL_HOST="$2"; + # (2) Start server in background (keep PID) #--------------------------------------------------------# -# (1) Start server (if not already done) # -if [ ! -f $ROOT/sats/.lock ]; then - - $ROOT/com/launch sats $1 44441 44440 9999& - SERV_PID=$!; - - touch $ROOT/sats/.lock; - - # wait for server to be active - sleep 5; - -fi; - - - -# (3) Start daemons -#--------------------------------------------------------# -# (1) GPIO daemon # -$ROOT/sats/gpio& -GPIO_PID=$!; - -# (2) SYSTEMD daemon # -$ROOT/sats/sysd& -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; - - ## {4} Delete lock file ## - echo 'sats.server.lock.delete'; - rm $ROOT/sats/.lock 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 +# (1) Launch master and all deamons # +$ROOT/com/master $POOL_KEY $POOL_HOST 9999 $ROOT/sats/daemon; \ No newline at end of file