Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit e1c23b4a99b39af55c98465e7c2b39df8060fa8d @tj committed Apr 12, 2012
Showing with 444 additions and 0 deletions.
  1. +3 −0 .gitignore
  2. +1 −0 History.md
  3. +22 −0 Makefile
  4. +56 −0 Readme.md
  5. +9 −0 example.sh
  6. +353 −0 src/mon.c
@@ -0,0 +1,3 @@
+*.o
+mon.log
+mon
@@ -0,0 +1 @@
+
@@ -0,0 +1,22 @@
+
+PREFIX = /usr/local
+SRC = src/mon.c
+OBJ = $(SRC:.c=.o)
+CFLAGS = -D_GNU_SOURCE -std=c99
+
+mon: $(OBJ)
+ $(CC) $^ -o $@
+
+%.o: %.c
+ $(CC) $< $(CFLAGS) -c -o $@
+
+install: mon
+ cp -f mon $(PREFIX)/bin/mon
+
+uninstall:
+ rm -f $(PREFIX)/bin/mon
+
+clean:
+ rm -f mon $(OBJ)
+
+.PHONY: clean install uninstall
@@ -0,0 +1,56 @@
+
+# mon(1)
+
+ Super-simple monitoring program.
+
+ Effectively all it does is daemonize some programs,
+ re-executing the program on failure, write pidfiles,
+ and provide status checks.
+
+## Installation
+
+```
+$ make install
+```
+
+## Usage
+
+```
+
+Usage: mon [options] <cmd>
+
+Options:
+
+ -s, --sleep <sec> sleep seconds before re-executing [1]
+ -S, --status check status of --pidfile
+ -l, --log <file> specify logfile [mon.log]
+ -d, --daemonize daemonize the program
+ -p, --pidfile <path> write pid to <path>
+ -P, --prefix <str> add a log prefix <str>
+ -v, --version output program version
+ -h, --help output help information
+
+```
+
+## Example
+
+ `mon(1)` is designed to monitor a single program only, this means a few things,
+ firstly that a single `mon(1)` may crash and it will not influence other programs,
+ secondly that the "configuration" for `mon(1)` is simply a shell script,
+ no need for funky weird inflexible DSLs.
+
+```bash
+#!/usr/bin/env bash
+
+pids="/var/run"
+app="/www/example.com"
+
+mon -d redis-server -p $pids/redis.pid
+mon -d "node $app/app" -p $pids/app-0.pid
+mon -d "node $app/jobs" -p $pids/jobs-0.pid
+mon -d "node $app/jobs" -p $pids/jobs-1.pid
+mon -d "node $app/jobs" -p $pids/jobs-2.pid
+mon -d "node $app/image" -p $pids/image-0.pid
+mon -d "node $app/image" -p $pids/image-1.pid
+mon -d "node $app/image-broker" -p $pids/image-broker.pid
+```
@@ -0,0 +1,9 @@
+
+echo one
+sleep 2
+echo two
+sleep 2
+echo three
+sleep 2
+echo exiting
+exit 1
Oops, something went wrong.

0 comments on commit e1c23b4

Please sign in to comment.