I have an Ubuntu 20.04 server, I'm connecting to a UPS. I want the Ubuntu server to shut down a truenas server, also on the same ups. The idea is that the UPS software on Ubuntu server triggers the shutdown on the trunas server when the battery is at 50%, The ubuntu server in turn triggers a shutdown of the trunas server, giving time for both boxes to power down gracefully.
I've set up the following script file truenas-off.sh
:
echo "shutdown occurred at $(date)" >> /root/shutdown-events.log
ssh root@1.2.3.4 "midclt call system.shutdown"
I set the script up as described here, the only difference is I set mine to just shutdown.
cat /etc/systemd/system/truenas-off.service
[Unit]
Description=Run truenas-off on shutdown
[Service]
Type=oneshot
RemainAfterExit=true
ExecStart=/root/truenas-off.sh
[Install]
WantedBy=multi-user.target
I've run ssh-keygen
on the ubuntu server and ssh-copy-id root@truenas-IP
and when I've issued sudo -i
, authenticated, I can ssh root@trunasIP truenas-off.sh
and the trunas turns off
It just doesn't seem to want to work automatically when I shutdown the Ubuntu server.
What am I doing wrong?
There's a similar problem, but not quite the same here: How to send shutdown command to servers
[unit]
section of the script that tells systemd to run the service at shutdown. By default the service will run when the system boots. – user68186 Jan 30 '24 at 19:36truenas-off.sh
you have the commandssh root@1.2.3.4 "midclt call system.shutdown"
. Does 1.2.3.4 stand fortrunasIP
that you use later? Why do you run this script from within the Trunas manually byssh root@trunasIP truenas-off.sh
. Does the scripttruenas-off.sh
stored in the Ubuntu server or in the Truenas? – user68186 Jan 30 '24 at 21:08journalctl
to see if your service is running – Daniel T Jan 30 '24 at 23:18ExecStop=
allows running a command (or multiple commands) when the service is stopped, not necessarily when the computer is stopped. It is important to understand the nuances. – user68186 Feb 01 '24 at 19:12