* 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:
22
root/etc/e-smith/db/configuration/migrate/20nutMigrate
Normal file
22
root/etc/e-smith/db/configuration/migrate/20nutMigrate
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
# migrate to SME11
|
||||
# first we get ride of Master=no
|
||||
# if Mode not set then set it according to Master
|
||||
my $mnut = $DB->get('nut') || $DB->new_record('nut', {type => 'service'});
|
||||
my $nutMaster = $DB->get_prop_and_delete ('nut','Master');
|
||||
unless ( ${'nut'}{'Mode'} ) {
|
||||
$mnut>set_prop('Mode','netserver') if $nutMaster eq "yes";
|
||||
}
|
||||
|
||||
# if nut-driver@ups not existing create it
|
||||
my $driverUPS = $DB->get('nut-driver@ups') || $DB->new_record('nut-driver@ups', {type => 'service'});
|
||||
# then migrate to nut-driver@ups (first UPS) the following properties
|
||||
my $mdl = $DB->get_prop_and_delete ('nut','mdl');
|
||||
$driverUPS->set_prop('mdl',$mdl) unless ${'nut-driver@ups'}{'mdl'};
|
||||
my $mfr = $DB->get_prop_and_delete ('nut','mfr');
|
||||
$driverUPS->set_prop('mfr',$mfr) unless ${'nut-driver@ups'}{'mfr'};
|
||||
my $model = $DB->get_prop_and_delete ('nut','Model');
|
||||
$driverUPS->set_prop('Model',$model) unless ${'nut-driver@ups'}{'Model'};
|
||||
my $Type = $DB->get_prop_and_delete ('nut','Type');
|
||||
$driverUPS->set_prop('Type',$model) unless ${'nut-driver@ups'}{'Type'};
|
||||
}
|
52
root/etc/e-smith/events/actions/nut-config
Normal file
52
root/etc/e-smith/events/actions/nut-config
Normal file
@@ -0,0 +1,52 @@
|
||||
#!/bin/bash
|
||||
|
||||
# this script is called before template-expand
|
||||
# then another script is called to run /usr/libexec/nut-driver-enumerator.sh and start/stop drivers
|
||||
# then traditionnal services2adjust
|
||||
|
||||
# calling this script to configure unit and drivers
|
||||
if [[ $(/sbin/e-smith/config getprop nut status || echo "disabled") == "disabled" ]] ; then
|
||||
# disable server
|
||||
/sbin/e-smith/config setprop nut-server status disabled
|
||||
/sbin/e-smith/config setprop nut access localhost
|
||||
# disable monitor
|
||||
/sbin/e-smith/config setprop nut-monitor status disabled
|
||||
# TODO get_all_by_prop filter nut-driver@ and foreach $UPS disabled
|
||||
#config keys|grep nut-driver
|
||||
for OUTPUT in $(/sbin/e-smith/config keys|grep nut-driver)
|
||||
do
|
||||
/sbin/e-smith/config setprop $OUTPUT status disabled
|
||||
done
|
||||
|
||||
exit 0;
|
||||
fi
|
||||
# nut is enabled
|
||||
|
||||
# we set services depending on Mode
|
||||
Mode=$(/sbin/e-smith/config getprop nut Mode || echo "standelone")
|
||||
if [[ $Mode == "netserver" ]] ; then
|
||||
/sbin/e-smith/config setprop nut-server status enabled
|
||||
/sbin/e-smith/config setprop nut access private
|
||||
elif [[ $Mode == "netclient" ]] ; then
|
||||
/sbin/e-smith/config setprop nut-server status disabled
|
||||
/sbin/e-smith/config setprop nut access localhost
|
||||
else
|
||||
/sbin/e-smith/config setprop nut-server status enabled
|
||||
/sbin/e-smith/config setprop nut access localhost
|
||||
fi
|
||||
# enable nut-monitor
|
||||
/sbin/e-smith/config setprop nut-monitor status enabled
|
||||
|
||||
# get_all_by_prop filter nut-driver@ and foreach $UPS enable.
|
||||
if [[ $Mode == "netclient" ]] ; then
|
||||
for OUTPUT in $(/sbin/e-smith/config keys|grep nut-driver)
|
||||
do
|
||||
/sbin/e-smith/config setprop $OUTPUT status disabled
|
||||
done
|
||||
else
|
||||
for OUTPUT in $(/sbin/e-smith/config keys|grep nut-driver)
|
||||
do
|
||||
/sbin/e-smith/config setprop $OUTPUT status enabled
|
||||
done
|
||||
fi
|
||||
|
@@ -1,18 +1,33 @@
|
||||
#!/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 [[ $(/sbin/e-smith/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.
|
||||
# another script is called before template-expand to set services
|
||||
# this script is called to run /usr/libexec/nut-driver-enumerator.sh and start/stop drivers
|
||||
# then traditionnal services2adjust
|
||||
|
||||
# enumerate / configure drivers
|
||||
/usr/libexec/nut-driver-enumerator.sh
|
||||
|
||||
event=$1
|
||||
|
||||
if [[ $i == "post-upgrade" ]] ; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [[ $i == "bootstrap-console-save" ]] ; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [[ $(/sbin/e-smith/config getprop nut status || echo "disabled") == "disabled" ]] ; then
|
||||
# if disabled stop them
|
||||
for OUTPUT in $(/sbin/e-smith/config keys|grep nut-driver)
|
||||
do
|
||||
/usr/bin/systemctl stop $OUTPUT
|
||||
done
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# if we are there we want to restart / start them
|
||||
for OUTPUT in $(/sbin/e-smith/config keys|grep nut-driver)
|
||||
do
|
||||
/usr/bin/systemctl restart $OUTPUT
|
||||
done
|
||||
|
@@ -3,12 +3,13 @@
|
||||
foreach my $ups ( sort {$a cmp $b} @upses )
|
||||
{
|
||||
my $nnut = ${$ups};
|
||||
my ($name )= $ups =~ /^nut-driver\@(.*)$/ ;
|
||||
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 .= "[$name]\n";
|
||||
$OUT .= "\tdriver = $model\n";
|
||||
if ($model eq 'genericups')
|
||||
{
|
||||
|
@@ -1,14 +1,14 @@
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user