A reminder...
Any networking services should be handles by rc.init2 and simply requires making the appropriate script in /etc/rc.d executable.
But if we add our own custom script, then we can add the following to rc.local
# Start MCR Monitor
if [ -x /etc/rc.d/rc.mcr_monitor ]; then
echo "Starting MCR Monitor..."
. /etc/rc.d/rc.mcr_monitor start
fi
similarly, we can create rc.local_shutdown with the same permissions as rc.local and add the following;
# Stop MCR Monitor
if [ -x /etc/rc.d/rc.mcr_monitor ]; then
echo "Stopping MCR Monitor..."
. /etc/rc.d/rc.mcr_monitor stop
fi
We could add the above to /etc/rc.M and /etc/rc.K but I prefer the former.
Example of a generic control script is as below;
#
# run control file for NAME
#
# User options:
#
# USER: set an alternative uid (default: www)
# GROUP: set an alternative group (default: www)
#
USER=root
GROUP=root
PRGNAM=mcr_monitor
BIN=/usr/bin/mcr_monitor
#CONF=/etc/prog.conf
#ARGS=-c $CONF -u $USER -g $GROUP
PID=/var/run/mcr_monitor/mcr_monitor.pid
magicd_start()
{
if [ ! -r $CONF ]; then
echo "No configuration file available. Aborting"
exit 1
fi
if [ -s $PID ]; then
echo "$PRGNAM is already running: $(cat $PID)"
exit 1
fi
if [ -x $BIN ]; then
echo "Starting $PRGNAM: $BIN $ARGS"
$BIN
fi
}
magicd_stop()
{
if [ -s $PID ]; then
kill -QUIT $(cat $PID)
fi
}
magicd_restart()
{
magicd_stop
sleep 3 # NOTE: adjust or remove if possible
magicd_start
}
magicd_status()
{
if [ -s $PID ]; then
echo "$PRGNAM is running: $(cat $PID)"
else
echo "$PRGNAM does not seem to be running"
fi
}
case $1 in
restart)
magicd_restart
;;
start)
magicd_start
;;
status)
magicd_status
;;
stop)
magicd_stop
;;
*)
echo "Usage: $0 {restart|start|status|stop}"
;;
esac
No comments:
Post a Comment
Note: only a member of this blog may post a comment.