Send email before shutdown, systemd nightmare

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…”
done

echo “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”
fi

BODY=”This is an automated message to notify you that %s %s.nDate and Time: %sn”

printf “$BODY” “$HOSTNAME” “$ACTION” “$(date)” | mail -s “${SUBJECT}” “${EMAIL}”

New contributor

Quertino is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật