Skip to content

Instantly share code, notes, and snippets.

@physacco
Created April 11, 2013 11:16
Show Gist options
  • Select an option

  • Save physacco/5362583 to your computer and use it in GitHub Desktop.

Select an option

Save physacco/5362583 to your computer and use it in GitHub Desktop.
monit init script for Redhat/Fedora.
#!/bin/sh
# monit: monit init script for Redhat/Fedora.
# Written by physacco. 2013/04/11
# To start at boot time:
# 1. copy this file to /etc/init.d/monit
# 2. chkconfig monit on
# ---------------------
# chkconfig: 2345 50 50
# ---------------------
# Source function library.
. /etc/rc.d/init.d/functions
DAEMON="monit"
DAEMON_PID="/var/run/monit.pid"
DAEMON_EXEC="$(which monit 2>/dev/null)"
start()
{
[ -x "$DAEMON_EXEC" ] || exit 5
echo -n "Starting $DAEMON: "
daemon "$DAEMON_EXEC" -c /etc/monitrc 2>/dev/null
RETVAL=$?
echo
return $RETVAL
}
stop()
{
echo -n "Stopping $DAEMON: "
killproc -p "$DAEMON_PID"
RETVAL=$?
echo
return $RETVAL
}
restart()
{
stop
start
}
rh_status() {
status -p "$DAEMON_PID" "$DAEMON"
}
rh_status_q() {
rh_status &>/dev/null
}
case "$1" in
start)
rh_status_q && exit 0
start
;;
stop)
rh_status_q || exit 0
stop
;;
restart|force-reload)
restart
;;
try-restart|condrestart)
rh_status_q || exit 7
restart
;;
reload)
exit 3
;;
status|status_q)
rh_$1
;;
*)
echo "Usage: $0 {start|stop|restart|reload|status}"
exit 2
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment