Files
unraid-nut-actions/nut-actions.plg

106 lines
4.1 KiB
XML

<?xml version='1.0' standalone='yes'?>
<!DOCTYPE PLUGIN [
<!ENTITY name "nut-actions">
<!ENTITY author "ich777">
<!ENTITY version "2025.02.25">
<!ENTITY md5 "8962ce4903db6efaa035921629750398">
<!ENTITY launch "Settings/nut-actions">
<!ENTITY gitURL "https://github.com/&author;/unraid-&name;/raw/master">
<!ENTITY pluginURL "&gitURL;/&name;.plg">
<!ENTITY plugin "/boot/config/plugins/&name;">
<!ENTITY emhttp "/usr/local/emhttp/plugins/&name;">
]>
<PLUGIN name="&name;" author="&author;" version="&version;" launch="&launch;" pluginURL="&pluginURL;" min="6.12.14" support="https://forums.unraid.net/topic/92865-support-ich777-amd-vendor-reset-coraltpu-hpsahba">
<CHANGES>
###2025.02.25
- Add configurable delay in seconds for on-battery task (defaults to 0), configruable in the file: &plugin;/settings.cfg
###2024.12.17
- Spin down all disks when on battery
###2024.12.15
- Initial release
</CHANGES>
<FILE Run="/bin/bash">
<INLINE>
rm -f $(ls &plugin;/&name;*.txz 2>/dev/null|grep -v '&version;')
</INLINE>
</FILE>
<FILE Name="&plugin;/&name;-&version;.txz" Run="upgradepkg --install-new">
<URL>&gitURL;/packages/&name;-&version;.txz</URL>
<MD5>&md5;</MD5>
</FILE>
<FILE Name="&emhttp;/README.md">
<INLINE>
**NUT Actions**
This plugin is intended to seamlessly integrate with the NUT Plugin, automatically shutting down all your Docker and LXC Containers, as well as virtual machines (VMs), when your Server is operating on battery power to save energy to bridge power outages without shutting down your Server. You can specify exceptions to this behavior. Once power is restored, the plugin will automatically restart all previously running containers and VMs.
</INLINE>
</FILE>
<FILE Run="/bin/bash">
<INLINE>
if [ ! -f /boot/config/plugins/nut-dw.plg ]; then
removepkg &name;-&version;
rm -rf &emhttp;
rm -rf &plugin;
echo "------------------------------------------------------------------------------------------"
echo "---ERROR: NUT Plugin not found! Please install the NUT Plugin from desertwitch aka Rysz---"
echo "------------------------------------------------------------------------------------------"
exit 1
fi
if [ ! -f &plugin;/settings.cfg ]; then
echo "DELAY_SECONDS=0" &gt; &plugin;/settings.cfg
fi
grep -q '/usr/bin/nut-actions on_line' /boot/config/plugins/nut-dw/ups/xnut-notify-hooks.sh || sed -i -e '/^ONLINE /,/}/{/}/s/^/ if [ -f \/usr\/bin\/nut-actions ]; then\n \/usr\/bin\/nut-actions on_line\n fi\n/}' /boot/config/plugins/nut-dw/ups/xnut-notify-hooks.sh
grep -q '/usr/bin/nut-actions on_battery' /boot/config/plugins/nut-dw/ups/xnut-notify-hooks.sh || sed -i -e '/^ONBATT /,/}/{/}/s/^/ if [ -f \/usr\/bin\/nut-actions ]; then\n \/usr\/bin\/nut-actions on_battery\n fi\n/}' /boot/config/plugins/nut-dw/ups/xnut-notify-hooks.sh
if [ -f /etc/nut/xnut-notify-hooks.sh ]; then
if ! grep -q '/usr/bin/nut-actions on_line' /etc/nut/xnut-notify-hooks.sh ; then
cp /boot/config/plugins/nut-dw/ups/xnut-notify-hooks.sh /etc/nut/xnut-notify-hooks.sh
chmod +x /etc/nut/xnut-notify-hooks.sh
fi
fi
echo "---------------------------------------------------"
echo "---Installation from NUT Actions Plugin complete---"
echo "---------------------------------------------------"
</INLINE>
</FILE>
<FILE Run="/bin/bash" Method="remove">
<INLINE>
echo "-------------------------------------"
echo "---Uninstalling NUT Actions Plugin---"
echo "-------------------------------------"
sed -i '/^ \{4\}if \[ -f \/usr\/bin\/nut-actions \]; then/{N;N;d;}' /boot/config/plugins/nut-dw/ups/xnut-notify-hooks.sh
if [ -f /etc/nut/xnut-notify-hooks.sh ]; then
cp /boot/config/plugins/nut-dw/ups/xnut-notify-hooks.sh /etc/nut/xnut-notify-hooks.sh
chmod +x /etc/nut/xnut-notify-hooks.sh
fi
# Remove plugin related files
removepkg &name;-&version;
rm -rf &emhttp;
rm -rf &plugin;
echo
echo "----------------------------------------------------------------"
echo "---NUT Actions Plugin uninstalled, please reboot your server!---"
echo "----------------------------------------------------------------"
echo
</INLINE>
</FILE>
</PLUGIN>