Permalink
Browse files

Merge pull request #8 from visionmedia/master

add on-error and on-restart config support
  • Loading branch information...
2 parents e1b35a2 + dd45792 commit 7ed944c357343b53aceb656bca614437b3b9b6a4 @jgallen23 committed Jan 3, 2013
Showing with 67 additions and 15 deletions.
  1. +42 −15 README.md
  2. +8 −0 bin/mongroup
  3. +15 −0 example/alert.js
  4. +2 −0 example/mongroup.conf
View
@@ -1,21 +1,12 @@
-#mongroup
+# mongroup
mongroup is a wrapper for [mon](https://github.com/visionmedia/mon/). It allows you to create easily monitor a group of processes.
##Installation
make install
-##Config File
-A config file lets you define what process you want to run in your mongroup. It also lets you set the directories for where your pids and logs are stored. Here is an example config file:
-
- pids = /var/run/
- logs = /var/log/
- web = node server 8001
- web2 = node server 8002
- redis = redis-server
-
-##Usage
+## Usage
Usage: mongroup [options] [command]
@@ -29,8 +20,44 @@ A config file lets you define what process you want to run in your mongroup. It
start [app] start [app] or all apps
restart [app] restart [app] or all apps
- stop [app] stops [app] or all apps
- status shows the status of all running apps
- log [app] tail the [app]'s log or all apps
- logf [app] tail -f the [app]'s log or all apps
+ stop [app] stops [app] or all apps
+ status shows the status of all running apps
+ log [app] tail the [app]'s log or all apps
+ logf [app] tail -f the [app]'s log or all apps
update update mongroup to the latest version
+
+## Config File
+
+A config file lets you define what process you want to run in your mongroup. It also lets you set the directories for where your pids and logs are stored. Here is an example config file:
+
+ pids = /var/run/
+ logs = /var/log/
+ on-error = ./alert error
+ on-restart = ./alert restart
+ web = node server 8001
+ web2 = node server 8002
+ redis = redis-server
+
+### Failure Hooks
+
+ Mongroup leverages mon(1)'s `--on-error <cmd>` and `--on-restart <cmd>` flags
+ to facilitate reporting and alerting. For example here's a simple non-useful
+ node script outputting to stdio:
+
+```js
+#!/usr/bin/env node
+
+console.log(process.argv);
+
+/*
+
+example:
+
+[ 'node',
+ '/Users/tj/projects/mongroup/example/alert.js',
+ 'restart',
+ 'web2',
+ '58119' ]
+
+*/
+```
View
@@ -5,6 +5,8 @@ CONFIG=./mongroup.conf
REPO=git://github.com/jgallen23/mongroup.git
PIDS=./pids
LOGS=./logs
+ON_RESTART=./restart.sh
+ON_ERROR=./error.sh
#
# Output usage.
@@ -68,6 +70,10 @@ read_config() {
PIDS=$v
elif [[ "$n" == "logs" ]]; then
LOGS=$v
+ elif [[ "$n" == "on-restart" ]]; then
+ ON_RESTART=$v
+ elif [[ "$n" == "on-error" ]]; then
+ ON_ERROR=$v
else
NAMES[i]=$n
CMDS[i]=$v
@@ -103,6 +109,8 @@ start_proc() {
mon -d -p $PIDS/$1.pid \
-m $PIDS/$1.mon.pid \
-l $LOGS/$1.log \
+ --on-error "$ON_ERROR $name" \
+ --on-restart "$ON_RESTART $name" \
"$2"
}
View
@@ -0,0 +1,15 @@
+#!/usr/bin/env node
+
+console.log(process.argv);
+
+/*
+
+example:
+
+[ 'node',
+ '/Users/tj/projects/mongroup/example/alert.js',
+ 'restart',
+ 'web2',
+ '58119' ]
+
+*/
@@ -1,5 +1,7 @@
pids = pids
logs = logs
+on-restart = ./alert.js restart
+on-error = ./alert.js error
web = node server.js 8001
web2 = node server.js 8002
web3 = node server.js 8003

0 comments on commit 7ed944c

Please sign in to comment.