Permalink
Browse files

add passing of PID to the error scripts

  • Loading branch information...
flexd authored and tj committed Dec 17, 2012
1 parent e1b59bf commit 5ad57a465427179bc6012c53cd8475848210ad1f
Showing with 14 additions and 9 deletions.
  1. +2 −1 example/on_error.sh
  2. +12 −8 src/mon.c
View
@@ -1,4 +1,5 @@
#!/usr/bin/env bash
# faux email / alert
-echo "it broke!" > email
+pid=$1
+echo "process $pid broke!" > email
View
@@ -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);
}
@@ -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);
}
@@ -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));
@@ -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);
}

0 comments on commit 5ad57a4

Please sign in to comment.