Skip to content

Instantly share code, notes, and snippets.

@thehunmonkgroup
Last active September 29, 2015 15:35
Show Gist options
  • Save thehunmonkgroup/f1b30f0940f66574191b to your computer and use it in GitHub Desktop.
Save thehunmonkgroup/f1b30f0940f66574191b to your computer and use it in GitHub Desktop.
Redhat-style init script to manage a service using monit commands
#!/usr/bin/env sh
#
# chkconfig: - 99 12
# description: Start apps, monit wrapper.
#
# This script uses the monit process to handle starting and stopping a
# service. This can be used in server configuration management software to
# manage the service programatically, in the case where it's already being
# managed via monit.
SERVICE={{ service_name }}
PIDFILE=/var/run/${SERVICE}.pid
# Load the function library.
. /etc/init.d/functions
RETVAL=0
rh_status() {
status -p ${PIDFILE} ${SERVICE}
}
rh_status_quiet() {
rh_status >/dev/null 2>&1
}
start() {
echo "Starting ${SERVICE}..."
/usr/bin/monit start ${SERVICE}
}
stop() {
echo "Stopping ${SERVICE}..."
/usr/bin/monit stop ${SERVICE}
}
restart() {
echo "Restarting ${SERVICE}..."
/usr/bin/monit restart ${SERVICE}
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
status)
rh_status_quiet
;;
*)
echo $"Usage: $0 {start|stop|restart|status}"
RETVAL=1
esac
exit $RETVAL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment