Skip to content

Instantly share code, notes, and snippets.

@infinityhacks
Forked from 3rd-Eden/monitrc
Created July 12, 2016 08:30
Show Gist options
  • Save infinityhacks/a1c71a403a76fc200b926921576fa311 to your computer and use it in GitHub Desktop.
Save infinityhacks/a1c71a403a76fc200b926921576fa311 to your computer and use it in GitHub Desktop.
monit nodejs deployment
###############################################################################
## Includes
###############################################################################
##
## It is possible to include additional configuration parts from other files or
## directories.
#
# include /etc/monit.d/*
#
#
set logfile /var/log/monit.log
check host nodejs with address 127.0.0.1
start program = "/etc/init.d/nodestats start"
stop program = "/etc/init.d/nodestats stop"
if failed port 7331 protocol HTTP
request /ping
with timeout 10 seconds
then restart
#! /bin/sh
### BEGIN INIT INFO
# Provides: server.js
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts nodejs and server.js
# Description: starts nodejs and server.js using forever
### END INIT INFO
NODE_PATH=/usr/local/lib/node_modules
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/local/bin/forever
NAME=forever
DESC=nodestats
test -x $DAEMON || exit 0
set -e
case "$1" in
start)
echo -n "Starting $DESC: "
exports NODE_PATH=$NODE_PATH
$DAEMON start /www/OMG-ADD-YOUR-DIRECTORY-HERE-LAL/server.js
echo "$NAME."
;;
stop)
echo -n "Stopping $DESC: "
$DAEMON stop /www/OMG-ADD-YOUR-DIRECTORY-HERE-LAL/server.js
echo "$NAME."
;;
restart|force-reload)
echo -n "Stopping $DESC: "
$DAEMON stop /www/OMG-ADD-YOUR-DIRECTORY-HERE-LAL/server.js
echo "$NAME."
sleep 1
echo -n "Starting $DESC: "
exports NODE_PATH=$NODE_PATH
$DAEMON start /www/OMG-ADD-YOUR-DIRECTORY-HERE-LAL/server.js
echo "$NAME."
;;
*)
N=/etc/init.d/$NAME
echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2
exit 1
;;
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment