Created
May 10, 2011 08:18
-
-
Save 3rd-Eden/964088 to your computer and use it in GitHub Desktop.
monit nodejs deployment
This file contains hidden or 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
############################################################################### | |
## 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 |
This file contains hidden or 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: 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
Add the
monitrc
in your/etc/monit/monitrc
fileMove the
nodestats
to/etc/init.d/nodestats
.And make sure your
server.js
has aping
hook. In this setup I just add a simple response to the ping requests using