Community
OpenEnergyMonitor

Community

EmonHub log systemd

emonhub
Tags: #<Tag:0x00007f8816e0e610>
(Brian Orpin) #1

Continuing the discussion from KwH per day:

There have been several reports that the EmonHub log seems to have gone AWOL (within the emonhub page) on 9.9.6.

You can get it via journalctl

@TrystanLea, @glyn.hudson could you suggest what has happened to it?

1 Like
9.9.7 version – Emonhub.conf Log has disappeared …
(Trystan Lea) #2

I can confirm it is not present. I will look into it.

journalctl -f -u emonhub -n 1000

does work for those needing it in the meantime

1 Like
(Trystan Lea) #3

It looks like this is as a result of moving from /etc/init.d/ service to the systemd service.
I have tried adding a standard output definition but cant seem the get it to log:

StandardOutput=file:/var/log/emonhub.log

Any ideas? @Greebo

(Trystan Lea) #4

We are considering here accessing the log directly from the system log rather than having an emonhub.log

(Brian Orpin) #5

Should possibly be append: (https://www.freedesktop.org/software/systemd/man/systemd.exec.html) but only available from systemd 236 or newer apparently (https://stackoverflow.com/questions/37585758/how-to-redirect-output-of-systemd-service-to-a-file)

An alternative might be to use rsyslog so it is available via journal and via a file - this answer as well. (https://stackoverflow.com/questions/37585758/how-to-redirect-output-of-systemd-service-to-a-file/43830129#43830129)

1 Like
(Trystan Lea) #6

We’ve got it to work with journalctl. www-data needs to be added to the systemd-journal group:

usermod -a -G systemd-journal www-data

and then the getemonhublog route https://github.com/emoncms/config/blob/master/config_controller.php#L36 changed to:

if ($route->action == 'getemonhublog') {
    $route->format = "text";
    ob_start();
    passthru("journalctl -u emonhub -n 30 --no-pager");
    return trim(ob_get_clean());
}

we are putting this together into an update now.

1 Like
(Brian Orpin) #7

The only downside to this, is that it will be more difficult to extract errors further back or over a longer period.

(Glyn Hudson) #8

The changes to emoncms/config mentioned by @TrystanLea are now committed in the stable branch of this module.

However I’m having an issue adding www-data to the systemd-journal via the update scripts.

Executing in a shell

sudo usermod -a -G systemd-journal www-data

works fine but when it’s in the emonhub update script it does’t seem to work, just failes with no error. I think this could be a permission issue, however all other sudo commands e.g sudo apt-get update work fine via the script. Any ideas?

We have also fixed the emonHub restart button to restart the systemd service.

The only thing remaining (apart from fixing the group add issue mentioned above) is to fix the emonHub log Download button. This is currently broken. I propose when a user clicks the download button the journal log is saved to a tmp file which is then downloaded via the browser e.g

journalctl -u emonhub --no-pager > ~/tmp/emonhub.log
rm /tmp/emonhub.log
(Brian Orpin) #9

Have you tried a reboot? https://unix.stackexchange.com/questions/277240/usermod-a-g-group-user-not-work

(Greebo) #10

@borpin nailed it… needs a newer version of systemd… I ran into the same issue with the service-runner unit file trying to log to its own log file. (I was sure I’d posted about it somewhere either here or in the discussions about the service-runner PR but I can’t find it now!)

[EDIT]
Debian stretch includes v232, buster includes v240… so the StandardOutput feature will become available when we switch to buster (or later) ref

The stretch-backports version is v239, so that would also provide the feature without having to upgrade from stretch. This may be most appropriate for the emonSD image?

1 Like
(Glyn Hudson) #11

A reboot is not required, just a restart of apache2 is fine to apply the group changes. The issue I’m having is I can run the usermod command via sudo in a shell window no problem. However, to be able to roll this out to all emonPi users we need to be able to do it via the emonpi update script. For some reason (I’m not sure why) usemode command does not seem to do anything when ran from a script. Maybe it’s a permission issue? But as I mentioned other sudo commands work fine from the update script.

(Brian Orpin) #12

There are some comments on those links suggesting that you need to log out/login to make the change stick. I wondered if a reboot might do the same.

I think it is to do with a vagary around the user running the script.

Could the command be run as a different user?

(Glyn Hudson) #13

Ok, this issue has now been fixed. If a users runs emonPi update the emonhub log should start working again. Please let me know if it does. It may require a reboot for changes to take effect.

emonSD: emonhub log missing?
(Brian Orpin) #14

You’ve got to tell me how!

(Glyn Hudson) #15

Most of the changes are in this commit

passthru("journalctl -u emonhub -n 30 --no-pager");

We just needed to add the www-data users to the systemd-journal group to allow it to read, this has been added to emonPi update and the emonhub config module readme

sudo usermod -a -G systemd-journal www-data

We still need to fix the log download button.

1 Like
Cannot download emonhub logs
9.9.7 version – Emonhub.conf Log has disappeared …
(Brian Orpin) #16

@TrystanLea @glyn.hudson I have just submitted a PR to fix the emonhub log download issue. Just used your same passthru solution without the number :smile:

1 Like
(Trystan Lea) #17

Thanks @borpin, merged

1 Like