Browse Source

Enable notifications for sick/dead with --cmd-sick and --cmd-dead options that execute commands when the event occurs

Luke Dashjr 12 years ago
parent
commit
6bd10d905a
4 changed files with 33 additions and 0 deletions
  1. 2 0
      README
  2. 11 0
      miner.c
  3. 17 0
      util.c
  4. 3 0
      util.h

+ 2 - 0
README

@@ -168,6 +168,8 @@ Options for both config file and command line:
 --api-port          Port number of miner API (default: 4028)
 --api-port          Port number of miner API (default: 4028)
 --balance           Change multipool strategy from failover to even share balance
 --balance           Change multipool strategy from failover to even share balance
 --benchmark         Run BFGMiner in benchmark mode - produces no shares
 --benchmark         Run BFGMiner in benchmark mode - produces no shares
+--cmd-sick <arg>    Execute a command when a device is declared sick
+--cmd-dead <arg>    Execute a command when a device is declared dead
 --coinbase-addr <arg> Set coinbase payout address for solo mining
 --coinbase-addr <arg> Set coinbase payout address for solo mining
 --coinbase-sig <arg> Set coinbase signature when possible
 --coinbase-sig <arg> Set coinbase signature when possible
 --compact           Use compact display without per device statistics
 --compact           Use compact display without per device statistics

+ 11 - 0
miner.c

@@ -337,6 +337,8 @@ static int include_count;
 #define JSON_MAX_DEPTH 10
 #define JSON_MAX_DEPTH 10
 #define JSON_MAX_DEPTH_ERR "Too many levels of JSON includes (limit 10) or a loop"
 #define JSON_MAX_DEPTH_ERR "Too many levels of JSON includes (limit 10) or a loop"
 
 
+char *cmd_sick, *cmd_dead;
+
 #if defined(unix) || defined(__APPLE__)
 #if defined(unix) || defined(__APPLE__)
 	static char *opt_stderr_cmd = NULL;
 	static char *opt_stderr_cmd = NULL;
 	static int forkpid;
 	static int forkpid;
@@ -1285,6 +1287,12 @@ static struct opt_table opt_config_table[] = {
 		     set_int_0_to_9999, opt_show_intval, &opt_bench_algo,
 		     set_int_0_to_9999, opt_show_intval, &opt_bench_algo,
 		     opt_hidden),
 		     opt_hidden),
 #endif
 #endif
+	OPT_WITH_ARG("--cmd-sick",
+	             opt_set_charp, NULL, &cmd_sick,
+	             "Execute a command when a device is declared sick"),
+	OPT_WITH_ARG("--cmd-dead",
+	             opt_set_charp, NULL, &cmd_dead,
+	             "Execute a command when a device is declared dead"),
 #if BLKMAKER_VERSION > 1
 #if BLKMAKER_VERSION > 1
 	OPT_WITH_ARG("--coinbase-addr",
 	OPT_WITH_ARG("--coinbase-addr",
 		     set_b58addr, NULL, &opt_coinbase_script,
 		     set_b58addr, NULL, &opt_coinbase_script,
@@ -8258,6 +8266,8 @@ static void *watchdog_thread(void __maybe_unused *userdata)
 				cgtime(&thr->sick);
 				cgtime(&thr->sick);
 
 
 				dev_error(cgpu, REASON_DEV_SICK_IDLE_60);
 				dev_error(cgpu, REASON_DEV_SICK_IDLE_60);
+				run_cmd(cmd_sick);
+				
 #ifdef HAVE_ADL
 #ifdef HAVE_ADL
 				if (adl_active && cgpu->has_adl && gpu_activity(gpu) > 50) {
 				if (adl_active && cgpu->has_adl && gpu_activity(gpu) > 50) {
 					applog(LOG_ERR, "GPU still showing activity suggesting a hard hang.");
 					applog(LOG_ERR, "GPU still showing activity suggesting a hard hang.");
@@ -8274,6 +8284,7 @@ static void *watchdog_thread(void __maybe_unused *userdata)
 				cgtime(&thr->sick);
 				cgtime(&thr->sick);
 
 
 				dev_error(cgpu, REASON_DEV_DEAD_IDLE_600);
 				dev_error(cgpu, REASON_DEV_DEAD_IDLE_600);
+				run_cmd(cmd_dead);
 			} else if (now.tv_sec - thr->sick.tv_sec > 60 &&
 			} else if (now.tv_sec - thr->sick.tv_sec > 60 &&
 				   (cgpu->status == LIFE_SICK || cgpu->status == LIFE_DEAD)) {
 				   (cgpu->status == LIFE_SICK || cgpu->status == LIFE_DEAD)) {
 				/* Attempt to restart a GPU that's sick or dead once every minute */
 				/* Attempt to restart a GPU that's sick or dead once every minute */

+ 17 - 0
util.c

@@ -2448,3 +2448,20 @@ void _bytes_alloc_failure(size_t sz)
 {
 {
 	quit(1, "bytes_resize failed to allocate %lu bytes", (unsigned long)sz);
 	quit(1, "bytes_resize failed to allocate %lu bytes", (unsigned long)sz);
 }
 }
+
+
+void *cmd_thread(void *cmdp)
+{
+	const char *cmd = cmdp;
+	applog(LOG_DEBUG, "Executing command: %s", cmd);
+	system(cmd);
+	return NULL;
+}
+
+void run_cmd(const char *cmd)
+{
+	if (!cmd)
+		return;
+	pthread_t pth;
+	pthread_create(&pth, NULL, cmd_thread, (void*)cmd);
+}

+ 3 - 0
util.h

@@ -279,4 +279,7 @@ void maybe_strdup_if_null(const char **p, const char *s)
 }
 }
 
 
 
 
+extern void run_cmd(const char *cmd);
+
+
 #endif /* __UTIL_H__ */
 #endif /* __UTIL_H__ */