Welcome to little lamb

Code » anopa » commit 8e86b09

Add shutdown

author Olivier Brunel
2015-02-27 17:50:10 UTC
committer Olivier Brunel
2015-04-04 12:47:35 UTC
parent c2f35a861cb84cceb3cb0fc0b451c8a2d49307ec

Add shutdown

doc/aa-shutdown.pod +41 -0
package/modes +1 -0
package/targets.mak +4 -0
src/scripts/aa-shutdown +50 -0

diff --git a/doc/aa-shutdown.pod b/doc/aa-shutdown.pod
new file mode 100644
index 0000000..6c75580
--- /dev/null
+++ b/doc/aa-shutdown.pod
@@ -0,0 +1,41 @@
+=head1 NAME
+
+aa-shutdown - Helper to trigger a reboot/power off/halt of the machine
+
+=head1 SYNOPSIS
+
+B<aa-shutdown> [B<-r> | B<-p> | B<-H>]
+
+=head1 OPTIONS
+
+=over
+
+=item B<-H, --halt>
+
+Halts the machine.
+
+=item B<-h, --help>
+
+Show help screen and exit.
+
+=item B<-p, --poweroff>
+
+Powers off the machine.
+
+=item B<-r, --reboot>
+
+Reboots the machine.
+
+=item B<-V, --version>
+
+Show version information and exit.
+
+=back
+
+=head1 DESCRIPTION
+
+B<aa-shutdown>(1) is a simple helper that will send the appropriate commands to
+B<s6-svscan> (using B<s6-svscanctl>).
+
+It obviously expects it to be running (as PID 1) using I</run/services/.scandir>
+as its scandir.
diff --git a/package/modes b/package/modes
index 5a9ad78..7dead11 100644
--- a/package/modes
+++ b/package/modes
@@ -7,6 +7,7 @@ aa-mount                0755
 aa-mvlog                0755
 aa-pivot                0755
 aa-reboot               0755
+aa-shutdown             0755
 aa-start                0755
 aa-stop                 0755
 aa-sync                 0755
diff --git a/package/targets.mak b/package/targets.mak
index 6b40015..4d54b1b 100644
--- a/package/targets.mak
+++ b/package/targets.mak
@@ -15,6 +15,9 @@ aa-terminate \
 aa-test \
 aa-umount
 
+BIN_SCRIPTS_TARGET := \
+aa-shutdown
+
 DOC_TARGETS := \
 anopa.1 \
 aa-chroot.1 \
@@ -26,6 +29,7 @@ aa-mount.1 \
 aa-mvlog.1 \
 aa-pivot.1 \
 aa-reboot.1 \
+aa-shutdown.1 \
 aa-start.1 \
 aa-stop.1 \
 aa-sync.1 \
diff --git a/src/scripts/aa-shutdown b/src/scripts/aa-shutdown
new file mode 100644
index 0000000..7e1960d
--- /dev/null
+++ b/src/scripts/aa-shutdown
@@ -0,0 +1,50 @@
+#!/bin/sh
+
+dieusage() {
+    cat << EOF
+Usage: aa-shutdown [OPTION]
+ -r, --reboot                  Reboot the machine
+ -H, --halt                    Halt the machine
+ -p, --poweroff                Power off the machine
+ -h, --help                    Show this help screen and exit
+ -V, --version                 Show version information and exit
+EOF
+    exit $1
+}
+
+dieversion() {
+    cat << EOF
+aa-shutdown v@VERSION@
+Copyright (C) 2015 Olivier Brunel - http://jjacky.com/anopa
+License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
+This is free software: you are free to change and redistribute it.
+There is NO WARRANTY, to the extent permitted by law.
+EOF
+    exit 0
+}
+
+if [ $# -ne 1 ]; then
+    dieusage 1
+fi
+
+case $1 in
+    -H|--halt)
+        cmd=s
+        ;;
+    -h|--help)
+        dieusage 0
+        ;;
+    -p|--poweroff)
+        cmd=p
+        ;;
+    -r|--reboot)
+        cmd=r
+        ;;
+    -V|--version)
+        dieversion
+        ;;
+    *)
+        dieusage 1
+esac
+
+exec s6-svscanctl -${cmd}b /run/services/.scandir