ioemu/sats/main

61 lines
1.2 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)
#--------------------------------------------------------#
# (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;