# NUT -> upslog not working?

## Cyker

Does anyone here use NUT?

I have been using it for some time and it's working fine; I have two UPS' connected over the network and am getting stats from them etc.

I wanted to start logging the telemetry so I can make some pretty graphs of the voltage fluctuations etc, but have gotten a bit stuck with the upslog program.

I can get it to work if I run it manually with the right params, but if I run it via. init.d, I get:

```

# /etc/init.d/upslog start

 * Starting upslog ...

 * start-stop-daemon: failed to start `/usr/bin/upslog'                   [ !! ]

 * ERROR: upslog failed to start

```

I suspect this is because it isn't set up, but I can't find a config file - There seems to be no documentation other than a single manpage entry for upslog, which mentions no config files, nor is there anything in /etc/conf.d or /etc/nut that look like it might be relevant.

Right now I'm thinking I should just kludge the /etc/init.d/upslog with the same command line that works when I run it manually; Just wanted a second opinion from someone in case I'm just being stupid.

What say ye??

----------

## bbgermany

Hi,

did you try to run "upslog" directly in your console and check for errors? Since I dont have an UPS running atm, I only get the following:

```

$ upslog

Network UPS Tools upslog 2.7.3

No UPS defined for monitoring - use -s <system>

$

```

greets, bb

----------

## boozo

Hi,

(Errf! thanks for the reminder... I should have done a report on b.g.o or an howto more than a year   :Embarassed:  )

If I remember right, the problem come from ups{log,mon} init script (and/or their config files)

so maybe compare with mine ?   :Smile: 

/etc/init.d/upslog

```
#!/sbin/runscript

# Copyright 1999-2013 Gentoo Foundation

# Distributed under the terms of the GNU General Public License v2

# $Header: /var/cvsroot/gentoo-x86/sys-power/nut/files/nut-2.6.5-init.d-upslog,v 1.1 2013/08/12 18:35:12 robbat2 Exp $

extra_started_commands="reload"

depend() {

   use upsdrv

   after upsdrv

}

checkconfig() {

   if [ ! -f /etc/conf.d/upslog ] ; then

      eerror "Please create /etc/conf.d/upslog file"

      return 1

   fi

   return 0

}

start() {

   checkconfig || return $?

   ebegin "Starting upslog"

   start-stop-daemon --start --exec /usr/bin/upslog \

      --pidfile /var/run/upslog.pid \

      -- -p /var/run/upslog.pid ${UPSLOG_OPTS}

   eend $? "Failed to start upslog"

}

 

stop() {

   ebegin "Stopping upslog"

   start-stop-daemon --stop --quiet --pidfile /var/run/upslog.pid \

      --exec /usr/bin/upslog

   eend $? "Failed to stop upslog"

}

reload() {

   ebegin "Reloading upslog"

   start-stop-daemon --stop --signal HUP --oknodo --quiet \

      --pidfile /var/run/upslog.pid

   eend $?

}
```

/etc/init.d/upsmon

```
#!/sbin/runscript

# Copyright 1999-2013 Gentoo Foundation

# Distributed under the terms of the GNU General Public License v2

# $Id$

extra_started_commands="reload"

pidfile=/var/run/upsmon.pid

bin=/usr/sbin/upsmon

depend() {

   use net

}

start() {

   ebegin "Starting upsmon"

   start-stop-daemon --start --quiet --exec ${bin}

   eend $?

}

stop() {

   ebegin "Stopping upsmon"

   start-stop-daemon --stop --quiet --pidfile ${pidfile}

   eend $?

}

reload() {

   ebegin "Reloading upsmon"

   start-stop-daemon --stop --signal HUP --oknodo --quiet --pidfile ${pidfile}

   eend $?

}
```

/etc/conf.d/upslog

```
UPSLOG_OPTS="-s eaton800@<hostname> -u <nut_username> -i 60 -l /var/log/upslog_eaton800.log"
```

# rc-update

```
(snip)

               upsd   |      default                 

               upsdrv |      default                 

               upslog |      default                 

               upsmon |      default   

(snip)      
```

---- ps: I'm so sorry for my bad english ----

---- ps2: If this help, feel free to report it on b.g.o ----

Aside, an example from an Eaton EllipseEco 800 and a Nut server in standalone mode with ssl activated - I have a special user for nut and "Eaton800" is the ups name - 

 *package.use (extract) wrote:*   

> sys-power/nut -* ups_drivers_usbhid-ups ssl tcpd usb xml

 

 */var/log/messages (extract) wrote:*   

> usbhid-ups[1868]: Startup successful
> 
> upsd[1892]: listening on ::1 port 3493
> 
> upsd[1892]: listening on <hostname> port 3493
> ...

 

```
$ ls -al /etc/nut/

total 60

drwxr-xr-x  3 root root   119  9 sept. 20:13 .

drwxr-xr-x 82 root root  8192 30 nov.  18:58 ..

drwxr-xr-x  2 root root    38 30 oct.   2014 certs

-rw-r--r--  1 root root  1544 28 oct.   2014 nut.conf

-rw-r--r--  1 root root  4878  9 sept. 20:09 ups.conf

-rw-r-----  1 root nut   4693 30 oct.   2014 upsd.conf

-rw-r-----  1 root nut   2413 30 oct.   2014 upsd.users

-rw-r-----  1 root nut  15365  9 sept. 20:12 upsmon.conf

