Skip to content

Commit

Permalink
added config generation for monit and upstart
Browse files Browse the repository at this point in the history
  • Loading branch information
DracoBlue committed Sep 25, 2011
1 parent 425b66d commit 03a69b0
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -9,6 +9,7 @@ Spludo is copyright 2009-2011 by DracoBlue <http://dracoblue.net>

## 1.1.0-dev

* generator for monit+upstart configuration
* code generation for migrations extended with shortcut fields definition
* added support for application/json paylod
* generate *ByIds method for services
Expand Down
78 changes: 78 additions & 0 deletions build/generate_monit_config.bash
@@ -0,0 +1,78 @@
#!/bin/bash

appname="$1"
port="$2"

if [ -z "$appname" ]
then
echo "Missing application name!"
echo ""
echo "Correct usage:"
echo " sudo $0 app_name port"
echo "For Example:"
echo " sudo $0 my_magic_app 3000"
exit 1
fi

if [ -z "$port" ]
then
echo "Missing port!"
echo ""
echo "Correct usage:"
echo " sudo $0 app_name port"
echo "For Example:"
echo " sudo $0 my_magic_app 3000"
exit 1
fi

username=`ls -al | head -n 2 | tail -n "1" | tr -s " " | cut -f "3" -d " "`
group=`ls -al | head -n 2 | tail -n "1" | tr -s " " | cut -f "4" -d " "`

echo "Configuring for:"
echo " application_name: $appname"
echo " port: $port"
echo " username: $username"
echo " group: $group"

upstartconf_name="/etc/init/$appname.conf"
monitrc_name="/etc/monit/conf.d/$appname.monitrc"
logfile_name="`pwd`/node.log"

echo "Will generate:"
echo " $monitrc_name"
echo " $upstartconf_name"
echo "The daemons output will be stored at:"
echo " $logfile_name"

echo "Press enter to continue ... (stop with CTRL+C)"
read

echo -n "" > $monitrc_name
echo "check process $appname" >> $monitrc_name
echo " with pidfile \"/var/run/$appname.pid\"" >> $monitrc_name
echo " start program = \"/sbin/start $appname\"" >> $monitrc_name
echo " stop program = \"/sbin/stop $appname\"" >> $monitrc_name
echo " if 2 restarts within 3 cycles then timeout" >> $monitrc_name
echo " if totalmem > 100 Mb then alert" >> $monitrc_name
echo " if children > 255 for 5 cycles then stop" >> $monitrc_name
echo " if cpu usage > 95% for 3 cycles then restart" >> $monitrc_name
echo " if failed port $port protocol http" >> $monitrc_name
echo " request /" >> $monitrc_name
echo " with timeout 5 seconds" >> $monitrc_name
echo " then restart" >> $monitrc_name

echo "#!upstart" > $upstartconf_name
echo "description \"$appname nodejs server\"" >> $upstartconf_name
echo "author \"spludo generator\"" >> $upstartconf_name
echo "" > $upstartconf_name
echo "start on (local-filesystems and net-device-up IFACE=eth0)" >> $upstartconf_name
echo "stop on runlevel 0" >> $upstartconf_name
echo "" > $upstartconf_name
echo "respawn # restart when job dies" >> $upstartconf_name
echo "respawn limit 5 60 # give up restart after 5 respawns in 60 seconds" >> $upstartconf_name
echo "" > $upstartconf_name
echo "script " >> $upstartconf_name
echo " exec start-stop-daemon --start --make-pidfile --pidfile /var/run/$appname.pid --chdir `pwd` --chuid $username:$group --exec /usr/local/bin/node run_server.js 2>&1 >> \"$logfile_name\"" >> $upstartconf_name
echo "end script" >> $upstartconf_name

echo "Finished. Please restart monit with /etc/init.d/monit restart"

0 comments on commit 03a69b0

Please sign in to comment.