Grafana stopped working

Hey there!

I’ve unplugged my Raspberry PI 3B+ for 3 days because I needed to take it offline for a while. Now I’ve plugged it back in and everything works except for grafana. I can open the Basic UI, the PaperUI and so on but not Grafana. I my opinion I didn’t change anything since last time working (I know that everybody says that).

Any Ideas how to solve this desperation?

Have you checked the log files

  • openhab.log
  • /var/log/syslog

for grafana related error messages ?
Have you trie to restart grafana service ?

I dont know what that is: (found in /var/log/syslog)

Jun 24 09:49:41 openhab influxd[609]: [httpd] 127.0.0.1 - admin [24/Jun/2020:09:49:41 +0200] "POST /write?consistency=one&db=openhab_db&p=%5BREDACTED%5D&precision=n&rp=autogen&u=admin HTTP/1.1" 204 0 "-" "okhttp/2.4.0" 42de30bb-b5ef-11ea-add6-b827eb085de4 57440

Also tryed to restart, that gave me an error and

systemctl status grafana-server.service

gives me:

● grafana-server.service - Grafana instance
   Loaded: loaded (/usr/lib/systemd/system/grafana-server.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Wed 2020-06-24 07:52:09 CEST; 2h 6min ago
     Docs: http://docs.grafana.org
  Process: 738 ExecStart=/usr/sbin/grafana-server --config=${CONF_FILE} --pidfile=${PID_FILE_DIR}/grafana-server.pid --packaging=deb cfg:default.paths.logs=${LOG_DIR} cfg:default.paths.data=${DATA_DIR} cfg:default.paths.plugins=${PLUGINS
 Main PID: 738 (code=exited, status=1/FAILURE)

Jun 24 07:52:09 openhab systemd[1]: grafana-server.service: Service RestartSec=100ms expired, scheduling restart.
Jun 24 07:52:09 openhab systemd[1]: grafana-server.service: Scheduled restart job, restart counter is at 6.
Jun 24 07:52:09 openhab systemd[1]: Stopped Grafana instance.
Jun 24 07:52:09 openhab systemd[1]: grafana-server.service: Start request repeated too quickly.
Jun 24 07:52:09 openhab systemd[1]: grafana-server.service: Failed with result 'exit-code'.
Jun 24 07:52:09 openhab systemd[1]: Failed to start Grafana instance.
lines 1-13/13 (END)

I forgot to mention: The
systemctl restart grafana-server.service
gives me the following error:

==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ===
Authentication is required to restart 'grafana-server.service'.
Authenticating as: root
Password:
polkit-agent-helper-1: pam_authenticate failed: Authentication failure
==== AUTHENTICATION FAILED ===
Failed to restart grafana-server.service: Access denied
See system logs and 'systemctl status grafana-server.service' for details.

i typed “openhabian” as password since this is the root password as default, acording to my Internet-Researches

Errr…

Ok found at least one Error, of a few…

I changed a few days earlier the owner of the openhab2 folder, to get access from network to it. I solved the problem causing me to do that with a other solution, but forgot to reset this ownership. Thats why I got that error message. I tryed with sudo… but that, of course, gave an Error because of the missing sudoers permission. Thats why I’ve tryed without the sudo and that caused this Error message. I fixed this permission thing now, so thats working and I get no error Message executing
systemctl start grafana-server.service

but the Message from systemctl status grafana-server.service is still the same…

I’ve found out another Thing, but can’t really tell what to do with it:

running the Syslog during the start of the grafana-server.service brings up this error message:

Jun 24 14:44:27 openhab grafana-server[3617]: t=2020-06-24T14:44:27+0200 lvl=crit msg="Failed to parse /etc/grafana/grafana.ini, open /etc/grafana/grafana.ini: permission denied"

at beginning the owner of this file was “openhabian” I changed to root and back, but nothing really happend. Is there another userpermission I need to fix?

The user under which Grafana runs (probably grafana) needs to have at least read permission on that file.

  • make sure that you can run system commandos with sudo or change to user root
  • switching ownership of a file to owner root will not help
  • what you could do is to make files readable for all: chmod ugo+r FileNameHere
  • but just changing file permissions not knowing if this will help is not the best approach
  • besides file permissions the user also needs to be able access the directory where the file is located
  • my suggestion would be do a complete system reboot; wait 10 - 20 minutes and run
sudo journalctl -b > /tmp/output.txt
  • this should information about all failing services
  • download the file from your system and provide content of that file

Hey guys thank you all for your help!!

My problem was that many directories had the wrong owner. Because of that the grafana user hadn’t the permission to access its own files. I’ve corrected all the File-ownerships and Permissions, now is all back to life and running like it should.
(to give credit this was the lead to the solution:

but I marked this as solution cause it describes the error for future users)

Hi @Elektrokiste,
I am facing exactly the same problem, since I (clean) installed OH3 and Grafana and Influxdb via Openhabian.
May I ask you how you fixed the File-ownerships and Permissions?
Thank you!

1 Like

Hi,

i got the same problem. @Elektrokiste it would be great if you could share details on your soution.

Thank you.

In directory /var/cache/apt/archives/ you should be able to find a file that contains grafana in it’s name.
Do a

dpkg -c /var/cache/apt/archives/<name of the file here>

this will list all files contained in the deb package also showing the original permissions and ownership of the files and directories.
You can do a manual compare then ( do a ls -ld /< path >/< file > resp. ls -ld /< path > to see the permission and ownership of the files in your filesystem ).
I would suggest to start with directory and content under /etc.

@Wolfgang_S: Thanks for the quick reply. I got a little further. I did check the ownership and permissions of the grafana folders like you suggested. The permissions looked right or the same like in “ls -ld” to me. All the directories were owned by root. So I changed that with “sudo chown grafana: grafana -R /path”. Sadly grafana still won’t start.Is that he right way to correct the ownership?

Ps: Sorry I’m not a Linux expert.

Under /etc/grafana the files should have these ownership:

ls -ld /etc/grafana/ /etc/grafana/grafana.ini 
drwxr-xr-x 2 root root    4096 Dec 17 19:40 /etc/grafana/
-rw-r----- 1 root grafana 7252 May  9  2020 /etc/grafana/grafana.ini

This means the file grafana.ini is owned by user root and belongs to the group grafana.
While the owner is able to ( r )ead and ( w )rite the group is able to ( r )ead the file.
An other thing is

ls -ld /var/lib/grafana/ /var/lib/grafana/* /var/lib/grafana/sessions/*
drwxr-xr-x  3 grafana grafana  4096 May  9  2020 /var/lib/grafana/
-rw-r-----  1 grafana grafana 61440 May  9  2020 /var/lib/grafana/grafana.db
drwxr-x--- 10 grafana grafana  4096 May 26  2020 /var/lib/grafana/sessions
drwxr-x---  4 grafana grafana  4096 Sep 10 17:06 /var/lib/grafana/sessions/1

these files/directories are owned by grafana and also the group is set to grafana.
Same for

ls -ld /var/log/grafana/ /var/log/grafana/*
drwxr-xr-x 2 grafana grafana 20480 Dec 25 14:56 /var/log/grafana/
-rw-r----- 1 grafana grafana    75 Dec 25 14:56 /var/log/grafana/grafana.log

In case you would like to know more about linux file permissions basics are explained here: e.g. Understanding Linux File Permissions - Linux.com

Ok I think I was on the wrong trace. I did a fresh new intall of openhabian with grafana and checked all the files you mentioned. And they were exactly configured like you said they have to be. The funny thing is after installing influx+grafana via openhabian-config grafana works. But if i restart the rpi grafana won’t start up again. I just did the installation of influx+grafana to exclude any side effects of other software installation.

“systemctl status grafana-server.service” gave me the following, but I am not able to read any cause out of it:rafana-server.service - Grafana instance
Loaded: loaded (/lib/systemd/system/grafana-server.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Sat 2020-12-26 13:56:19 CET; 62ms ago
Docs: http://docs.grafana.org
Process: 1734 ExecStart=/usr/sbin/grafana-server --config=${CONF_FILE} --pidfile=${PID_FILE_DIR}/grafana-server.pid –
Main PID: 1734 (code=exited, status=1/FAILURE)

Any hint by running
sudo journalctl | grep grafana

Since I’m having same issues, this it what is shows running

sudo journalctl | grep grafana

result:

[19:53:59] openhabian@openHABianDevice:~$ sudo journalctl | grep grafana
[sudo] password for openhabian:
Dec 26 19:50:28 openHABianDevice **grafana**-server[897]: Failed to start **grafana**. error: failed to create log directory "/var/log/**grafana**": mkdir /var/log/**grafana**: permission denied
Dec 26 19:50:28 openHABianDevice systemd[1]: **grafana**-server.service: Main process exited, code=exited, status=1/FAILURE
Dec 26 19:50:28 openHABianDevice systemd[1]: **grafana**-server.service: Failed with result 'exit-code'.
Dec 26 19:50:28 openHABianDevice systemd[1]: **grafana**-server.service: Service RestartSec=100ms expired, scheduling restart.
Dec 26 19:50:28 openHABianDevice systemd[1]: **grafana**-server.service: Scheduled restart job, restart counter is at 1.
Dec 26 19:50:29 openHABianDevice **grafana**-server[1004]: Failed to start **grafana**. error: failed to create log directory "/var/log/**grafana**": mkdir /var/log/**grafana**: permission denied
Dec 26 19:50:29 openHABianDevice systemd[1]: **grafana**-server.service: Main process exited, code=exited, status=1/FAILURE
Dec 26 19:50:29 openHABianDevice systemd[1]: **grafana**-server.service: Failed with result 'exit-code'.
Dec 26 19:50:29 openHABianDevice systemd[1]: **grafana**-server.service: Service RestartSec=100ms expired, scheduling restart.
Dec 26 19:50:29 openHABianDevice systemd[1]: **grafana**-server.service: Scheduled restart job, restart counter is at 2.
Dec 26 19:50:29 openHABianDevice **grafana**-server[1026]: Failed to start **grafana**. error: failed to create log directory "/var/log/**grafana**": mkdir /var/log/**grafana**: permission denied
Dec 26 19:50:29 openHABianDevice systemd[1]: **grafana**-server.service: Main process exited, code=exited, status=1/FAILURE
Dec 26 19:50:29 openHABianDevice systemd[1]: **grafana**-server.service: Failed with result 'exit-code'.
Dec 26 19:50:29 openHABianDevice systemd[1]: **grafana**-server.service: Service RestartSec=100ms expired, scheduling restart.
Dec 26 19:50:29 openHABianDevice systemd[1]: **grafana**-server.service: Scheduled restart job, restart counter is at 3.
Dec 26 19:50:29 openHABianDevice **grafana**-server[1052]: Failed to start **grafana**. error: failed to create log directory "/var/log/**grafana**": mkdir /var/log/**grafana**: permission denied
Dec 26 19:50:29 openHABianDevice systemd[1]: **grafana**-server.service: Main process exited, code=exited, status=1/FAILURE
Dec 26 19:50:29 openHABianDevice systemd[1]: **grafana**-server.service: Failed with result 'exit-code'.
Dec 26 19:50:30 openHABianDevice systemd[1]: **grafana**-server.service: Service RestartSec=100ms expired, scheduling restart.
Dec 26 19:50:30 openHABianDevice systemd[1]: **grafana**-server.service: Scheduled restart job, restart counter is at 4.
Dec 26 19:50:30 openHABianDevice **grafana**-server[1071]: Failed to start **grafana**. error: failed to create log directory "/var/log/**grafana**": mkdir /var/log/**grafana**: permission denied
Dec 26 19:50:30 openHABianDevice systemd[1]: **grafana**-server.service: Main process exited, code=exited, status=1/FAILURE
Dec 26 19:50:30 openHABianDevice systemd[1]: **grafana**-server.service: Failed with result 'exit-code'.
Dec 26 19:50:30 openHABianDevice systemd[1]: **grafana**-server.service: Service RestartSec=100ms expired, scheduling restart.
Dec 26 19:50:30 openHABianDevice systemd[1]: **grafana**-server.service: Scheduled restart job, restart counter is at 5.
Dec 26 19:50:30 openHABianDevice systemd[1]: **grafana**-server.service: Start request repeated too quickly.
Dec 26 19:50:30 openHABianDevice systemd[1]: **grafana**-server.service: Failed with result 'exit-code'.

running the folder permission it seems it’s just reading rights for others than admin, correct?

> [19:54:04] openhabian@openHABianDevice:~$ ls -ld /var/log
> drwxr-xr-x 1 root root 4096 Dec 26 19:50 /var/log

/var/log/grafana is normally being created during the installation by user root.
Thus the permissions for directory /var/log are correct.
I do not know if this cold be a probelm with zram but I would try to create the directory e.g.

sudo mkdir /var/log/grafana; sudo chown grafana:grafana /var/log/grafana

solved for me with following:

  1. Grafana folder manual generated

[20:03:01] openhabian@openHABianDevice:~$ sudo su
[20:03:07] root@openHABianDevice:/home/openhabian# mkdir /var/log/grafana

  1. full rights granted

[20:03:27] openhabian@openHABianDevice:~$ sudo chmod -R 777 /var/log/grafana
[20:10:51] openhabian@openHABianDevice:~$ ls -ld /var/log/grafana
drwxrwxrwx 2 root root 4096 Dec 26 20:03 /var/log/grafana

  1. restart Grafana
    [20:11:18] openhabian@openHABianDevice:~$ sudo service grafana-server restart

…and than Grafana frontend (ip:3000) work again

1 Like

that is working but not in the intention of the developer of Unix/Linux permissions :slight_smile:
have a look at my posting before yours.