* Tue Mar 18 2025 Jean-Philippe Pialasse <jpp@koozali.org> 11.0.0-9.sme

- update config for Nut 2.8.2 [SME: 12657]
  TODO review master/slave mode
  TODO convert master/slave to primary/secondary
  TODO convert to new config data + migrate
  TODO event and action
This commit is contained in:
2025-05-14 23:06:09 -04:00
parent 30dcc4861f
commit a768594f0f
34 changed files with 292 additions and 108 deletions

View File

@@ -0,0 +1 @@
disabled

View File

@@ -0,0 +1 @@
service

View File

@@ -0,0 +1 @@
disabled

View File

@@ -0,0 +1 @@
service

View File

@@ -0,0 +1 @@
disabled

View File

@@ -0,0 +1 @@
service

View File

@@ -0,0 +1 @@
3493

View File

@@ -1 +1 @@
service
configuration

View File

@@ -2,7 +2,21 @@
use MIME::Base64 qw(encode_base64);
my $nutrec = $DB->get('nut') || $DB->new_record('nut', {type => 'service'});
$nutrec->set_prop('MasterPass', sprintf("%15.0f", int( (1000000000000000) * rand() ))) if not $nutrec->prop('MasterPass');
$nutrec->set_prop('SlavePass', sprintf("%15.0f", int( (1000000000000000) * rand() ))) if not $nutrec->prop('SlavePass');
  # migrate old
$nutrec->set_prop('PrimaryPass',$DB->get_prop_and_delete('nut', MasterPass)) if (exists $nut{'MasterPass'});
$nutrec->set_prop('SecondaryPass',$DB->get_prop_and_delete('nut', SlavePass)) if (exists $nut{'SlavePass'});
$nutrec->set_prop('PrimaryPass', sprintf("%15.0f", int( (1000000000000000) * rand() ))) if not $nutrec->prop('PrimaryPass');
$nutrec->set_prop('SecondaryPass', sprintf("%15.0f", int( (1000000000000000) * rand() ))) if not $nutrec->prop('SecondaryPass');
$nutrec->set_prop('AdminPass', sprintf("%15.0f", int( (1000000000000000) * rand() ))) if not $nutrec->prop('AdminPass');
# if $nut{SlaveUPS} defined we set and the target not existing ClientUPS ; then delete SlaveUPS
# set ClientUser as upsslave (was the content before sme11) intended for smooth migration
# set ClientPass as $nut{SlavePass}/{SecondaryPass}
if ( $nut{'SlaveUPS'} ) {
$nutrec->set_prop('ClientUPS',$DB->get_prop_and_delete('nut','SlaveUPS') ) if not $nut{'ClientUPS'};
$nutrec->set_prop('ClientUser','upsslave');
$nutrec->set_prop('ClientPass',$nutrec->prop('SecondaryPass'));
}
}

View File

@@ -0,0 +1,18 @@
#!/bin/bash
#if MODE = netserver then access should be private
#if MODE = netclient only enable monitor
# calling this script to configure unit and drivers
if [[ $(config getprop nut status || echo "disabled") == "disabled" ]] ; then
# disable server
# leave monitor as is, we might want to monitor an external ups ?
# get_all_by_prop filter nut-driver@ and foreach $UPS disabled
exit 0;
fi
# nut is enabled
# enable nut-monitor
# enable nut-server "enable nut-server.service\n" if ($master eq 'yes');
# get_all_by_prop filter nut-driver@ and foreach $UPS enable.
/usr/libexec/nut-driver-enumerator.sh

View File

@@ -1 +0,0 @@
MODEL=upsdrvctl

View File

@@ -1 +0,0 @@
SERVER={ $nut{Master} || 'yes' }

View File

@@ -1,16 +1,26 @@
# nut UPS specific subservices
{
$nutstatus = $nut{status} || 'disabled';
$master = $nut{Master} || 'yes';
$mode = $nut{Mode} || 'standalone';
my @upses = grep(/^nut-driver\@[a-zA-Z0-9_-]+$/, $DB->keys);
if ($nutstatus eq 'enabled') {
$OUT .= "enable nut-server.service\n" if ($master eq 'yes');
$OUT .= "disable nut-server.service\n" unless ($master eq 'yes');
$OUT .= "enable nut-monitor.service\n";
$OUT .= "enable nut-server.service\n" if ($mode ne 'netclient');
$OUT .= "disable nut-server.service\n" unless ($mode eq 'netclient');
$OUT .= "enable nut-monitor.service\n";
foreach my $ups ( sort {$a cmp $b} @upses )
{
$OUT .= "enable $ups.service\n";
}
}
else
{
$OUT .= "disable nut-server.service\n";
$OUT .= "disable nut-monitor.service\n";
foreach my $ups ( sort {$a cmp $b} @upses )
{
$OUT .= "disable $ups.service\n";
}
}
}

View File

@@ -0,0 +1,7 @@
# mode could be none|standalone|netserver|netclient
MODE={
return "none" unless ( ($nut{"status"}||"disabled") eq "enabled");
# if Master no => netclient
# if Master yes => standalone or netserver
$nut{mode} || "standalone";
}

View File

@@ -0,0 +1,10 @@
# Uncomment this to allow starting the `upsd` data server even if `ups.conf`
# has no device sections configured at the moment. This environment variable
# overrides the built-in "false" flag in `upsd`, and an optional same-named
# default flag that can be set in `upsd.conf`. If you want a data server always
# running, even if it initially has nothing to serve (may be live-reloaded
# later, when devices become configured), this option is for you.
#ALLOW_NO_DEVICE=true
#export ALLOW_NO_DEVICE

