Shut down warm backup server via SSH

I have created a warm backup server using the guide in the Wiki. I have my main PBX plugged in to a Cyberpower 1350VA UPS via a USB. This shuts down the main PBX fine, but is there a way for it to also shut down the warm spare?

Hi,

You can run a post backup hook. It is a script that will ssh to the backup server as root and send a poweroff command.
Why do you want to shutdown your backup server anyway?

Thank you,

Daniel Friedman
Trixton LTD.

I would like to shut it down gracefully in the event of a full power failure to protect it.

How would I create the post backup hook? I’ve never done anything like that before.

Traditionally one could write an init script that would in effect exec:-

ssh the_other_server ‘shutdown -h now’

if the shutdown was called by the UPS, this would need to be called before the network was stopped, and depends on what you are using for init, ‘systemd’ or ‘system V’ and what run-level your system calls on shutdown.

Hi,

Just create a bash script similar to this (I am assuming that you are authenticated by a certificate):

#!/bin/bash

function shutdown_backup_server () {

  ssh root@backup_server.com -t "poweroff"

}

shutdown_backup_server

Please be advised that if you will use this script as a post backup hook, it will shutdown the backup server every time. If you want to shutdown your backup server just in a power failure, you can run this script manually from your production server.

Thank you,

Daniel Friedman
Trixton LTD.

Being that this is a “post backup” script that it will shutdown the warm spare after each backup? If that’s the case, that’s not really what I’m looking for.

Hi,

If you had read my answer again, you probably would have noticed that I have suggested to run this script manually in a power down situation.

Thank you,

Daniel Friedman
Trixton LTD.

That’s why I suggest the init script route, it will be run whenever your system is “called down” including a usb UPS instigated one. It requires no “manual” intervention, which would be absolutely necessary in this use case.

Hi,

Yes, I agree with @dicko. You can take my bash script and run it with your UPS software in a power down failure. Just do not forget to give it execution rights (chmod +x script_name.sh)

Thank you,

Daniel Friedman
Trixton LTD.

Manually running it is not an option. The power could go out when these are unattended.

I’ll look into the other option.

Thanks

For quick and dirty, and if these devices are like most (APC cpome to mind) , somewhere in the software install location will be a script called shutdown.sh or something similar, it is probably a good idea to find it and add the

ssh the_other_server ‘shutdown -h now’

to it before it calls shutdown locally. (You will need “password less” ssh access to the other server.)

I think you just want to use the (already existing) UPS configuration in Sysadmin.

If you have a look at the documentation, you’ll see that you can add a file /etc/apcupsd/doshutdown that will do ‘things’ when the UPS says its time to shut down.

1 Like

If sysadmin can run on your machine (mine can’t, and it is not open source and this is in ‘general help’) and the device supports apcupsd, (not guaranteed) :wink:

This sounds like the best solution, but my UPS is a Cyberpower, not APC. Will it still work with Cyberpower? It seems like that documentation is for APC.

Many times the chinese stuff is derivative or just a straight copy, look in the files that where installed somewhere to handle the usb connection, I am sure you will find a shell script that does what I suggest. Edit it . . .

https://www.google.com.au/search?q=cyberpower+apcupsd

Suggests it will

Thanks for the help guys. I’ve read through that link and determined this is too far above my head for now. I may visit it later.

Thanks!

That’s where consulting can help you, I suggest you start with