ElectricEel-24.10.1 Issue

That’s about what my script looks like, mainly just calling the sendmail.py with appropriate parameters.

I tried calling it via the init/shutdown functions, and as a service. The former doesn’t work at all, middleware is downed before the python script finishes. Same with running it as a service.

As a service works when testing on local lan, but not remotely. My remote connection is established by connecting the test truenas box via ethernet to another router, then wireguard to my pfsense (as a peer). That other router gets internet from an ethernet tethered phone using mobile data. So from one extreme to the other. Pings between the two end points can be as high as 300ms (mobile data service sucks around here).

I think the goal to making this work is to figure out how to ensure the sendmail.py completes fully before TN shuts down all its services.

For the service I had

[Unit]
Description=Shutdown Email Notification Process
#DefaultDependencies=no
#Before=shutdown.target
#After=middlewared.service network.target
#Requires=network.target

Before=shutdown.target reboot.target
#Requires=middlewared.service wg-quick@wg0.service
Requires=wg-quick@wg0.service

# This works because it is installed in the target and will be
#   executed before the target state is entered
# Also consider kexec.target

[Service]
Type=oneshot
RemainAfterExit=true
ExecStart=/bin/true
ExecStop=/root/util/shutdownemail.sh
TimeoutSec=30


[Install]
WantedBy=multi-user.target
#WantedBy=halt.target reboot.target shutdown.target

For the script

#!/bin/sh

uptime=$(awk '{print $1}' /proc/uptime)
uptime=$(echo $uptime | awk '{ printf "%d\n",$1 }'  )

if [ "$uptime" -lt "30" ]  ;

then
     exit
else

     /usr/bin/python3 /root/sendmail.py --subject "Remote Nas Shutdown on $(date)" --to_address user@domain.com --mail_body_html "Shutdown or reboot occurred on $(date)"

fi