Stop docker on UPS power


Recommended Posts

Hi, can any one tell me if there is a way to stop docker containers when the server is running off ups power?

I have a foldingathome container which i have running on the server which I need to stop if the power goes out and is running on the UPS
My UPS is capable of running my unraid server for over 45min if I do not have the foldingathome docker running but only 10min if everything is running at 100%

Thanks

Link to comment

The purpose of UPS is to allow safe shutdown, not to allow running on batteries. If you run the batteries down you will have to let them recharge sufficiently before starting your server again or you won't have enough battery for safe shutdown.

 

After a short time on batteries, you can assume the power is going to be off for an unknown time and it should just go ahead and shutdown.

  • Like 1
Link to comment
8 minutes ago, trurl said:

The purpose of UPS is to allow safe shutdown, not to allow running on batteries. If you run the batteries down you will have to let them recharge sufficiently before starting your server again or you won't have enough battery for safe shutdown.

 

After a short time on batteries, you can assume the power is going to be off for an unknown time and it should just go ahead and shutdown.

While this is true yes 99% of the power outages where I live are less than 15min. Which is easily within the run time of my UPS when foldingathome is not running, but, would require a shutdown if it is.

I have the system setup to shutdown at 15min reported runtime remaining

Link to comment
  • 2 months later...

@pyrosrockthisworld I just got a UPS and wanted to do the exact same thing: stop the FaH container while running from battery.  I did some reading in the APCUPSD manual (specifically Customizing Event Handling), and I've come up with a simple method.

 

The apccontrol script (in /etc/apcupsd/) gets called when apcupsd detects an "event".  Switching to battery power ('onbattery') and back to mains power ('offbattery') are both recognized events.  When these events occur, the apccontrol script calls event-specific scripts (named the same as the event) located in /etc/apcupsd.  By adding 'docker stop' to the 'onbattery' script, and 'docker start' lines to the 'offbattery' script, power-intensive docker containers can be prevented from running while on battery power.  The 'onbattery' and 'offbattery' scripts already exist in /etc/apcupsd.

 

In the /etc/apcupsd/onbattery script, I added the following line right above 'exit 0':

docker stop FoldingAtHome

 

In the /etc/apcupsd/offbattery script, I added:

docker start FoldingAtHome

 

You could add more Docker container names after "FoldingAtHome" to stop/start additional containers.

 

I've tested it several times, and the FaH container stops several seconds after switching to battery power, and then starts again once mains power is restored.

 

Edit: Looks like this is the exact same method used in the post linked by @kizer.  I could have saved some time... oh well. I learned more by figuring it out myself.

 

Note:  If the power outage is only a few seconds long, the container won't be stopped by the time power is restored, and the 'start' command is issued.  If the container is still stopping, then it won't start, and you'll be left with a stopped container.

Edited by C4RBON
Changing from pause/restart to stop/start
Link to comment

What happens to a paused container when the battery limit is reached and Unraid shuts down?  Would "docker stop" and "docker start" be more appropriate?  Could data get lost by using pause?  I read that when you use pause, the container doesn't know it's being paused.  So if it is shut down before being restarted, could you lose data?

 

Edit: After doing some reading, it seems that stop/start are more appropriate for this scenario, since a shutdown is likely after running on battery.  I'll update my previous post to reflect stop/start instead of pause/restart.

Edited by C4RBON
Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.