Friday, 23 August 2013

Similar method to /etc/init.d

Similar method to /etc/init.d

I have set my script to run using the /etc/init.d method. All works good.
The problem is that my script does packet capturing and when it restarts
the machine after say the crond is loaded then it loads this script of
mine and the packet capture process I guess starting then and it halts
from going further. Is there any method where I can force it only to start
when Linux is fully loaded ?
Below is how my script looks like.
#!/bin/bash
# chkconfig: 2345 95 05
# myapp daemon
# description: myapp daemon
# processname: myapp
DAEMON_PATH="/usr/local/bin/"
DAEMON=pc1.c
#DAEMONOPTS="-my opts"
NAME=pc1.c
DESC="my packet capture"
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
case "$1" in
start)
printf "%-50s" "Starting $NAME..."
insmod /usr/local/pfring/kernel/pf_ring.ko
/usr/local/bin/pc1.c &
$! > PIDFILE
;;
status)
if [ -f $PIDFILE];
then if [ -d /proc/cat $PIDFILE ];
then echo "Process is running";
fi;
else echo "Error! PID file is missing!";
fi
;;
stop)
printf "%-50s" "Stopping $NAME"
PID=`cat $PIDFILE`
cd $DAEMON_PATH
if [ -f $PIDFILE ]; then
kill -HUP $PID
printf "%s\n" "Ok"
rm -f $PIDFILE
else
printf "%s\n" "pidfile not found"
fi
;;
restart)
$0 stop
$0 start
;;
*)
echo "Usage: $0 {status|start|stop|restart}"
exit 1
esac

No comments:

Post a Comment