#! /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 if [ -d $UTM_BIN ] then var0=0 else echo "no /opt/utm" fi UPD_BINDIR=/opt/utm/updater/bin/ if [ -d $UPD_BINDIR ] then var0=0 else echo "no /opt/utm/updater/bin" fi UPD_BIN=/opt/utm/updater/bin/transport-updater.sh if [ -e $UPD_BIN ] then var0=0 else echo "no /opt/utm/updater/bin/transport-updater.sh" fi UPD_PID=/var/run/updater.pid UPD_LOG=/var/log/updater.log TRA_BINDIR=/opt/utm/transporter/bin/ if [ -d $TRA_BINDIR ] then var0=0 else echo "no /opt/utm/transporter/bin/" fi TRA_BIN=/opt/utm/transporter/bin/transport.sh if [ -e $TRA_BIN ] then var0=0 else echo "no /opt/utm/transporter/bin/transport.sh" fi 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... echo "all ok" case "$1" in start) echo "Starting EGAIS UTM updater..." cd $UPD_BINDIR sh $UPD_BIN &>> $UPD_LOG status=$? log_end_msg $status 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 & status=$? log_end_msg $status 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 8080 | wc -l)" -eq 1 ] then echo "Web started correctly." if [ "$(curl -I http://localhost:8080/ 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 status=$? log_end_msg $status ;; stop) echo -n "Shutting down UTM: " kill -s 9 $(cat $TRA_PID) kill -s 9 $(cat $UPD_PID) echo "All done!" status=$? log_end_msg $status ;; restart) $0 stop $0 start status=$? log_end_msg $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 8080 | wc -l)" -eq 1 ] then echo "web run correctly." let i=$i+1 if [ "$(curl -I http://localhost:8080/ 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 status=$i log_end_msg $status ;; *) echo "Usage: $0 {start|stop|restart|status}" exit 1 ;; esac exit 0