-rw-r--r--  1 root root  4569 30 oct.   2014 upssched.conf
```

 */etc/nut/upsd.conf  wrote:*   

> MAXAGE 15
> 
> STATEPATH /var/lib/nut
> 
> LISTEN <hostname> 3493
> ...

 

 */etc/nut/upsd.users wrote:*   

>  [nut]
> 
> 	password = <your_passwd>
> 
> 	actions = SET
> ...

 

 * /etc/nut/upsmon.conf  wrote:*   

> RUN_AS_USER <nut_username>
> 
> MONITOR eaton800@<host_name> 1 <nut_username> <nut_username_passwd> master
> 
> MINSUPPLIES 1
> ...

 

n.b.: Cherry on the pudding: my tiny notes if you really want to activate SSL for monitor

```
### Generate Openssl CRT and KEY server

$ openssl req -new -x509 -nodes -days 365 -out upsd.crt -keyout upsd.key

// n.b. Verifying : $ openssl x509 -enddate -noout -in <file>

### Use the following command to determine the hash of the certificate 8 hex characters (i.e. 8 hex characters)

$ openssl x509 -hash -noout -in upsd.crt

### Install the client-side certificate

# mkdir /etc/nut/certs

# chmod 0750 /etc/nut/certs

# cp upsd.crt /etc/nut/certs/<hex_hash_cert>.0

// n.b. If necessary : increment last file number (.0->.1->.2-> ...) until you get a unique filename that works

### Create the combined file for upsd

# cat upsd.crt upsd.key > upsd.pem

# chown root:nut upsd.pem

# chmod 0640 upsd.pem

### Install the server-side certificate

# mv upsd.pem /etc/nut/certs/upsd.pem

//Edit upsd.conf and specify $CERTFILE /path/to/upsd.pem

//n.b. Verifying the rights on directories and files

### Clean up the temporary files

# rm upsd.crt upsd.key
```

Edit: typos, bbcode, and forgot a conf. file...

----------

## Cyker

 *bbgermany wrote:*   

> Hi,
> 
> did you try to run "upslog" directly in your console and check for errors? Since I dont have an UPS running atm, I only get the following:
> 
> ```
> ...

 

Thanks  :Smile: 

This is normal as, even if you have your UPS set up, you need to specify all the info about it to upslog as it doesn't seem to take a config file?

My problem is I can't see a way of providing this info to the init.d launch one, short of editing the init.d/upslog script, which is a nasty hacky way of doing things, and will probably get nuked by portage next time it updates NUT :S

----------

## Cyker

 *boozo wrote:*   

> Hi,
> 
> (Errf! thanks for the reminder... I should have done a report on b.g.o or an howto more than a year   )
> 
> If I remember right, the problem come from ups{log,mon} init script (and/or their config files)
> ...

 

Ah, yes! Your init.d/upslog is very different to mine - The checkconfig section is missing completely and the start section is different and missing all the params in my one!

I've copied your one over mine - This is a much more elegant way of feeding it the configs  :Smile: 

Thanks so much!  :Very Happy: 

For comparison, mine looked like this:

```
#!/sbin/runscript

# Copyright 1999-2013 Gentoo Foundation

# Distributed under the terms of the GNU General Public License v2

# $Header: /var/cvsroot/gentoo-x86/sys-power/nut/files/nut-2.6.5-init.d-upslog,v 1.1 2013/08/12 18:35:12 robbat2 Exp $

extra_started_commands="reload"

pidfile=/var/run/upslog.pid

bin=/usr/bin/upslog

depend() {

   use upsdrv

   after upsdrv

}

checkconfig() {

   if [ ! -f /etc/conf.d/upslog ] ; then

      eerror "Please create /etc/conf.d/upslog file"

      return 1

   fi

   return 0

}

start() {

   ebegin "Starting upslog"

   start-stop-daemon --start --quiet --exec ${bin}

   eend $?

}

stop() {

   ebegin "Stopping upslog"

   start-stop-daemon --stop --quiet --pidfile ${pidfile}

   eend $?

}

reload() {

   ebegin "Reloading upslog"

   start-stop-daemon --stop --signal HUP --oknodo --quiet --pidfile ${pidfile}

   eend $?

}

```

There is one fly in the ointment tho' - I have two UPS that I wish to monitor but the way init.d/upslog is set up it'll only let me monitor one.

I'm not sure what the best solution is here; The more elegant way might be rejigging the init.d to launch multiple processes based on entries in the conf.d/upslog.

The quick and dirty way tho' is to copy it to upslog2 and tweak that to use a different PID and conf file  :Smile: 

For now I'm playing with the format string as despite both UPS being made by APC they seem to spit out very different sets of data!

----------

## Anon-E-moose

You can start the upslog program yourself, you don't need to use /etc/init.d/upslog.

That way you can monitor different ups

----------

## boozo

What ? a fly problem too ?   :Laughing: 

For sure, an oneliner or a simple loop in script can do the job (i.e. create slaved users and parse a config file with all the $MONITOR ...)

I don't have a better way at the moment but anyway have a look here (see from 6.4 paragraph to 6.5 -> Typical setups for big servers with UPS redundancy) for working with more than 1 ups.

I'll have do some search about "upslog-ing" this use case. I'll post here if I find something interesting   :Wink: 

----------

## Cyker

@Boozo - Yeah, the upsmon is quite flexible for multiple and layered UPS setups; By comparison upslog fees like it was added as an afterthought as the documentation for it is very thin on the ground.

@Moosey - That's what I'm doing at the moment!!  :Laughing: 

----------

