Save your script in
/etc/init.d/ with exe permissions
statement contain the runlevels to enable the script at, the value to use after the “S” in the start scripts, and the value to use after the “K” in the kill scripts
Lets say file name is vikas
Now
ln -s /etc/init.d/vikas /etc/rc1.d/k97vikas
ln -s /etc/init.d/vikas /etc/rc2.d/k97vikas
ln -s /etc/init.d/vikas /etc/rc3.d/k97vikas
ln -s /etc/init.d/vikas /etc/rc4.d/k97vikas
ln -s /etc/init.d/vikas /etc/rc4.d/S97vikas
ln -s /etc/init.d/vikas /etc/rc5.d/S97vikas
ln -s /etc/init.d/vikas /etc/rc5.d/k97vikas
ln -s /etc/init.d/vikas /etc/rc6.d/S97vikas
ln -s /etc/init.d/vikas /etc/rc6.d/k97vikas
make the symbolic links in the appropriate run levels i.e rc(1-6). dir as above starting from S and K
Add as service
chkconfig --add vikas
Example file
-------------------------------------------------
#!/bin/bash
#
# vikas This shell script takes care of starting and stopping
# named (BIND DNS server).
#
# chkconfig: - 13 87
# description: vikas to start the siproxd \
# probe: true
#echo "************************Vikas Sharma*****************************"
start()
{
touch /root/Desktop/vikas_from_startup_script
echo -e "Started...."
}
stop()
{
touch /root/Desktop/vikas_from_startup_script
echo -e "Stoped..."
}
restart()
{
echo -e "Restarting..."
rm -f /root/Desktop/vikas_from_startup_script
sleep 5
touch /root/Desktop/vikas_from_startup_script
echo -e "Restarted..."
}
status()
{
echo -e "Running..."
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
sleep 3
start
;;
status)
status
;;
*)
echo $"Usage: $0 {start|stop|restart|status}"
exit 3
esac
--------------------------------------------------
Description is must.
On on startup
chkconfig vikas on
No comments:
Post a Comment