Skip to content

Commit 81d9c9e

Browse files
ystarnaudtroky
authored andcommitted
Events framework
Added the ability to have users run commands, reboot the system or quit sgminer based on system events. These events can be defined and placed throughout the sgminer source. So far the events are: "gpu_sick", "gpu_dead" and "idle". I will document further shortly. Config example available here: http://pastebin.com/2rRv3EzH
1 parent 611b370 commit 81d9c9e

8 files changed

+487
-1
lines changed

Makefile.am

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ sgminer_SOURCES += adl.c adl.h adl_functions.h
4343
sgminer_SOURCES += pool.c pool.h
4444
sgminer_SOURCES += algorithm.c algorithm.h
4545
sgminer_SOURCES += config_parser.c config_parser.h
46+
sgminer_SOURCES += events.c events.h
4647
sgminer_SOURCES += ocl/patch_kernel.c ocl/patch_kernel.h
4748
sgminer_SOURCES += ocl/build_kernel.c ocl/build_kernel.h
4849
sgminer_SOURCES += ocl/binary_kernel.c ocl/binary_kernel.h

config_parser.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ static char *parse_config_array(json_t *obj, char *parentkey, bool fileconf)
662662
json_t *val;
663663

664664
//fix parent key - remove extra "s" to match opt names (e.g. --pool-gpu-memclock not --pools-gpu-memclock)
665-
if(!strcasecmp(parentkey, "pools") || !strcasecmp(parentkey, "profiles"))
665+
if(!strcasecmp(parentkey, "pools") || !strcasecmp(parentkey, "profiles") || !strcasecmp(parentkey, "events"))
666666
parentkey[(strlen(parentkey) - 1)] = '\0';
667667

668668
json_array_foreach(obj, idx, val)

doc/configuration.md

