hello,
I’ve created a service and scripts that sends out email with Postfix at shutdown.
Well so far what I’ve noticed is that systemd is not behaving as it should.
Tested on Amazon Linux 2 and works.
It also works on Debian 12.5 and I assume systemd is not “messed” up on these. (Just Yet)
On Amazon Linux 3 email stuck only sent out when system booted up. (stuck in queue)
Other Distros, Oracle Linux 9.4, Oracle Liunux 9.3, Ubuntu 24.04 same it is not working on these.
So far I went through on many possible options that I found on the net and also tried “100” options with AI too. pre, post, all dependencies network-target, network-online etc, none helped.
It is either gets fully stuck and email part is not even generated or just sent out after the reboot.
So I really want to know why it is working on those 2 distros and why not on the others?
Also I tried the override option:
/etc/systemd/system/shutdown.target.d# cat override.conf
[Unit]
Requires=shutdown-e.service
Requires=delay-shutdown.service
After=shutdown-e.service
After=delay-shutdown.service
This only kills reboot part, but not “shutdown -r now”.
I’ve noticed this when I purposelly changed the service name and issued reboot and reboot said this:
Broadcast message from root@testbed on pts/1 (Wed 2024-06-26 16:01:38 UTC):
The system will reboot now!
Call to Reboot failed: Unit shutdown-e–.service not found.
But I’ve added dependency with new delay service and again on the vm console the reboot starts instanlty and overriding the delay process and that delay process is in the override part of shutdown. (So is this an override?)
Also I’ve added conflict to depend on the reboot and that just killed the whole reboot:
The system will reboot now!
Call to Reboot failed: Transaction contains conflicting jobs ‘stop’ and ‘start’ for reboot.target. Probably contradicting requirement dependencies configured.
root@testbed:/etc/systemd/system#
I could create aliases to each command but that is a bit of a joke.
Let’s say I need to shutdown my UPS or nuclear power plant up front, well currently systemd does not care about it, shutdown is a shutdown.
Any idea would be appreciated please as I run out and dried out now.
Scripts below:
#/etc/systemd/system/shutdown-e.service
[Unit]
Description=Send email on shutdown
After=network.target
After=multi-user.target[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/bin/true
ExecStop=/usr/local/bin/down.sh[Install]
WantedBy=multi-user.target
WantedBy=reboot.target
cat /usr/local/bin/down.sh
#!/bin/bash
/usr/local/bin/sendmail.sh shutdown
echo “cleaning…”
for i in {1..5}; do
sleep 1s
echo “waiting…”
doneecho “done”
cat /usr/local/bin/sendmail.sh
#! /bin/sh
EMAIL=”[email protected]”
SUBJECT=”[$HOSTNAME] – System $1″if [ “$1″ = startup ]
then
ACTION=”started successfully at”
else
ACTION=”is shutting down. The Shutdown process started at”
fiBODY=”This is an automated message to notify you that %s %s.nDate and Time: %sn”
printf “$BODY” “$HOSTNAME” “$ACTION” “$(date)” | mail -s “${SUBJECT}” “${EMAIL}”
Quertino is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.