Skip to content

Commit

Permalink
add passing of PID to the error scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
flexd authored and tj committed Dec 17, 2012
1 parent e1b59bf commit 5ad57a4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
3 changes: 2 additions & 1 deletion example/on_error.sh
@@ -1,4 +1,5 @@
#!/usr/bin/env bash

# faux email / alert
echo "it broke!" > email
pid=$1
echo "process $pid broke!" > email
20 changes: 12 additions & 8 deletions src/mon.c
Expand Up @@ -218,9 +218,11 @@ daemonize() {
*/

void
exec_restart_command(monitor_t *monitor) {
log("on restart `%s`", monitor->on_restart);
int status = system(monitor->on_restart);
exec_restart_command(monitor_t *monitor, pid_t pid) {
char buf[256] = {0};
snprintf(buf, 256, "%s %d", monitor->on_restart, pid);
log("on restart `%s`", buf);
int status = system(buf);
if (status) log("exit(%d)", status);
}

Expand All @@ -229,9 +231,11 @@ exec_restart_command(monitor_t *monitor) {
*/

void
exec_error_command(monitor_t *monitor) {
log("on error `%s`", monitor->on_error);
int status = system(monitor->on_error);
exec_error_command(monitor_t *monitor, pid_t pid) {
char buf[256] = {0};
snprintf(buf, 256, "%s %d", monitor->on_error, pid);
log("on error `%s`", buf);
int status = system(buf);
if (status) log("exit(%d)", status);
}

Expand Down Expand Up @@ -320,7 +324,7 @@ exec: {

// restart
error: {
if (monitor->on_restart) exec_restart_command(monitor);
if (monitor->on_restart) exec_restart_command(monitor, pid);
int64_t ms = ms_since_last_restart(monitor);
monitor->last_restart_at = timestamp();
log("last restart %s ago", milliseconds_to_long_string(ms));
Expand All @@ -329,7 +333,7 @@ exec: {
if (attempts_exceeded(monitor, ms)) {
char *time = milliseconds_to_long_string(60000 - monitor->clock);
log("%d restarts within %s, bailing", monitor->max_attempts, time);
exec_error_command(monitor);
exec_error_command(monitor, pid);
log("bye :)");
exit(2);
}
Expand Down

0 comments on commit 5ad57a4

Please sign in to comment.