Script to start/stop application in linux/unix : Gracefully/Smartly/Startup script
#!/bin/sh
APPLICATION_BIN_DIR=/opt/application/bin
prog=application_name
start()
{ pid_check=`ps -eaf | grep application_name | awk '{print $2}'`
if [ -z "$pid_check" ]; then
echo $"Starting $prog: ......."
$APPLICATION_BIN_DIR/StartUp_Script.sh > /dev/null 2> /dev/null &
sleep 15s
pid=`ps -eaf | grep application_name | awk '{print $2}'`
if [ -z $pid ]; then echo " Application is not running.Please start it again..."; exit 0;else
echo "Application_name is running with PID ($pid)....Done";fi
else
echo "Another Instance of Application_name is already running.Please shutdown it first."
fi
}
status ()
{
pid=`ps -eaf | grep application_name | awk '{print $2}'`
if [ -z $pid ]; then echo " Application_name application is not running."; exit 0;else
echo "Application_name is running with PID ($pid)....";fi
}
stop()
{
echo $"Shutting down $prog:.... "
pid=`ps -eaf | grep application_name | awk '{print $2}'`
if [ -z $pid ]; then echo " application_name application is not running.Please start it first."; exit 0;fi
kill -15 $pid
sleep 15s
kill -9 $pid
pid_check=`ps -eaf | grep application_name | awk '{print $2}'`
if [ -z "$pid_check" ]; then echo Application_name shutdown complete; else echo Application_nameshutdown did not compelete; fi
}
case "$1" in
start)
start
;;
status)
status
;;
stop)
stop
;;
restart)
stop
start
;;
*)
echo $"Usage: $0 {start|status|stop|restart}"
esac
label:Scripting
APPLICATION_BIN_DIR=/opt/application/bin
prog=application_name
start()
{ pid_check=`ps -eaf | grep application_name | awk '{print $2}'`
if [ -z "$pid_check" ]; then
echo $"Starting $prog: ......."
$APPLICATION_BIN_DIR/StartUp_Script.sh > /dev/null 2> /dev/null &
sleep 15s
pid=`ps -eaf | grep application_name | awk '{print $2}'`
if [ -z $pid ]; then echo " Application is not running.Please start it again..."; exit 0;else
echo "Application_name is running with PID ($pid)....Done";fi
else
echo "Another Instance of Application_name is already running.Please shutdown it first."
fi
}
status ()
{
pid=`ps -eaf | grep application_name | awk '{print $2}'`
if [ -z $pid ]; then echo " Application_name application is not running."; exit 0;else
echo "Application_name is running with PID ($pid)....";fi
}
stop()
{
echo $"Shutting down $prog:.... "
pid=`ps -eaf | grep application_name | awk '{print $2}'`
if [ -z $pid ]; then echo " application_name application is not running.Please start it first."; exit 0;fi
kill -15 $pid
sleep 15s
kill -9 $pid
pid_check=`ps -eaf | grep application_name | awk '{print $2}'`
if [ -z "$pid_check" ]; then echo Application_name shutdown complete; else echo Application_nameshutdown did not compelete; fi
}
case "$1" in
start)
start
;;
status)
status
;;
stop)
stop
;;
restart)
stop
start
;;
*)
echo $"Usage: $0 {start|status|stop|restart}"
esac
label:Scripting
Comments
Post a Comment