Skip to content
View in the app

A better way to browse. Learn more.

Unraid

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Stop docker on UPS power

Featured Replies

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

  • Community Expert

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.

  • Author
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

  • 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

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

Archived

This topic is now archived and is closed to further replies.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.