View File

@@ -0,0 +1,11 @@
# Uncomment this to allow starting the `upsd` data server even if not all
# `LISTEN` directives can be honoured at the moment. This environment variable
# overrides the built-in "false" flag in `upsd`, and an optional same-named
# default flag that can be set in `upsd.conf`. If you want a data server always
# running, even if it would potentially not serve all clients on every uptime,
# this option is for you (note you would have to restart `upsd` to pick up the
# `LISTEN`ed IP address if it appears later). Probably `LISTEN *` is better.
#ALLOW_NOT_ALL_LISTENERS=true
#export ALLOW_NOT_ALL_LISTENERS

View File

@@ -0,0 +1,6 @@
# The optional 'UPSD_OPTIONS' allow to set upsd specific command-line options.
# It is ignored when 'MODE' above indicates that no upsd should be running.
# It may be redundant in comparison to options which can be set in `upsd.conf`.
#UPSD_OPTIONS=

View File

@@ -0,0 +1,6 @@
# The optional 'UPSMON_OPTIONS' allow to set upsmon specific command-line options.
# It is ignored when 'MODE' above indicates that no upsmon should be running.
# It may be redundant in comparison to options which can be set in `upsmon.conf`.
#UPSMON_OPTIONS=

View File

@@ -0,0 +1,9 @@
# If the optional 'POWEROFF_WAIT' is configured (to a value that can be handled
# by `/bin/sleep` on the current system - typically an integer with the number
# of seconds for a delay, but not always limited to that syntax), and the current
# system which manages one or more UPS devices would not only command it to shut
# down, but also try to avoid the "Power race". Caveats emptor, see NUT FAQ and
# other docs for details.
#POWEROFF_WAIT=3600

View File

@@ -0,0 +1,8 @@
# The optional 'POWEROFF_QUIET' setting controls if the NUT shutdown integration
# scripts or service units would emit messages about their activity (or lack
# thereof). By default they may be verbose, to aid post-mortem troubleshooting
# via logs or console captures.
# Set to `true` to avoid that trove of information, if you consider it noise.
#POWEROFF_QUIET=true

View File

@@ -1,16 +1,21 @@
{
my $model = $nut{Model} || "usbhid-ups";
my $device = $nut{Device} || "/var/lib/ups/hiddev0";
my $type = $nut{Type};
my $mfr = $nut{mfr};
my $mdl = $nut{mdl};
$OUT .= "[UPS]\n";
$OUT .= "\tdriver = $model\n";
if ($model eq 'genericups')
{
$OUT .= "\tupstype = $type\n" if defined $type;
$OUT .= "\tmfr = $mfr\n" if defined $mfr;
$OUT .= "\tmodel = $mdl\n" if defined $mdl;
my @upses = grep(/^nut-driver\@[a-zA-Z0-9_-]+$/, $DB->keys);
foreach my $ups ( sort {$a cmp $b} @upses )
{
my $nnut = ${$ups};
my $model = $nnut{Model} || "usbhid-ups";
my $device = $nnut{Device} || "auto"; #"/var/lib/ups/hiddev0";
my $type = $nnut{Type};
my $mfr = $nnut{mfr};
my $mdl = $nnut{mdl};
$OUT .= "[UPS]\n";
$OUT .= "\tdriver = $model\n";
if ($model eq 'genericups')
{
$OUT .= "\tupstype = $type\n" if defined $type;
$OUT .= "\tmfr = $mfr\n" if defined $mfr;
$OUT .= "\tmodel = $mdl\n" if defined $mdl;
}
$OUT .= "\tport = $device\n";
}
$OUT .= "\tport = $device\n";
}

View File

@@ -1,8 +1,18 @@
[upsprimary]
password = { $nut{PrimaryPass} }
upsmon primary
[upssecondary]
password = { $nut{SecondaryPass} }
upsmon secondary
{
# we keep those two for backward compatibility pre SME11
}
[upsmaster]
password = { $nut{MasterPass} }
upsmon master
password = { $nut{PrimaryPass} }
upsmon primary
[upsslave]
password = { $nut{SlavePass} }
upsmon slave
password = { $nut{SecondaryPass} }
upsmon secondary

View File

@@ -1,7 +1,14 @@
{
if ( ($nut{Master} || 'yes') ne 'no' ) {
$OUT = "MONITOR UPS\@localhost 1 upsmaster $nut{MasterPass} master";
} else {
$OUT = "MONITOR $nut{SlaveUPS} 1 upsslave $nut{SlavePass} slave";
}
if ( ($nut{Mode} || 'standalone') eq 'netclient' ) {
$OUT = "MONITOR $nut{ClientUPS} 1 $nut{ClientUser} $nut{ClientPass} secondary";
} else {
my @upses = grep(/^nut-driver\@[a-zA-Z0-9_-]+$/, $DB->keys);
my $size = scalar(@upses);
foreach my $ups ( sort {$a cmp $b} @upses )
{
my ($upsname) = $ups =~ /^nut-driver\@([a-zA-Z0-9_-]+)$/ ;
$OUT .= "MONITOR $upsname\@localhost 1 upsprimary $nut{PrimaryPass} primary";
$OUT .= "\n" if --$size >=1;
}
}
}