Skip to content

Commit

Permalink
rename --on-error to --on-restart to disambiguate
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Nov 10, 2012
1 parent 22b39f7 commit 1048ca1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Options:
-m, --mon-pidfile <path> write mon(1) pid to <path>
-P, --prefix <str> add a log prefix
-d, --daemonize daemonize the program
-e, --on-error <cmd> execute <cmd> on errors
-R, --on-restart <cmd> execute <cmd> on restarts
```

Expand Down
22 changes: 11 additions & 11 deletions src/mon.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ typedef struct {
const char *pidfile;
const char *mon_pidfile;
const char *logfile;
const char *on_error;
const char *on_restart;
int64_t last_restart_at;
int64_t clock;
int daemon;
Expand Down Expand Up @@ -215,13 +215,13 @@ daemonize() {
}

/*
* Invoke the --on-error command.
* Invoke the --on-restart command.
*/

void
exec_error_command(monitor_t *monitor) {
log("on error \"%s\"", monitor->on_error);
int status = system(monitor->on_error);
exec_restart_command(monitor_t *monitor) {
log("on restart `%s`", monitor->on_restart);
int status = system(monitor->on_restart);
if (status) {
log("exit(%d)", status);
log("shutting down");
Expand Down Expand Up @@ -314,7 +314,7 @@ exec: {

// restart
error: {
if (monitor->on_error) exec_error_command(monitor);
if (monitor->on_restart) exec_restart_command(monitor);
int64_t ms = ms_since_last_restart(monitor);
monitor->last_restart_at = timestamp();
log("last restart %s ago", milliseconds_to_long_string(ms));
Expand Down Expand Up @@ -404,13 +404,13 @@ on_prefix(command_t *self) {
}

/*
* --on-error <cmd>
* --on-restart <cmd>
*/

static void
on_error(command_t *self) {
on_restart(command_t *self) {
monitor_t *monitor = (monitor_t *) self->data;
monitor->on_error = self->arg;
monitor->on_restart = self->arg;
}

/*
Expand All @@ -432,7 +432,7 @@ main(int argc, char **argv){
monitor_t monitor;
monitor.pidfile = NULL;
monitor.mon_pidfile = NULL;
monitor.on_error = NULL;
monitor.on_restart = NULL;
monitor.logfile = "mon.log";
monitor.daemon = 0;
monitor.sleepsec = 1;
Expand All @@ -452,7 +452,7 @@ main(int argc, char **argv){
command_option(&program, "-m", "--mon-pidfile <path>", "write mon(1) pid to <path>", on_mon_pidfile);
command_option(&program, "-P", "--prefix <str>", "add a log prefix", on_prefix);
command_option(&program, "-d", "--daemonize", "daemonize the program", on_daemonize);
command_option(&program, "-e", "--on-error <cmd>", "execute <cmd> on errors", on_error);
command_option(&program, "-R", "--on-restart <cmd>", "execute <cmd> on restarts", on_restart);
command_option(&program, "-a", "--attempts <n>", "retry attempts within 60 seconds [10]", on_attempts);
command_parse(&program, argc, argv);

Expand Down

0 comments on commit 1048ca1

Please sign in to comment.