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.

Unraid on the Laptop, using battery as an UPS.

Featured Replies

Hi,

 

I am using Thinkpad W530 Laptop for unraid server. Today, after fruitful discussion on this forum I made a user.script that will shutdown unraid when laptop battery is bellow 30% and ac is off.

Plugin user.script

is required to use my solution.

All You need to do is to extract attached archive to folder:  /boot/config/plugins/user.scripts/scripts/shutdownWhenBatteryDepleted

root@nas:/boot/config/plugins/user.scripts/scripts/shutdownWhenBatteryDepleted# ls -l
total 64
-rw------- 1 root root 2716 Mar  6 09:41 ac.ko.xz
-rw------- 1 root root 6700 Mar  6 09:41 battery.ko.xz
-rw------- 1 root root  177 Mar  6 11:20 description
-rw------- 1 root root 1018 Mar  6 12:54 script
root@nas:/boot/config/plugins/user.scripts/scripts/shutdownWhenBatteryDepleted#

 

It is important not to change script name, as path to *.ko.xz module is hardcoded in the script file.

When this is done, You must test script, by running it manually. Then after You make sure it works in Your system You can enable the scheduler. Script will write log using logger command when shutdown is issued.

On first run script will load ac and battery kernel modules.

battery.thumb.png.bf484db2f3d5ebc3890e46fee0c89952.png

 

In the attached figure I am running script every one minute, but maybe every 2 minutes would be sufficient. You can enter */2 * * * * to run script every 2 minutes. Use this website https://crontab.guru to find Your preferred schedule.

 

Use at Your own risk! For testing purpose I suggest commenting out (sign #) command /sbin/poweroff in my script.

I am still unsure if /sbin/poweroff is proper way to shutdown VMs and docker gracefully. Waitng for support to answere my question, as I was unable to find it on the Internet.

 

Best Regards,

Kacper

 

shutdownWhenBatteryDepleted_unraid6_8_3.zip shutdownWhenBatteryDepleted_unraid6_9_0.zip

Edited by Kacper
Added kernel modules for unraid 6.9.0

  • Author

According to reply from a forum /sbin/poweroff will wait  Settings -> VM Manager -> VM shutdown time-out:  number of seconds before forcing shutdown.

 

shutdown.thumb.png.170cf29293b87c94a5e1f1b06e5a16da.png

  • Author

There is also second timeout setting - global timeout that schould be greater than VM shutdown timeout.

 

globalTimeout.thumb.png.94f0588e1b2000e2fd266b7ccc143d69.png

  • 5 months later...

@KacperThanks for this great solution
Did you build the "battery" and "ac" kernel modules yourself? or did you get pre-compiled versions of them?
I would like to test it on Unraid 6.10 rc: Linux version 5.13.13-Unraid (gcc (GCC) 11.2.0, GNU ld version 2.36.1-slack15)

 

  • Author

Hi nice to know u like it. I used docker called:

unraid-kernel-helper

 

Then I set to manual compile or sth. like that. Then I did my own make menuconfig - like it is described in the manual for this docker. Then I compiled with make commands. At the end i have copied over ssh battery modules.

  • 3 months later...

hi

 

don't understand what i'm doing wrong

i try to test first time after installation and it gives me this message

 

any idea?

Immagine 2021-12-24 174007.png

First thing to do is to get the appropriate commands working from the command line before using User Scripts as it introduces other complications

  • Author

I am almost sure that this message means that module is not compiled for kernel used by unraid 6.9.2. Pay attention that I have compiled modules for unraid 6.8.3 and 6.9.0. I am still using unraid 6.9.0 as I don't want to waste time for upgrading my unraid server. It works fine right now. So you need to use docker called unraid-kernel-helper if it is already avaliable for 6.9.2 and compile ac and battery modules by yourselfe. Script will stay the same, it will work if modules load correctly.

  • 2 months later...

@Kacper

Thanks so much for your work. Do you feel like writing up a detailed explanation on how to install those missing modules required by your script? That would be an amazing help.

Or could you just compile the modules for unraid 6.9.2, the current stable release?

Edited by brin

@brin & @Kacper & @usmaple & @thecode:

 

Here is a package for 6.9.2: battery-5.10.28-Unraid-1.txz with the two modules, place it somewhere on your server, navigate to the that folder in a terminal and to install it simply type in:

installpkg battery-5.10.28-Unraid-1.txz
depmod -a

(this has to be done on every reboot, or simply put it somewhere on your server and add the above commands to your go file, keep in mind that you maybe have to add the path to the file)

!!!THIS PACKAGE WORSK ONLY ON UNRAID 6.9.2!!!

 

After that change the scripts to the following because the modules are installed directly to the libraries directory and this makes also sure that the script is compatible with newer Unraid releases (read below):

FILE=/sys/class/power_supply/BAT0/capacity
if [ -f "$FILE" ]; then
    capacity=`cat "$FILE"`
else 
    echo "$FILE does not exist. Trying to enable battery module"
    logger "$FILE does not exist. Trying to enable battery module"
    modprobe battery
fi

FILE2=/sys/class/power_supply/AC/online
if [ -f "$FILE2" ]; then
    online=`cat "$FILE2"`
else 
    echo "$FILE2 does not exist. Trying to enable ac module"
    logger "$FILE2 does not exist. Trying to enable ac module"
    modprobe ac
fi


# online is expected to be 0 or 1 - ac on or off
# capacity is expected to be 0-100 - percent of battery charge

# for testing change number to 101 and 0 inside if statement
# for normal operation set 30 and 1 as constant value to compare variables with

if [ -n "$capacity" ] && [ -n "$online" ] && [[ "$capacity" -lt "30" ]] && [[ "$online" -ne "1" ]]; then
    echo "$(date) Battery bellow safe margin. Shutting down system."
    logger "Battery bellow safe margin. Shutting down the system."
    # Unraid shutdown command here
    /sbin/poweroff
fi

 

 

From what I see the two modules that are needed for this script to work are included in the next release from the Unraid RC series and you don't need the package anymore, the script that I've modified above should be enough and will work for the next Unraid RC series releases and even the stable releases afterwards.

  • Author

Thanks ich777 for compiling these modules for all of us :)

@ich777 Thank you so much!! Seems to work very nicely.

  • 4 months later...

Anybody got a copy working for 6.10.3?

9 hours ago, daver898 said:

Anybody got a copy working for 6.10.3?

 

On 3/8/2022 at 4:31 AM, ich777 said:

From what I see the two modules that are needed for this script to work are included in the next release from the Unraid RC series and you don't need the package anymore, the script that I've modified above should be enough and will work for the next Unraid RC series releases and even the stable releases afterwards.

 

  • 1 year later...

Do this still work on latest version? Should I install the modules or only the script and set it up from user.scripts module? 

 

edit:

To answer my own question - modules are not needed on latest Unraid. Only user.scripts, the script from this thread and cron job. I have to change the script little but after that my unraid has valid "UPS" :) 

Edited by bladyle

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...

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.