2018-01-29 13:04:31 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# (1) Primary init.
|
|
|
|
#--------------------------------------------------------#
|
|
|
|
# (1) Get absolute folder #
|
|
|
|
ROOT=$(dirname `realpath $0`);
|
|
|
|
ROOT=`dirname $ROOT`;
|
|
|
|
|
2018-01-29 14:30:43 +00:00
|
|
|
# (2) Check required arguments
|
2018-01-29 13:04:31 +00:00
|
|
|
test $# -lt 1 && echo -e "ERR: Missing argument\n\n\tSATS_ID\tThe id for the bash-socket\n" && exit 1;
|
|
|
|
|
2018-01-29 17:25:09 +00:00
|
|
|
# (2) Create config dir (if doesn't exist) #
|
2018-01-29 17:32:48 +00:00
|
|
|
test ! -d $ROOT/config && ( mkdir $ROOT/config; sudo chown sats:pi $ROOT/config; sudo chmod 770 $ROOT/config );
|
2018-01-29 13:04:31 +00:00
|
|
|
|
2018-01-29 14:30:43 +00:00
|
|
|
# (2) Start server in background (keep PID)
|
2018-01-29 13:04:31 +00:00
|
|
|
#--------------------------------------------------------#
|
|
|
|
# (1) Start server #
|
|
|
|
$ROOT/com/launch sats $1 44441 44440 9999&
|
|
|
|
SERV_PID=$!;
|
|
|
|
|
|
|
|
|
2018-01-29 14:30:43 +00:00
|
|
|
|
2018-01-29 13:04:31 +00:00
|
|
|
# (3) Start daemons
|
|
|
|
#--------------------------------------------------------#
|
|
|
|
# (1) GPIO daemon #
|
2018-01-29 16:13:14 +00:00
|
|
|
$ROOT/sats/gpio sats&
|
2018-01-29 13:04:31 +00:00
|
|
|
GPIO_PID=$!;
|
|
|
|
|
|
|
|
# (2) SYSTEMD daemon #
|
2018-01-29 16:13:14 +00:00
|
|
|
$ROOT/sats/sysd sats&
|
2018-01-29 13:04:31 +00:00
|
|
|
SYSD_PID=$!;
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-01-29 14:30:43 +00:00
|
|
|
# (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)
|
2018-01-29 13:04:31 +00:00
|
|
|
#--------------------------------------------------------#
|
2018-01-29 14:30:43 +00:00
|
|
|
wait $SERV_PID;
|
|
|
|
on_exit;
|