-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit e1c23b4
Showing
6 changed files
with
444 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
*.o | ||
mon.log | ||
mon |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
``` |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
|
||
echo one | ||
sleep 2 | ||
echo two | ||
sleep 2 | ||
echo three | ||
sleep 2 | ||
echo exiting | ||
exit 1 |
Oops, something went wrong.