I'm running Raspbian Stretch on a Raspberry Pi (a derivative of Debian Stretch), and nobody on the RPi forums have a solution, so I thought I might ask here...
My service file is located in /etc/systemd/system/example.service and contains:
Code: Select all
[Unit]
Description=This service calls shutdownScript.sh upon shutdown or reboot.
Before=shutdown.target reboot.target halt.target
[Service]
Type=oneshot
RemainAfterExit=true
ExecStop=/home/pi/shutdownScript.sh
[Install]
WantedBy=multi-user.target
Code: Select all
#!/bin/bash
curl 'https://api.twilio.com/2010-04-01/Accounts/redacted/Messages.json' -X POST \
--data-urlencode 'To=+redacted' \
--data-urlencode 'From=+redacted' \
--data-urlencode "Body=Shutting down..." \
-u redacted
The end goal is to have the system send me an SMS (via the above HTTP POST request) when it shuts down or reboots.
I've gone through several dozen Google search results and have also asked on Stack Overflow. I can't seem to get this working.
What does happen is as follows:
Code: Select all
systemctl daemon-reload
Code: Select all
sudo systemctl start example --now
Code: Select all
sudo systemctl stop example
If I do:
Code: Select all
systemctl enable example --now
Code: Select all
systemctl list-unit-files --type=service
If I then reboot the system (which should trigger the script), a normal shutdown/reboot occurs, and the SMS is never sent.
A friend suggested that the system may not be waiting for the script to run before shutting down, and pointed me towards this discussion, which suggested I do the following:
Code: Select all
sudo nano /etc/systemd/journald.conf
Code: Select all
systemctl restart systemd-journald
Code: Select all
journalctl -b-1 -u /etc/systemd/system/example.service
Code: Select all
--No entries --
However, running sudo journalctl yielded the following:
Code: Select all
Dec 13 02:27:33 v2iOTS99 pppd[1045]: Child process /etc/ppp/ip-down (pid 2193) terminated with signal 15
Dec 13 02:27:33 v2iOTS99 systemd[1]: Stopping This service calls shutdownScript.sh upon shutdown or reboot....
Dec 13 02:27:33 v2iOTS99 pppd[1045]: Exit.
Dec 13 02:27:33 v2iOTS99 systemd[1]: Stopping Regular background program processing daemon...
Dec 13 02:27:33 v2iOTS99 sudo[1041]: pam_unix(sudo:session): session closed for user root
Dec 13 02:27:33 v2iOTS99 systemd[1]: Stopping OpenBSD Secure Shell server...
Dec 13 02:27:33 v2iOTS99 systemd[1]: Stopping LSB: Switch to ondemand cpu governor (unless shift key is pressed)...
Dec 13 02:27:33 v2iOTS99 systemd[1]: Stopping LSB: A service to forward local ports to the internet...
Dec 13 02:27:33 v2iOTS99 systemd[1]: Stopping LSB: Autogenerate and use a swap file...
Dec 13 02:27:33 v2iOTS99 systemd[1]: Stopping LSB: Remote-IoT...
Dec 13 02:27:33 v2iOTS99 systemd[1]: Stopping Deferred execution scheduler...
Dec 13 02:27:33 v2iOTS99 systemd[1]: Stopped Daily Cleanup of Temporary Directories.
Dec 13 02:27:33 v2iOTS99 systemd[1]: Stopping LSB: AWS CodeDeploy Host Agent...
Dec 13 02:27:33 v2iOTS99 systemd[1]: Stopping LSB: LiFePO4wered/Pi daemon...
Dec 13 02:27:33 v2iOTS99 systemd[1]: Stopping D-Bus System Message Bus...
Dec 13 02:27:33 v2iOTS99 systemd[1]: Stopping Authorization Manager...
Dec 13 02:27:33 v2iOTS99 systemd[1]: Stopping Avahi mDNS/DNS-SD Stack...
Dec 13 02:27:33 v2iOTS99 systemd[1]: Stopping Session c2 of user pi.
Dec 13 02:27:33 v2iOTS99 sshd[1371]: pam_systemd(sshd:session): Failed to release session: Connection reset by peer
Dec 13 02:27:33 v2iOTS99 systemd[1]: Closed Load/Save RF Kill Switch Status /dev/rfkill Watch.
Dec 13 02:27:33 v2iOTS99 systemd[1]: Stopped OpenVPN service.
Dec 13 02:27:33 v2iOTS99 systemd[1]: Stopping amazon-ssm-agent...
Dec 13 02:27:33 v2iOTS99 systemd[1]: Stopping triggerhappy global hotkey daemon...
Dec 13 02:27:33 v2iOTS99 systemd[1]: Stopped target Login Prompts.
Dec 13 02:27:33 v2iOTS99 systemd[1]: Stopping Serial Getty on ttyAMA0...
Dec 13 02:27:33 v2iOTS99 systemd[1]: Stopping Getty on tty1...
Dec 13 02:27:33 v2iOTS99 systemd[1]: Stopping System Logging Service...
Dec 13 02:27:33 v2iOTS99 systemd[1]: Stopped Check for v3d driver.
Dec 13 02:27:33 v2iOTS99 systemd[1]: Stopping PPPOn...
Dec 13 02:27:33 v2iOTS99 systemd[1]: Stopped D-Bus System Message Bus.
Dec 13 02:27:33 v2iOTS99 systemd[1]: Stopped System Logging Service.
Dec 13 02:27:33 v2iOTS99 systemd[1]: Stopped Regular background program processing daemon.
Dec 13 02:27:33 v2iOTS99 systemd[1]: Stopped Deferred execution scheduler.
Dec 13 02:27:33 v2iOTS99 systemd[1]: Stopped Avahi mDNS/DNS-SD Stack.
Dec 13 02:27:33 v2iOTS99 systemd[1]: Stopped triggerhappy global hotkey daemon.
Dec 13 02:27:33 v2iOTS99 systemd[1]: Stopped amazon-ssm-agent.
Dec 13 02:27:33 v2iOTS99 systemd[1]: Stopped Serial Getty on ttyAMA0.
Dec 13 02:27:33 v2iOTS99 systemd[1]: Stopped Getty on tty1.
Dec 13 02:27:33 v2iOTS99 systemd[1]: Stopped OpenBSD Secure Shell server.
Dec 13 02:27:33 v2iOTS99 systemd[1]: Stopped User Manager for UID 1000.
Dec 13 02:27:33 v2iOTS99 systemd[1]: Stopped Authorization Manager.
Dec 13 02:27:33 v2iOTS99 systemd[1]: Stopped Save/Restore Sound Card State.
Dec 13 02:27:33 v2iOTS99 systemd[1]: Unmounted /run/user/1000.
Dec 13 02:27:33 v2iOTS99 systemd[1]: Unmounted RPC Pipe File System.
Dec 13 02:27:33 v2iOTS99 systemd[1]: openport.service: Control process exited, code=exited status=1
Dec 13 02:27:33 v2iOTS99 systemd[1]: Stopped LSB: A service to forward local ports to the internet.
Dec 13 02:27:33 v2iOTS99 systemd[1]: openport.service: Unit entered failed state.
Dec 13 02:27:33 v2iOTS99 systemd[1]: openport.service: Failed with result 'exit-code'.
Dec 13 02:27:33 v2iOTS99 systemd[1]: Failed to propagate agent release message: Transport endpoint is not connected
Dec 13 02:27:33 v2iOTS99 systemd[1]: Failed to propagate agent release message: Transport endpoint is not connected
Dec 13 02:27:33 v2iOTS99 systemd[1]: Failed to propagate agent release message: Transport endpoint is not connected
Dec 13 02:27:33 v2iOTS99 systemd[1]: Failed to propagate agent release message: Transport endpoint is not connected
Dec 13 02:27:33 v2iOTS99 systemd[1]: Failed to propagate agent release message: Transport endpoint is not connected
Dec 13 02:27:33 v2iOTS99 systemd[1]: Failed to propagate agent release message: Transport endpoint is not connected
Dec 13 02:27:33 v2iOTS99 systemd[1]: Failed to propagate agent release message: Transport endpoint is not connected
Dec 13 02:27:33 v2iOTS99 systemd[1]: Failed to propagate agent release message: Transport endpoint is not connected
Dec 13 02:27:33 v2iOTS99 systemd[1]: Failed to propagate agent release message: Transport endpoint is not connected
Dec 13 02:27:33 v2iOTS99 systemd[1]: Failed to propagate agent release message: Transport endpoint is not connected
Dec 13 02:27:33 v2iOTS99 systemd[1]: Failed to propagate agent release message: Transport endpoint is not connected
Dec 13 02:27:33 v2iOTS99 systemd[1]: Failed to propagate agent release message: Transport endpoint is not connected
Dec 13 02:27:33 v2iOTS99 shutdownScript.sh[2160]: % Total % Received % Xferd Average Speed Time Time Time Current
Dec 13 02:27:33 v2iOTS99 shutdownScript.sh[2160]: Dload Upload Total Spent Left Speed
Dec 13 02:27:33 v2iOTS99 systemd[1]: Failed to propagate agent release message: Transport endpoint is not connected
Dec 13 02:27:33 v2iOTS99 systemd[1]: Failed to propagate agent release message: Transport endpoint is not connected
Dec 13 02:27:33 v2iOTS99 systemd[1]: Failed to propagate agent release message: Transport endpoint is not connected
Dec 13 02:27:33 v2iOTS99 systemd[1]: Failed to propagate agent release message: Transport endpoint is not connected
Dec 13 02:27:33 v2iOTS99 systemd[1]: Failed to propagate agent release message: Transport endpoint is not connected
Dec 13 02:27:33 v2iOTS99 systemd[1]: Failed to propagate agent release message: Transport endpoint is not connected
Dec 13 02:27:33 v2iOTS99 systemd[1]: Failed to propagate agent release message: Transport endpoint is not connected
Dec 13 02:27:33 v2iOTS99 systemd[1]: Failed to propagate agent release message: Transport endpoint is not connected
Dec 13 02:27:33 v2iOTS99 systemd[1]: Failed to propagate agent release message: Transport endpoint is not connected
Dec 13 02:27:33 v2iOTS99 shutdownScript.sh[2160]: [127B blob data]
Dec 13 02:27:33 v2iOTS99 systemd[1]: Stopped PPPOn.
Dec 13 02:27:33 v2iOTS99 systemd-logind[387]: Failed to abandon session scope, ignoring: Transport endpoint is not connected
Dec 13 02:27:33 v2iOTS99 systemd[1]: Stopped Session c2 of user pi.
Dec 13 02:27:33 v2iOTS99 remote-iot[2168]: remote-iot stopped
Dec 13 02:27:33 v2iOTS99 systemd[1]: example.service: Control process exited, code=exited status=6
Dec 13 02:27:33 v2iOTS99 systemd[1]: Stopped This service calls shutdownScript.sh upon shutdown or reboot..
Dec 13 02:27:33 v2iOTS99 systemd[1]: example.service: Unit entered failed state.
Dec 13 02:27:33 v2iOTS99 systemd[1]: example.service: Failed with result 'exit-code'.
Dec 13 02:27:33 v2iOTS99 systemd[1]: Reached target Unmount All Filesystems.
Dec 13 02:27:33 v2iOTS99 systemd[1]: Stopped target Local File Systems (Pre).
Dec 13 02:27:33 v2iOTS99 systemd[1]: Removed slice User Slice of pi.
Dec 13 02:27:33 v2iOTS99 systemd[1]: Stopping Login Service...
Dec 13 02:27:33 v2iOTS99 systemd[1]: Starting Show Plymouth Reboot Screen...
Dec 13 02:27:33 v2iOTS99 systemd[1]: Removed slice system-getty.slice.
Dec 13 02:27:33 v2iOTS99 systemd[1]: Stopping Permit User Sessions...
Dec 13 02:27:33 v2iOTS99 systemd[1]: Stopped /etc/rc.local Compatibility.
Dec 13 02:27:33 v2iOTS99 systemd[1]: Removed slice system-serial\x2dgetty.slice.
Dec 13 02:27:33 v2iOTS99 systemd[1]: Stopped Login Service.
Code: Select all
Dec 13 02:27:33 v2iOTS99 systemd[1]: Stopping PPPOn...
Note: I use a 4G modem (a PPP connection) for internet access.
You can see from the lines containing "shutdownScript.sh", that the HTTP POST request's stdout (logged in the file) doesn't show any progress indicators.
Is my script failing because it shuts down the PPP connection before running my script?
If so, is there a solution to this problem?
Or is my issue caused by something else?
Thanks in advance for any help given.
David