Changes

From SME Server
Jump to navigationJump to search
Altered UPS Parameters section to UPS Variables and Commands with templated and database creation of upsd admin user
Line 11: Line 11:  
  status = disabled
 
  status = disabled
 
  type = service
 
  type = service
{Note box|Absence of a 'Master' property setting defaults the configuration to being a Master setup. That is a UPS connected directly to the server via USB or serial cable is assumed. See later for setting as a Slave.
+
{{Note box|Absence of a 'Master' property setting defaults the configuration to being a Master setup. That is a UPS connected directly to the server via USB or serial cable is assumed. See later for setting as a Slave.
   −
The default is for nut to be disabled, that is no UPS connected}
+
The default is for nut to be disabled, that is no UPS connected}}
    
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:
Line 86: Line 86:  
To be added http://bugs.contribs.org/show_bug.cgi?id=629
 
To be added http://bugs.contribs.org/show_bug.cgi?id=629
   −
==Modifying UPS Parameters==
+
==UPS Variables and Commands==
In some cases you may wish to modify parameters on the actual UPS such as the Low Charge/LOWBATTERY setting. This requires the use of the '''upsrw''' command and temporary modifications to the '''upsd.users''' configuration file. In general, the UPS data should be left protected and changes thought out. If you wish to make the administrative privileges more permanent, then you can make custom templates as identified in the section "Additional Information".
+
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.
   −
In the examples below, it is assumed your UPS name is '''ups''' and that the UPS is local. you can verify the UPS name via:
+
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.
  upsc -l
+
{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===
 +
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.
 +
 
 +
First we need to create a suitable template fragment
 +
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'
 +
{
 +
    # 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} || '') ne '');
 +
 +
    $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)
   −
To determine the modifiable parameters for your UPS execute the command:
+
Now, to get '''upsd''' to recognise the new user with the required administrative privileges we expand the template and reload the '''upsd''' configuration
  upsrw ups
+
  /sbin/e-smith/expand-template /etc/ups/upsd.users
 +
/usr/sbin/upsd -c reload
   −
next we need to create a temporary user with privileges to modify these parameters. First make a safe copy of /etc/ups/upsd.users
+
{{Note box|To disabled the admin user once you have changed the UPS parameters or issued commands as required, issue the commands
cp /etc/ups/upsd.users /etc/ups/upsd.users.backup
+
config setprop nut AdminUser disabled
 +
/sbin/e-smith/expand-template /etc/ups/upsd.users
 +
/usr/sbin/upsd -c reload
 +
}}
   −
Modify /etc/ups/upsd.users and add the user "admin" or anything else you prefer. The entry should look like the other entries and be something like:
+
===Setting UPS Variables===
      [admin]
+
In order to set UPS variables it is necessary to have enabled a user with administrative privileges as above first.
              password = admin
  −
              allowfrom = localhost
  −
              actions = set
     −
Now reload the config files:
+
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:
  upsd -c reload
+
  upsc -l
   −
You can now modify the parameters you wish using a command similar to:
+
To view a complete list of the UPS variables
  upsrw -s battery.charge.low=20 -u admin -p admin ups
+
  upsc UPS
   −
Where the value after '''-s''' should be one of the parameters identified by the '''upsrw ups''' command and where "-u admin -p admin" is the username and password set above and '''ups''' is the name of your ups. You can of course verify your changes using '''upsrw ups''' or '''upsc ups'''.
+
To determine the modifiable variables for your UPS execute the command:
 +
upsrw UPS
   −
After you are done, clean up:
+
You can now modify the variables you wish using a command similar to:
  mv /etc/ups/upsd.users.backup /etc/ups/upsd.users
+
  upsrw -s battery.charge.low=20 -u admin -p admin UPS
upsd -c reload
     −
And don't forget to verify that your changes meet your intended behaviour!
+
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|Verify that your changes meet your intended behaviour!}}
    
More information on upsrw can be found at:
 
More information on upsrw can be found at:
Line 122: Line 164:  
- Manual page: man upsrw
 
- Manual page: man upsrw
   −
- Upsrw examples: http://opensource.mgeups.com/howto.htm
+
- Upsrw examples: [http://opensource.mgeups.com/howto.htm]
 
  −
- Templating example: http://forums.contribs.org/index.php?topic=40668.0
      
==Modifying shutdown time delay==
 
==Modifying shutdown time delay==

Navigation menu