Last active
December 24, 2015 23:09
-
-
Save hairyhum/6878022 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/sh | |
### BEGIN INIT INFO | |
# Provides: skeleton | |
# Required-Start: $remote_fs $syslog | |
# Required-Stop: $remote_fs $syslog | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: Example initscript | |
# Description: This file should be used to construct scripts to be | |
# placed in /etc/init.d. | |
### END INIT INFO | |
# Author: Foo Bar <foobar@baz.org> | |
# | |
# Please remove the "Author" lines above and replace them | |
# with your own name if you copy and modify this script. | |
# Do NOT "set -e" | |
# PATH should only include /usr/* if it runs after the mountnfs.sh script | |
PATH=/sbin:/usr/sbin:/opt/bin:/bin:/usr/bin | |
DESC="Buymeapie erlang server" | |
NAME=buymeapie_erl | |
APP_DIR=/srv/buymeapie/current/erl_front/rel/front | |
PIDFILE=/var/run/$NAME.pid | |
SCRIPTNAME=/etc/init.d/$NAME | |
# Read configuration variable file if it is present | |
[ -r /etc/default/$NAME ] && . /etc/default/$NAME | |
BIN_DIR=$APP_DIR/bin | |
DAEMON=$BIN_DIR/front | |
PID_SOURCE=$APP_DIR/pid.pid | |
# Exit if the package is not installed | |
[ -x "$DAEMON" ] || exit 3 | |
DAEMON_CMD="sudo -u buymeapie HOME=/tmp $DAEMON" | |
# Load the VERBOSE setting and other rcS variables | |
#[ -x /lib/init/vars.sh ] && . /lib/init/vars.sh | |
# | |
# Function that starts the daemon/service | |
# | |
do_start() | |
{ | |
# Return | |
# 0 if daemon has been started | |
# 1 if daemon was already running | |
# 2 if daemon could not be started | |
$DAEMON_CMD start || return 1 | |
sleep 5 && pgrep beam || return 2 | |
cp $PID_SOURCE $PIDFILE | |
} | |
# | |
# Function that stops the daemon/service | |
# | |
do_stop() | |
{ | |
# Return | |
# 0 if daemon has been stopped | |
# 1 if daemon was already stopped | |
# 2 if daemon could not be stopped | |
# other if a failure occurred | |
$DAEMON_CMD ping > /dev/null || return 1 | |
$DAEMON_CMD stop | |
RETVAL="$?" | |
[ "$RETVAL" = 2 ] && return 2 | |
rm -f $PIDFILE | |
return "$RETVAL" | |
} | |
# | |
# Function that sends a SIGHUP to the daemon/service | |
# | |
do_reload() { | |
$DAEMON_CMD restart | |
return 0 | |
} | |
log_msg() { | |
echo $1 | |
return 0 | |
} | |
log_error() { | |
echo "Error on $NAME" | |
echo "Service $DESC $2" | |
exit $1 | |
} | |
case "$1" in | |
start) | |
log_msg "Starting $DESC" "$NAME" | |
do_start | |
case "$?" in | |
0) return 0 ;; | |
1) echo "$DESC is already started";return 0 ;; | |
2) log_error 1 "failed to start" ;; | |
esac | |
;; | |
stop) | |
log_msg "Stopping $DESC" "$NAME" | |
do_stop | |
case "$?" in | |
0) return 0 ;; | |
1) echo "$DESC is already stopped"; return 0 ;; | |
2) log_error 2 "could not be stopped" ;; | |
esac | |
;; | |
status) | |
escript $APP_DIR/show_status.escript | |
;; | |
#reload|force-reload) | |
# | |
# If do_reload() is not implemented then leave this commented out | |
# and leave 'force-reload' as an alias for 'restart'. | |
# | |
#log_msg "Reloading $DESC" "$NAME" | |
#do_reload | |
#log_end $? | |
#;; | |
restart|force-reload) | |
# | |
# If the "reload" option is implemented then remove the | |
# 'force-reload' alias | |
# | |
log_msg "Restarting $DESC" "$NAME" | |
do_stop | |
case "$?" in | |
0|1) | |
do_start | |
case "$?" in | |
0) return 0 ;; | |
1) log_error 1 "Old process is still running" ;; | |
*) log_error 2 "failed to start" ;; | |
esac | |
;; | |
*) | |
# Failed to stop | |
log_error 2 "Failed to stop" | |
;; | |
esac | |
;; | |
*) | |
#echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2 | |
echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2 | |
exit 3 | |
;; | |
esac | |
: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set mail-format { | |
from: monit@$HOST | |
subject: monit alert -- $HOST: $EVENT $SERVICE | |
message: $EVENT Service $SERVICE | |
Date: $DATE | |
Action: $ACTION | |
Host: $HOST | |
Description: $DESCRIPTION | |
Your faithful employee, | |
Monit | |
} | |
check process erlang_process with pidfile /run/buymeapie_erl.pid | |
start program = "/etc/init.d/buymeapie_erl start" with timeout 60 seconds | |
stop program = "/etc/init.d/buymeapie_erl stop" with timeout 60 seconds | |
if cpu > 80% for 2 cycles then alert | |
if children > 34 then restart | |
#if loadavg(5min) greater than 10 for 8 cycles then stop | |
if 3 restarts within 5 cycles then timeout | |
group server | |
check host erl_buymeapie with address 127.0.0.1 | |
start program = "/etc/init.d/buymeapie_erl start" with timeout 60 seconds | |
stop program = "/etc/init.d/buymeapie_erl stop" with timeout 60 seconds | |
if failed url http://zabbix:8989@phpd13.buymeapie.com/bauth within 3 cycles then restart | |
#if failed port 8082 within 3 cycles then restart | |
if 10 restarts within 15 cycles then timeout | |
group server | |
check file erl_error_log with path /srv/buymeapie/shared/log/error.log | |
stop program = "/etc/init.d/buymeapie_erl stop" with timeout 60 seconds | |
if match ".* CRASH REPORT .*" then stop | |
#if 3 restarts within 5 cycles then timeout | |
group server |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment