Changes

From SME Server
Jump to navigationJump to search
m
no edit summary
Line 26: Line 26:  
Most USB connected UPS's will work with these default settings. If using a USB connection just enable NUT as follows:
 
Most USB connected UPS's will work with these default settings. If using a USB connection just enable NUT as follows:
    +
<tabs container>
 +
<tab name="SME 10">
 +
For '''SME 10''', systemd is now in use. We have created a generic service for your convenience:
 +
 +
config setprop nut status enabled
 +
signal-event e-smith-nutUPS-update
 +
systemctl restart nut-server.service
 +
systemctl restart nut-monitor.service
 +
systemctl restart nut.service
 +
</tab>
 +
<tab name="SME 9 and earlier">
 
  config setprop nut status enabled
 
  config setprop nut status enabled
 
  signal-event post-upgrade
 
  signal-event post-upgrade
 
  signal-event reboot
 
  signal-event reboot
    +
</tab>
 +
</tabs>
 
If your USB UPS does not work properly OR you have a '''serial device''' then follow the Configuration Options below as required.
 
If your USB UPS does not work properly OR you have a '''serial device''' then follow the Configuration Options below as required.
   Line 38: Line 51:  
====Serial Connection====
 
====Serial Connection====
   −
<ol></li><li>Find the configuration details for your model of UPS. Refer to:  http://www.networkupstools.org/stable-hcl.html and make note of the driver name and upstype number (if any) in the third column.  
+
<ol><li>Find the configuration details for your model of UPS. Refer to:  http://www.networkupstools.org/stable-hcl.html and make note of the driver name and upstype number (if any) in the third column.  
    
{{Warning box|Always use the serial cable supplied with the UPS.  Standard serial cables won't work with a serial UPS and have been known to cause damage to the UPS. Pay particular attention to any references to cable in in the UPS Model column.}}
 
{{Warning box|Always use the serial cable supplied with the UPS.  Standard serial cables won't work with a serial UPS and have been known to cause damage to the UPS. Pay particular attention to any references to cable in in the UPS Model column.}}
    
</li><li>From the console issue the following commands:
 
</li><li>From the console issue the following commands:
   
  config setprop nut Model <model>  
 
  config setprop nut Model <model>  
 
  config setprop nut Device <device>
 
  config setprop nut Device <device>
Line 72: Line 84:  
Whenever a UPS event occurs Emails are sent to the admin account.
 
Whenever a UPS event occurs Emails are sent to the admin account.
 
</li></ol>
 
</li></ol>
 +
 +
====Configuring as a master====
 +
edit the file /etc/ups/nut.conf, and modify the line
 +
MODE=netserver
 +
 +
Set configuration values:
 +
config setprop nut access private TCPPort 3493
 +
expand-template /etc/ups/upsd.conf
 +
expand-template /etc/rc.d/init.d/masq
 +
systemctl restart masq
 +
systemctl restart nut-server
    
====Configuring as a slave====
 
====Configuring as a slave====
Line 83: Line 106:  
  signal-event post-upgrade
 
  signal-event post-upgrade
 
  signal-event reboot  
 
  signal-event reboot  
 +
 +
or (for SME10):
 +
signal-event e-smith-nutUPS-update
    
Confirm server is communicating with master:
 
Confirm server is communicating with master:
Line 88: Line 114:     
====Connecting multiple UPS's====
 
====Connecting multiple UPS's====
To be added http://bugs.contribs.org/show_bug.cgi?id=629
+
As reference to http://bugs.contribs.org/show_bug.cgi?id=629 and https://bugs.koozali.org/show_bug.cgi?id=626#c2
 +
 
 +
1- you will need to do<syntaxhighlight lang="bash">
 +
mkdir -p /etc/e-smith/templates-custom/ups/ups.conf/
 +
cp /etc/e-smith/templates/ups/ups.conf/UPS /etc/e-smith/templates-custom/ups/ups.conf/UPS2
 +
</syntaxhighlight>then edit content to replace the header to UPS2 and Model and Device to Model2 and Device2
 +
 
 +
 
 +
2- Then you need to do<syntaxhighlight lang="bash">
 +
mkdir -p /etc/e-smith/templates-custom/ups/upsmon.conf/
 +
cp /etc/e-smith/templates/ups/upsmon.conf/MONITOR /etc/e-smith/templates-custom/ups/ups.conf/MONITOR2
 +
</syntaxhighlight>Then edit it to change UPS to UPS2.  Then you set Device2 and Model2.
 +
 
   −
= SME8 =
+
 
 +
3- Repeat the steps 1 and 2 for as many UPS you have, then finish by<syntaxhighlight lang="bash">
 +
signal-event console-save
 +
</syntaxhighlight>
    
===UPS Variables and Commands===
 
===UPS Variables and Commands===
Line 99: Line 140:     
====UPS Administrative Privileges====
 
====UPS Administrative Privileges====
In order to be able to use '''upsrw''' and '''upscmd''' it is necessary to have a suitable additional user defined in the '''upsd.users''' configuration file.  
+
<tabs container>
 +
<tab name="SME 10">
 +
You should check your new password ( AdminPass ) to run '''upsrw''' & '''upscmd'''. Of course, you could change your password for a easier one to use.
 +
 
 +
config show nut
 +
 
 +
To set new admin password in database. The new password would be admin ( change it to suit your need )
   −
In order to create a suitable user we will use SME Servers templating system and configuration database. This is based on an original forum thread[http://forums.contribs.org/index.php?topic=40668.0].
+
config setprop nut AdminPass admin
   −
First we need to create a suitable custom template directory
+
To enabled administrative privileges and run command to ups.
mkdir -p /etc/e-smith/templates-custom/etc/ups/upsd.users
  −
cd /etc/e-smith/templates-custom/etc/ups/upsd.users
     −
Create and edit a new file called 'admin' with the following content:
+
  config setprop nut AdminUser enabled
  {
  −
    # create admin user for upsd to allow setting of
  −
    # UPS parameters via upsrw
  −
  −
    $OUT .= "";
  −
    return unless (($nut{AdminUser} || 'disabled') eq 'enabled');
  −
    return unless (($nut{AdminPass} || <nowiki>''</nowiki>) ne <nowiki>''</nowiki>);
  −
  −
    $OUT .= "\n";
  −
    $OUT .= "      [admin]\n";
  −
    $OUT .= "              password  = $nut{AdminPass}\n";
  −
    if ( ($nut{Master} || 'yes') ne 'no') {
  −
        $OUT .= "              allowfrom = localhost\n";
  −
    } else {
  −
        $OUT .= "              allowfrom = localhost localnet\n";
  −
    }
  −
    $OUT .= "              actions  = set\n";
  −
    $OUT .= "              instcmds  = all\n";
  −
}
     −
Create two new database properties for nut
+
Now, to get '''upsd''' to recognise admin modification for administrative privileges we expand the template and reload the '''upsd''' configuration
config setprop nut AdminUser enabled                (This enables the creation of the user in the template above)
  −
config setprop nut AdminPass admin                  (This sets a password for the admin user. Set to whatever you want)
     −
Now, to get '''upsd''' to recognise the new user with the required administrative privileges we expand the template and reload the '''upsd''' configuration
   
  /sbin/e-smith/expand-template /etc/ups/upsd.users
 
  /sbin/e-smith/expand-template /etc/ups/upsd.users
  /usr/sbin/upsd -c reload
+
  /usr/sbin/upsd -c reload  
   −
{{Note box|To disabled the admin user once you have changed the UPS parameters or issued commands as required, issue the commands
+
{{Note box|To disabled the administrative privileges once you have changed the UPS parameters or issued commands as required, issue the commands
 
  config setprop nut AdminUser disabled
 
  config setprop nut AdminUser disabled
 
  /sbin/e-smith/expand-template /etc/ups/upsd.users
 
  /sbin/e-smith/expand-template /etc/ups/upsd.users
  /usr/sbin/upsd -c reload
+
  /usr/sbin/upsd -c reload  
 
}}
 
}}
   −
==Setting UPS Variables==
+
</tab>
In order to set UPS variables it is necessary to have enabled a user with administrative privileges as above first.
+
<tab name="SME 9">
 
  −
In the examples below, it is assumed your UPS name is '''UPS''', that it is local, that the administrative user is '''admin''' and password '''admin'''. You can verify your UPS name via:
  −
upsc -l
  −
 
  −
To view a complete list of the UPS variables, both informational and modifiable
  −
upsc UPS
  −
 
  −
To determine the modifiable variables for your UPS, their current settings and their available setting values execute the command:
  −
upsrw UPS
  −
 
  −
You can now modify the variables you wish using a command similar to the following (Note the order of the arguments is important, and you may need quotes around the value being set, "20"):
  −
upsrw -s battery.charge.low=20 -u admin -p admin UPS
  −
 
  −
Where the value after '''-s''' should be one of the parameters identified by the '''upsrw ups''' command. You can of course verify your changes using   
  −
upsrw UPS
  −
or
  −
upsc UPS
  −
 
  −
After you are done, clean up by disabling the '''upsd''' administrative user '''admin''':
  −
{{Warning box|Make sure you understand the meaning or the UPS variables and their available setting options. Verify that your changes meet your intended behaviour!}}
  −
 
  −
More information on upsrw can be found at:
  −
 
  −
- Manual page: man upsrw
  −
 
  −
====Issuing UPS Commands====
  −
In order to issue UPS commands it is necessary to have enabled a user with administrative privileges as above first.
  −
 
  −
In the examples below, it is assumed your UPS name is '''UPS''', that it is local, that the administrative user is '''admin''' and password '''admin'''. You can verify your UPS name via:
  −
upsc -l
  −
 
  −
To view a complete list of available commands for your UPS:
  −
upscmd -l UPS
  −
 
  −
You can now issue a command to the UPS with similar to the following:
  −
upscmd -u admin -p admin UPS test.battery.start
  −
 
  −
Where the command '''test.battery.start''' is a valid command for your UPS as previously determined by '''upscmd -l UPS'''. Depending upon the command issued you may get broadcast messages and emails relating to and confirming what the UPS is doing.
  −
 
  −
After you are done, clean up by disabling the '''upsd''' administrative user '''admin''':
  −
{{Warning box|Before issuing any commands verify what they do for your particular UPS via the relevant documentation and ensure that the command meets your intended behavioural requirement!
  −
 
  −
Issuing commands could shutdown your server unexpectedly!}}
  −
 
  −
= SME 9 =
      
{{Warning box|Be sure to have e-smith-nutUPS-2.4.0-9.el6.sme.noarch or higher to carry on with these instructions. If you get a lower version, just follow SME8 instruction.}}  
 
{{Warning box|Be sure to have e-smith-nutUPS-2.4.0-9.el6.sme.noarch or higher to carry on with these instructions. If you get a lower version, just follow SME8 instruction.}}  
Line 205: Line 183:  
  /usr/sbin/upsd -c reload  
 
  /usr/sbin/upsd -c reload  
   −
===UPS Variables and Commands===
  −
In some cases you may wish to modify variables on the actual UPS such as the Low Charge/LOWBATTERY setting. This requires the use of the '''upsrw''' command and UPS administrative privileges.
  −
  −
You may also want to control the UPS directly from the command line by issuing UPS commands. This requires use of the '''upscmd''' command and UPS administrative privileges.
  −
{{Warning box|In general, the UPS data should be left protected and changes to it or issuing of commands well thought out. If you wish to make data changes or issue commands then the administrative privileges can be enabled as below and should then be disabled.}}
     −
====UPS Administrative Privileges====
     −
You should check your new password ( AdminPass ) to run '''upserw''' & '''upscmd'''. Of course, you could change your password for a easier one to use.
+
You should check your new password ( AdminPass ) to run '''upsrw''' & '''upscmd'''. Of course, you could change your password for a easier one to use.
    
  config show nut
 
  config show nut
Line 235: Line 207:  
  /usr/sbin/upsd -c reload  
 
  /usr/sbin/upsd -c reload  
 
}}
 
}}
 +
 +
</tab>
 +
<tab name="SME 8">
 +
In order to be able to use '''upsrw''' and '''upscmd''' it is necessary to have a suitable additional user defined in the '''upsd.users''' configuration file.
 +
 +
In order to create a suitable user we will use SME Servers templating system and configuration database. This is based on an original forum thread[http://forums.contribs.org/index.php?topic=40668.0].
 +
 +
First we need to create a suitable custom template directory
 +
mkdir -p /etc/e-smith/templates-custom/etc/ups/upsd.users
 +
cd /etc/e-smith/templates-custom/etc/ups/upsd.users
 +
 +
Create and edit a new file called 'admin' with the following content:
 +
{
 +
    # create admin user for upsd to allow setting of
 +
    # UPS parameters via upsrw
 +
 +
    $OUT .= "";
 +
    return unless (($nut{AdminUser} || 'disabled') eq 'enabled');
 +
    return unless (($nut{AdminPass} || <nowiki>''</nowiki>) ne <nowiki>''</nowiki>);
 +
 +
    $OUT .= "\n";
 +
    $OUT .= "      [admin]\n";
 +
    $OUT .= "              password  = $nut{AdminPass}\n";
 +
    if ( ($nut{Master} || 'yes') ne 'no') {
 +
        $OUT .= "              allowfrom = localhost\n";
 +
    } else {
 +
        $OUT .= "              allowfrom = localhost localnet\n";
 +
    }
 +
    $OUT .= "              actions  = set\n";
 +
    $OUT .= "              instcmds  = all\n";
 +
}
 +
 +
Create two new database properties for nut
 +
config setprop nut AdminUser enabled                (This enables the creation of the user in the template above)
 +
config setprop nut AdminPass admin                  (This sets a password for the admin user. Set to whatever you want)
 +
 +
Now, to get '''upsd''' to recognise the new user with the required administrative privileges we expand the template and reload the '''upsd''' configuration
 +
/sbin/e-smith/expand-template /etc/ups/upsd.users
 +
/usr/sbin/upsd -c reload
 +
 +
{{Note box|To disabled the admin user once you have changed the UPS parameters or issued commands as required, issue the commands
 +
config setprop nut AdminUser disabled
 +
/sbin/e-smith/expand-template /etc/ups/upsd.users
 +
/usr/sbin/upsd -c reload
 +
}}
 +
</tab>
 +
</tabs>
    
==== UPS access ====
 
==== UPS access ====
   
The access of the ups is controled by database properties. The default propertie is set to localhost and give permission to run '''upsrw''' & '''upscmd''' from localhost only if administrative privileges is set to enabled as above. No slave ups could be connected in this mode. Three choices is available to set access.
 
The access of the ups is controled by database properties. The default propertie is set to localhost and give permission to run '''upsrw''' & '''upscmd''' from localhost only if administrative privileges is set to enabled as above. No slave ups could be connected in this mode. Three choices is available to set access.
   Line 260: Line 278:  
  UPS@localhost or UPS@192.168.1.1 ( ups master IP )
 
  UPS@localhost or UPS@192.168.1.1 ( ups master IP )
 
  slave ups get access with UPS@192.168.1.1 ( ups master IP )
 
  slave ups get access with UPS@192.168.1.1 ( ups master IP )
==Setting UPS Variables==
+
 
 +
 
 +
====Setting UPS Variables====
 
In order to set UPS variables it is necessary to have enabled the administrative privileges as above first and you get the possibility to run command from slave ups if access is set to private as above.
 
In order to set UPS variables it is necessary to have enabled the administrative privileges as above first and you get the possibility to run command from slave ups if access is set to private as above.
   Line 289: Line 309:     
- Manual page: man upsrw
 
- Manual page: man upsrw
 +
 +
=====Changing battery date=====
 +
An example to update you battery date upon changing it. (use your own password)<syntaxhighlight lang="bash">
 +
upsrw -s  battery.mfr.date=2020/08/31 -u admin -p admin UPS
 +
</syntaxhighlight>
    
====Issuing UPS Commands====
 
====Issuing UPS Commands====
Line 307: Line 332:  
Where the command '''test.battery.start''' is a valid command for your UPS as previously determined by '''upscmd -l UPS'''. Depending upon the command issued you may get broadcast messages and emails relating to and confirming what the UPS is doing.
 
Where the command '''test.battery.start''' is a valid command for your UPS as previously determined by '''upscmd -l UPS'''. Depending upon the command issued you may get broadcast messages and emails relating to and confirming what the UPS is doing.
   −
After you are done, clean up by disabling the '''upsc''' administrative privileges:
+
After you are done, clean up by disabling the '''upsc''' administrative privileges.
 
{{Warning box|Before issuing any commands verify what they do for your particular UPS via the relevant documentation and ensure that the command meets your intended behavioural requirement!
 
{{Warning box|Before issuing any commands verify what they do for your particular UPS via the relevant documentation and ensure that the command meets your intended behavioural requirement!
    
Issuing commands could shutdown your server unexpectedly!}}
 
Issuing commands could shutdown your server unexpectedly!}}
  −
<headertabs/>
      
=Scheduling Events=
 
=Scheduling Events=
Line 409: Line 432:  
  cd /etc/e-smith/templates-custom/etc/sudoers
 
  cd /etc/e-smith/templates-custom/etc/sudoers
   −
To preserve the content of the orginal /etc/sudoers file copy that into the custom template directory:
+
To preserve the content of the original /etc/sudoers file copy that into the custom template directory:
 
  cp /etc/sudoers 10sudoers  
 
  cp /etc/sudoers 10sudoers  
   Line 444: Line 467:     
===Download and install===
 
===Download and install===
 +
<tabs container><tab name="For SME 10">
 +
You have to enable the epel repository:
 +
yum install smeserver-extrarepositories-epel -y
 +
 +
then install nut-cgi:
 +
yum install --enablerepo=epel nut-cgi
 +
 +
then configure it the SME way:
 +
Edit file /etc/ups/hosts.conf and add.
 +
mkdir -p /etc/e-smith/templates-custom/etc/ups/hosts.conf
 +
echo 'MONITOR UPS@localhost "local UPS"' >/etc/e-smith/templates-custom/etc/ups/hosts.conf/10localhost
 +
expand-template /etc/ups/hosts.conf
 +
 +
Httpd template
 +
 +
mkdir -p /etc/e-smith/templates-custom/etc/httpd/conf/httpd.conf
 +
cd /etc/e-smith/templates-custom/etc/httpd/conf/httpd.conf
    +
Now edit and create a new file 92nutupscmon with the following content
 +
 +
{
 +
    $OUT = "";
 +
    my $allow = 'all';
 +
    my $pass = '0';
 +
    my $satisfy = 'all';
 +
    my $name = $nut{'Name'} || 'NUT UPS Daemon Monitoring';
 +
    my $PublicAccess = $nut{'PublicAccess'} || "local";
 +
 +
    for ('exit-if-none')
 +
    {
 +
      if ($PublicAccess eq 'none')
 +
          {
 +
            next;
 +
          }
 +
      elsif ($PublicAccess eq 'local')
 +
          {
 +
            $allow  = "ip $localAccess";
 +
            $pass    = 0;
 +
            $satisfy = 'All';
 +
          }
 +
      elsif ($PublicAccess eq 'local-pw')
 +
          {
 +
            $allow  = "ip $localAccess";
 +
            $pass    = 1;
 +
            $satisfy = 'All';
 +
          }
 +
      elsif ($PublicAccess eq 'global')
 +
          {
 +
            $allow  = 'all granted';
 +
            $pass    = 0;
 +
            $satisfy = 'All';
 +
          }
 +
      elsif ($PublicAccess eq 'global-pw')
 +
          {
 +
            $allow  = 'all granted';
 +
            $pass    = 1;
 +
            $satisfy = 'All';
 +
          }
 +
      elsif ($PublicAccess eq 'global-pw-remote')
 +
          {
 +
            $allow  = "ip $localAccess";
 +
            $pass    = 1;
 +
            $satisfy = 'Any';
 +
          }
 +
 
 +
      $OUT .= "#------------------------------------------------------------\n";
 +
      $OUT .= "# nut multimon - $name\n";
 +
      $OUT .= "#------------------------------------------------------------\n";
 +
 +
      {
 +
        if ((exists $nut{'URL'}) && ($nut{'URL'} ne <nowiki>''</nowiki>)) {
 +
          $OUT .= "Alias  /$nut{'URL'}  /var/www/nut-cgi-bin\n";
 +
        } 
 +
      }
 +
 +
      $OUT .= "Alias  /nut  /var/www/nut-cgi-bin\n";
 +
 +
      $OUT .= "\n";
 +
      $OUT .= "<Directory /var/www/nut-cgi-bin>\n";
 +
      $OUT .= "    DirectoryIndex upsstats.cgi\n";
 +
      $OUT .= "    Options +ExecCGI\n";
 +
      $OUT .= "    <Require$satisfy>\n" if ($pass);
 +
      $OUT .= "    Require $allow\n";
 +
      if ($pass)
 +
      {
 +
          $OUT .= "    AuthName $name\n";
 +
          $OUT .= "    AuthType Basic\n";
 +
          $OUT .= "    AuthExternal pwauth\n";
 +
          $OUT .= "    require valid-user\n";
 +
          $OUT .= "    </Require$satisfy>\n";
 +
      }
 +
      $OUT .= "</Directory>\n";
 +
    }
 +
}
 +
 +
Configure databases and expand the template
 +
 +
config setprop nut PublicAccess local
 +
/sbin/e-smith/expand-template /etc/httpd/conf/httpd.conf
 +
 +
{{Note box|The above sets access to the scripts to ''local'' ip addresses only. See the [[Web_Application_RPM#New_DB_settings]] for further info and settings}}
 +
 +
Restart the web server
 +
 +
systemctl restart httpd-e-smith
 +
 +
</tab><tab name="For SME 9  and before">
 
You have to enable the '''[[epel]]''' repositories.
 
You have to enable the '''[[epel]]''' repositories.
 
  yum install --enablerepo=epel nut-cgi  
 
  yum install --enablerepo=epel nut-cgi  
Line 468: Line 597:  
  {
 
  {
 
     $OUT = "";
 
     $OUT = "";
     my $allow = 'all';
+
     my $allow = 'all granted';
 
     my $pass = '0';
 
     my $pass = '0';
     my $satisfy = 'all';
+
     my $satisfy = 'All';
 
     my $name = $nut{'Name'} || 'NUT UPS Daemon Monitoring';
 
     my $name = $nut{'Name'} || 'NUT UPS Daemon Monitoring';
+
 
 
     for ('exit-if-none')
 
     for ('exit-if-none')
 
     {
 
     {
Line 554: Line 683:     
  sv t httpd-e-smith
 
  sv t httpd-e-smith
 +
</tab>
 +
</tabs>
    
===Usage of Nut-cgi Scripts===
 
===Usage of Nut-cgi Scripts===
Line 656: Line 787:     
Nut is a Software well documented, you can find the [http://www.networkupstools.org/docs/user-manual.chunked/index.html TOC here] and with [http://www.networkupstools.org/docs/user-manual.chunked/ar01s02.html an overview]
 
Nut is a Software well documented, you can find the [http://www.networkupstools.org/docs/user-manual.chunked/index.html TOC here] and with [http://www.networkupstools.org/docs/user-manual.chunked/ar01s02.html an overview]
<noinclude>[[Category:Howto]]</noinclude>
+
<noinclude>
<noinclude>[[Category:Administration]]</noinclude>
+
[[Category:Howto]]
 +
</noinclude>
 +
<noinclude>
 +
[[Category:Administration]]
 +
</noinclude>
 +
__FORCETOC__
3,054

edits

Navigation menu