Hi guys,
I've come to a road block so i need some help.
1)I have an exe which i need to run at start up.
So I put the following bash file in the inid.d directory:
#!/bin/bash
#
#
. /etc/rc.d/init.d/functions
EXE_DIR="/root/monkey-0.9.2/bin/"
EXE_NAME="monkey"
#############################################################
#################### Functions ##############################
#############################################################
function start {
RUNNING=`ps -ef | grep -c ./${EXE_NAME}\$`
if [ $RUNNING -ge 1 ]; then
echo "${EXE_NAME} is already running"
echo_failure
echo ""
else
if [ ! -x "${EXE_DIR}${EXE_NAME}" ]; then
echo ""
echo "[error] ${EXE_NAME} doesn't exist"
echo_failure
echo ""
else
cd "${EXE_DIR}"
sleep 1
./${EXE_NAME} > output &
disown
echo "Restarting ${EXE_NAME}"
echo_ok
echo ""
fi
fi
}
function stop {
echo ""
echo "Stopping ${EXE_NAME}"
RUNNING=`ps -ef | grep -c ./${EXE_NAME}\$`
if [ $RUNNING -ge 1 ]; then
ID=`ps -ef | grep ${EXE_NAME} | grep -v grep | awk '{print $2}'`
echo "PID= $ID"
kill -9 $ID
echo_ok
echo ""
else
echo "${EXE_NAME} is not running"
echo_failure
echo ""
fi
return 0;
}
function restart {
stop
start
return 1;
}
function status {
RUNNING=`ps -ef | grep -c ./${EXE_NAME}\$`
if [ $RUNNING -ge 1 ]; then
echo "${EXE_NAME} Running"
echo_ok
echo ""
tail -f "${EXE_DIR}output"
else
echo "${EXE_NAME} Not Running"
echo_failure
echo ""
fi
}
#############################################################
###################### MAIN #################################
#############################################################
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
details|status)
status
;;
*)
exit 1
esac
exit 0
The funny thing is the pid says it is running on boot. But it only works when I log on and restart the program manually?!
Any ideas?