+148
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@
88
* [Globals and the Default Profile](#globals-and-the-default-profile)
99
* [Working with Profiles and Pool Specific Settings](#working-with-profiles-and-pool-specific-settings)
1010
* [Include and Includes](#include-and-includes)
11+
* [Events](#events)
1112
* [CLI Only options](#cli-only-options)
1213
* [Config-file and CLI options](#config-file-and-cli-options)
14+
* [Event options](#event-options)
15+
* [Event Types](#event-types)
1316

1417
---
1518

@@ -233,6 +236,34 @@ There is no limit as to how includes can be used as long as they follow proper j
233236

234237
---
235238

239+
## Events
240+
241+
Users can now execute commands or perform certain tasks when pre-defined events occur while mining.
242+
243+
For example, one might want their miner to email them via a script when the miner goes idle and reboot the computer when a GPU goes dead. This gives users a little more flexibility controlling their mining uptime without necessarily resorting to external watchdog programs that, in some cases, can be troublesome.
244+
245+
Here is a configuration example of the above scenario:
246+
```
247+
...
248+
"events":[
249+
{
250+
"on":"idle",
251+
"runcmd":"/bin/mailscript \"Miner Idle\" \"Hey! My miner went idle!\""
252+
},
253+
{
254+
"on":"gpu_dead",
255+
"reboot":"yes"
256+
}
257+
],
258+
...
259+
```
260+
261+
For more details on configuration options, see [Event Options](#event-options) below.
262+
263+
[Top](#configuration-and-command-line-options)
264+
265+
---
266+
236267
## CLI Only options
237268

238269
* [config](#config) `--config` or `-c`
@@ -2446,3 +2477,120 @@ Displays extra work time debug information.
24462477
*Default:* `false`
24472478

24482479
[Top](#configuration-and-command-line-options) :: [Config-file and CLI options](#config-file-and-cli-options) :: [Miscellaneous Options](#miscellaneous-options)
2480+
2481+
---
2482+
2483+
## Event options
2484+
2485+
* [on](#on)
2486+
* [runcmd](#runcmd)
2487+
* [reboot](#reboot)
2488+
* [reboot-delay](#reboot-delay)
2489+
* [quit](#quit)
2490+
* [quit-message](#quit-message)
2491+
2492+
### on
2493+
2494+
Specify which event type to respond on. See below for a list of supported [event types](#event-types)
2495+
2496+
*Available*: Events
2497+
2498+
*Config File Syntax:* `"on":"<value>"`
2499+
2500+
*Command Line Syntax:* `--event-on <value>`
2501+
2502+
*Argument:* `string` Name of the event type
2503+
2504+
*Default:* None
2505+
2506+
[Top](#configuration-and-command-line-options) :: [Event options](#event-options)
2507+
2508+
### runcmd
2509+
2510+
Specify a command to run when the event occurs. Please remember to properly escape quotes (") with backslashes (\\) if you need to specify multi-word parameters enclosed in quotes (") for your commands: `\"`
2511+
2512+
*Available*: Events
2513+
2514+
*Config File Syntax:* `"runcmd":"<value>"`
2515+
2516+
*Command Line Syntax:* `--event-runcmd <value>`
2517+
2518+
*Argument:* `string` Command to execute on event
2519+
2520+
*Default:* None
2521+
2522+
[Top](#configuration-and-command-line-options) :: [Event options](#event-options)
2523+
2524+
### reboot
2525+
2526+
Reboot when event occurs.
2527+
2528+
*Available*: Events
2529+
2530+
*Config File Syntax:* `"reboot":"<value>"`
2531+
2532+
*Command Line Syntax:* `--event-reboot <value>`
2533+
2534+
*Argument:* `string` Yes: `"true"` `"yes"` `"1"` or No: `"false"` `"no"` `"0"`
2535+
2536+
*Default:* `false`
2537+
2538+
[Top](#configuration-and-command-line-options) :: [Event options](#event-options)
2539+
2540+
### reboot-delay
2541+
2542+
Wait a number of seconds before rebooting when event occurs. This is useful if you also want to fire off a script via `runcmd` prior to rebooting, giving it extra seconds to finish.
2543+
2544+
*Available*: Events
2545+
2546+
*Config File Syntax:* `"reboot-delay":"<value>"`
2547+
2548+
*Command Line Syntax:* `--event-reboot-delay <value>`
2549+
2550+
*Argument:* `number` Seconds to wait before reboot
2551+
2552+
*Default:* `0`
2553+
2554+
[Top](#configuration-and-command-line-options) :: [Event options](#event-options)
2555+
2556+
### quit
2557+
2558+
Exit sgminer when event occurs.
2559+
2560+
*Available*: Events
2561+
2562+
*Config File Syntax:* `"quit":"<value>"`
2563+
2564+
*Command Line Syntax:* `--event-quit <value>`
2565+
2566+
*Argument:* `string` Yes: `"true"` `"yes"` `"1"` or No: `"false"` `"no"` `"0"`
2567+
2568+
*Default:* `false`
2569+
2570+
[Top](#configuration-and-command-line-options) :: [Event options](#event-options)
2571+
2572+
### quit-message
2573+
2574+
Message to display on sgminer exit when event occurs.
2575+
2576+
*Available*: Events
2577+
2578+
*Config File Syntax:* `"quit-message":"<value>"`
2579+
2580+
*Command Line Syntax:* `--event-quit-message "<value>"`
2581+
2582+
*Argument:* `string` Message
2583+
2584+
*Default:* `event_type`
2585+
2586+
[Top](#configuration-and-command-line-options) :: [Event options](#event-options)
2587+
2588+
---
2589+
2590+
## Event Types
2591+
2592+
* `idle` Occurs when a GPU goes idle for not performing any work or when no work has been received in 10 minutes.
2593+
* `gpu_sick` Occurs when a GPU fails to respond for 2 minutes
2594+
* `gpu_dead` Occurs when a GPU fails to respond for 10 minutes
2595+
2596+
[Top](#configuration-and-command-line-options)

0 commit comments

Comments
 (0)