Commit ba02d3a1 authored by Lorenzo Pivetta's avatar Lorenzo Pivetta

Revised script

parent 6ca2461e
#!/bin/bash
#
# WARNING! WARNING! WARNING!
#
# Do **NOT** edit this file! Your changes will be overwritten!
HOSTNAME=`hostname`
CONFFILE=/runtime/site/${HOSTNAME}/etc/tango.conf
SRV="DataBaseds"
CMD="/usr/local/tango-9.3.3/bin/${SRV}"
ROOT=0
checkmysql() {
NB=`echo "select name from device where name like 'sys/database/$INSTANCE'" | mysql -u tangocheck tango | grep database | wc -l`
if [ $NB -eq 0 ]; then
echo "ERROR: MySQL not running!"
exit 1
fi
}
findproc() {
pid=`ps -ef | grep "$1" | grep -v grep | awk '{print $2}'`
}
killproc() {
pid=`ps -ef | grep "$1" | grep -v grep | awk '{print $2}'`
if [ "$pid" ]; then
kill $pid
fi
}
startsrv()
{
echo -n "Starting ${MYSELF}... "
/bin/rm -f ${CTRLFILE}
${CMD} ${INSTANCE} ${ORB_ENDPOINT} ${ORB_ENDPOINT_PUBLISH} 1>${CTRLFILE} 2>&1
echo "done"
}
checksrv()
{
echo -n "Checking ${MYSELF}... "
loop=0
while [ "$loop" -lt ${RETRY} ]; do
/usr/local/bin/tango_device_check.py sys/database/$INSTANCE >& /dev/null
if [ "$?" -eq 0 ]; then
echo " OK"
break
else
loop=$(($loop+1))
echo -n "."
fi
sleep 1
done
if [ "$loop" -eq ${RETRY} ]; then
echo "FAILED!"
echo "DataBaseds not responding after ${RETRY} seconds!"
fi
}
stopsrv()
{
uid=`id -u`
if [ ${uid} -ne ${ROOT} -a ${uid} -ne ${USERID} ]; then
echo "ERROR: you should be '${USER}' or 'root' to stop ${SRV}"
else
echo -n "Stopping ${MYSELF}... "
killproc "${MYSELF}"
echo " done"
fi
}
statussrv()
{
findproc "$MYSELF"
if [ ${pid} ]; then
echo "${MYSELF} running"
checksrv
else
echo "${MYSELF} NOT running"
fi
}
#
# main
#
if [ -f ${CONFFILE} ]; then
. ${CONFFILE}
else
echo "Error! '${CONFFILE}' file missing!"
exit 0
fi
MYSELF="$SRV $INSTANCE"
CTRLFILE=/runtime/site/${HOSTNAME}/log/ctrl_${SRV}_${INSTANCE}.log
LOGFILE=/runtime/site/${HOSTNAME}/log/${SRV}_${INSTANCE}.log
case "$1" in
start)
checkmysql
startsrv
checksrv
;;
stop)
stopsrv
;;
restart)
stopsrv
sleep 5
startsrv
;;
status)
checkmysql
statussrv
;;
*)
echo "Usage: $0 {start|stop|status|restart}"
exit 0
;;
esac
exit 0
# EOF
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment