Browse Source

Add signal watcher system with power cycle triggers

power-cycle
Luke Childs 5 years ago
parent
commit
4b64c03528
  1. 19
      signal-watcher
  2. 0
      watcher/signals/.gitkeep
  3. 4
      watcher/triggers/reboot
  4. 4
      watcher/triggers/shutdown

19
signal-watcher

@ -0,0 +1,19 @@
#!/usr/bin/env bash
root_dir="$(readlink -f $1)"
signal_dir="$root_dir/signals"
trigger_dir="$root_dir/triggers"
fswatch -0 --event=PlatformSpecific $signal_dir | while read -d "" event; do
signal="${event#"$signal_dir"}"
signal="${signal#"/"}"
trigger="$trigger_dir/$signal"
echo "Got signal: $signal"
if test -x "$trigger"; then
echo "Executing trigger"
"$trigger"
else
echo "No trigger found"
fi
done

0
watcher/signals/.gitkeep

4
watcher/triggers/reboot

@ -0,0 +1,4 @@
#!/usr/bin/env bash
set -euo pipefail
shutdown -r now

4
watcher/triggers/shutdown

@ -0,0 +1,4 @@
#!/usr/bin/env bash
set -euo pipefail
shutdown -h now
Loading…
Cancel
Save