#! /bin/sh #Author: Grigoriy Pletnev ### BEGIN INIT INFO # Provides: utm # Required-Start: $local_fs $network # Required-Stop: $local_fs $network # Default-Start: 3 5 # Default-Stop: # Short-Description: utm daemon # Description: Daemon for EGAIS UTM ### END INIT INFO . /etc/rc.status rc_reset ###Initializatin folders and bin variables UTM_BIN=/opt/utm test -d $UTM_BIN || exit 5 UPD_BINDIR=/opt/utm/updater/bin/ test -d $UPD_BINDIR || exit 5 UPD_BIN=/opt/utm/updater/bin/transport-updater.sh test -x $UPD_BIN || exit 5 UPD_PID=/var/run/updater.pid UPD_LOG=/var/log/updater.log test -e $UPD_PID || touch $UPD_PID test -e $UPD_LOG || touch $UPD_LOG TRA_BINDIR=/opt/utm/transporter/bin/ test -d $TRA_BINDIR || exit 5 TRA_BIN=/opt/utm/transporter/bin/transport.sh test -x $TRA_BIN || exit 5 TRA_PID=/var/run/transporter.pid TRA_LOG=/var/log/transporter.log test -e $TRA_PID || touch $TRA_PID test -e $TRA_LOG || touch $TRA_LOG ###We need write pid updater and transporter to file for kill him if [ "$(cat $UPD_BIN | grep "echo \$!")" == "" ] then sed -i "s/\"\$@\"/\"\$@\"\ \&/" $UPD_BIN echo "echo \$! > /var/run/updater.pid" >> $UPD_BIN echo "exit 0" >> $UPD_BIN fi if [ "$(cat $TRA_BIN | grep "echo \$!")" == "" ] then sed -i "s/\"\$@\"/\"\$@\"\ \&/" $TRA_BIN echo "echo \$! > /var/run/transporter.pid" >> $TRA_BIN echo "exit 0" >> $TRA_BIN fi ###Initialization done... case "$1" in start) echo "Starting EGAIS UTM updater..." cd $UPD_BINDIR startproc $UPD_BIN -l $UPD_LOG rc_status -v sleep 30 if [ "$(netstat -napl | grep 8193 | wc -l)" -eq 1 ] then echo "Updater with PID $(cat $UPD_PID) started correctly." else echo "Updater start failed." exit 1 fi echo "Starting EGAIS UTM transporter..." cd $TRA_BINDIR sh $TRA_BIN &> $TRA_LOG & sleep 90 if [ "$(netstat -napl | grep 8192 | wc -l)" -eq 1 ] then echo "Transporter with PID $(cat $TRA_PID) started correctly." else echo "Transporter start failed." fi if [ "$(netstat -napl | grep 8081 | wc -l)" -eq 1 ] then echo "Web started correctly." if [ "$(curl -I http://localhost:8081/ 2> /dev/null | head -n 1 | grep OK | wc -l)" -eq 1 ] then echo "web work!" else echo "web doesnt work(((" fi else echo "Web start failed" fi rc_status -v ;; stop) echo -n "Shutting down UTM: " kill -s 9 $(cat $TRA_PID) kill -s 9 $(cat $UPD_PID) echo "All done!" rc_status -v ;; restart) $0 stop $0 start rc_status ;; status) i=0 echo -n "Checking for UTM: " if [ "$(netstat -pl | grep 8193 | wc -l)" -eq 1 ] then echo "Updater run correctly." let i=$i+1 else echo "Updater run failed." fi if [ "$(netstat -pl | grep 8192 | wc -l)" -eq 1 ] then echo "Transporter run correctly." let i=$i+1 else echo "Transporter run failed." fi if [ "$(netstat -pl | grep 8081 | wc -l)" -eq 1 ] then echo "web run correctly." let i=$i+1 if [ "$(curl -I http://localhost:8081/ 2> /dev/null | head -n 1 | grep OK | wc -l)" -eq 1 ] then echo "web work." let i=$i+1 else echo "web doesnt work(((" fi else echo "web doesnt run." fi if [ "$i" -ne 4 ] then rc_failed else rc_active exit 1 fi rc_status -v ;; *) echo "Usage: $0 {start|stop|restart|status}" exit 1 ;; esac exit 0