diff --git a/listen-for-shutdown.service b/listen-for-shutdown.service new file mode 100755 index 0000000..9a986ce --- /dev/null +++ b/listen-for-shutdown.service @@ -0,0 +1,11 @@ +[Unit] +Description=Listen for shutdown service at GPIO3 +After=syslog.target network.target + +[Service] +Type=simple +ExecStart=/usr/bin/python3 /usr/local/bin/listen-for-shutdown.py +PIDFile=/run/listen-for-shutdown.pid + +[Install] +WantedBy=multi-user.target diff --git a/script/install.systemd b/script/install.systemd new file mode 100755 index 0000000..3e0a758 --- /dev/null +++ b/script/install.systemd @@ -0,0 +1,21 @@ +#! /bin/sh + +set -e + +cd "$(dirname "$0")/.." + +echo "=> Installing shutdown listener...\n" +sudo cp listen-for-shutdown.py /usr/local/bin/ +sudo chmod +x /usr/local/bin/listen-for-shutdown.py + +echo "=> Installing shutdown listener systemd service...\n" +sudo cp listen-for-shutdown.service /etc/systemd/system/ +sudo chmod +x /etc/systemd/system/listen-for-shutdown.service + +echo "=> Starting shutdown listener...\n" +sudo systemctl daemon-reload +sudo systemctl enable listen-for-shutdown.service +sudo systemctl start listen-for-shutdown.service +sudo systemctl status listen-for-shutdown.service + +echo "Shutdown listener installed.\n" diff --git a/script/uninstall.systemd b/script/uninstall.systemd new file mode 100755 index 0000000..5a86842 --- /dev/null +++ b/script/uninstall.systemd @@ -0,0 +1,18 @@ +#! /bin/sh + +set -e + +cd "$(dirname "$0")/.." + +echo "=> Stopping shutdown listener...\n" +sudo systemctl stop listen-for-shutdown.service + +echo "=> Removing shutdown listener...\n" +sudo systemctl disable listen-for-shutdown.service +sudo systemctl status listen-for-shutdown.service +sudo rm -f /etc/systemd/system/listen-for-shutdown.service +sudo rm -f /usr/local/bin/listen-for-shutdown.py + +echo "=> Reloading systemd services...\n" +sudo systemctl daemon-reload +echo "Shutdown listener uninstalled.\n"