#!/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;