ioemu/sats/main

71 lines
1.4 KiB
Plaintext
Raw Normal View History

#!/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)
#--------------------------------------------------------#
2018-01-29 18:04:00 +00:00
# (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;
fi;
# (3) Start daemons
#--------------------------------------------------------#
# (1) GPIO daemon #
2018-01-29 18:00:01 +00:00
$ROOT/sats/gpio&
GPIO_PID=$!;
# (2) SYSTEMD daemon #
2018-01-29 18:00:01 +00:00
$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;
2018-01-29 18:04:00 +00:00
## {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;