Skip to content

Commit ec7eb26

Browse files
committed
shell commands can now be handled optionally as pimatic expressions. child processes are now kill after a given timeout as part of the plugin config (15 secs by default).
pimatic/pimatic#980
1 parent cb06bf0 commit ec7eb26

4 files changed

+331
-141
lines changed

README.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ You can load the plugin by editing your `config.json` to include:
1313
"plugin": "shell-execute"
1414
}
1515

16-
Commands are executed parallel by default. With the optional boolean attribute `sequential`set to `true`shell commands are executed sequentially.
16+
Commands are executed parallel by default. With the optional boolean attribute
17+
`sequential`set to `true` all shell commands are executed sequentially. This option
18+
should be used mindfully it can dramatically slow down the execution of command and
19+
yield other side effects like execution timeouts.
1720

1821
{
1922
"plugin": "shell-execute",
@@ -146,3 +149,18 @@ automatically reset to "absent" after some time. For this you can set to `autoRe
146149
}
147150

148151
For device configuration options see the [device-config-schema](device-config-schema.coffee) file.
152+
153+
Troubleshooting
154+
-------
155+
156+
### Execution of Long Running Commands
157+
158+
Long running commands should be avoided as they may block pimatic or yield errors when the `timeout` value
159+
in the plugin configuration is set to kill pending processes. If you want to execute a long running command
160+
though, write a wrapper script which send the command to the background. You can also use a wrapper
161+
command which detaches the process from the controlling terminal and send it to the background.
162+
* Linux: `nohup <command> &` or `nohup bash -c "<command1>; <command2>" &`
163+
if you need to execute multiple commands
164+
* Windows: `start -b <command>`.
165+
166+

device-config-schema.coffee

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ module.exports = {
3232
"
3333
type: "boolean"
3434
default: false
35+
evaluateCommandStrings:
36+
description: "
37+
treat commands strings as pimatic expressions
38+
"
39+
type: "boolean"
40+
default: false
3541
}
3642
ShellButtons: {
3743
title: "ShellButtons config options"
@@ -62,6 +68,12 @@ module.exports = {
6268
description: "Ask the user to confirm the button press"
6369
type: "boolean"
6470
default: false
71+
evaluateCommandStrings:
72+
description: "
73+
treat commands strings as pimatic expressions
74+
"
75+
type: "boolean"
76+
default: false
6577
}
6678
ShellSensor: {
6779
title: "ShellSensor config options"
@@ -98,6 +110,12 @@ module.exports = {
98110
description: "the time in ms, the command gets executed to get a new sensor value"
99111
type: "integer"
100112
default: 5000
113+
evaluateCommandStrings:
114+
description: "
115+
treat commands strings as pimatic expressions
116+
"
117+
type: "boolean"
118+
default: false
101119
}
102120
ShellPresenceSensor: {
103121
title: "ShellPresenceSensor config options"
@@ -132,6 +150,12 @@ module.exports = {
132150
"
133151
type: "integer"
134152
default: 10000
153+
evaluateCommandStrings:
154+
description: "
155+
treat commands strings as pimatic expressions
156+
"
157+
type: "boolean"
158+
default: false
135159
}
136160
ShellShutterController: {
137161
title: "ShellShutterController config options"
@@ -161,5 +185,11 @@ module.exports = {
161185
"
162186
type: "integer"
163187
default: 0
188+
evaluateCommandStrings:
189+
description: "
190+
treat commands strings as pimatic expressions
191+
"
192+
type: "boolean"
193+
default: false
164194
}
165195
}

shell-execute-config-schema.coffee

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@ module.exports = {
22
title: "shell execute config options"
33
type: "object"
44
properties:
5+
debug:
6+
description: "Debug mode. Writes debug messages to the pimatic log, if set to true."
7+
type: "boolean"
8+
default: false
59
sequential:
610
description: "
7-
Run all shell commands sequential (not in parallel). Enable
8-
this if you have commands that should not be execute in parallel
11+
Run all shell commands sequentially (not in parallel). Enable
12+
this if you have commands that should not be executed in parallel
913
"
1014
type: "boolean"
1115
default: false
@@ -20,4 +24,8 @@ module.exports = {
2024
description: "Current working directory of the child process"
2125
type: "string"
2226
required: false
27+
timeout:
28+
description: "child process will be killed if it runs longer than timeout milliseconds"
29+
type: "integer"
30+
default: 15000
2331
}

0 commit comments

Comments
 (0)