-
Notifications
You must be signed in to change notification settings - Fork 11.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug] PID_FILE not set and not created #9133
Comments
It seems when this option is set, grafana server does not start. Interestingly without any error message in the grafana.log |
As you said, looks like the PID_FILE variable is not set here: https://github.com/grafana/grafana/blob/master/packaging/rpm/sysconfig/grafana-server Does it work if you use this instead:
Anyway, looks like a bug. |
No, it does not work. Even if i touch the pid file before I start. Interesting at this point is the way the arguments are passed to the grafana-server. The systemd unit file lists this:
The help output shows this:
(notice the help screen "-pidfile" while the unit file passes "--pidfile". I tried adopting the unitfile for this but the behaviour did not change at all) |
I was digging deeper. The problem is actually quite simple. But as the whole Grafana is deployed via rpm, the related installation procedure in the pre- and post-script section needs to be extended by just a a few lines. (I just don't know where the rpm spec file can be found) What is the problem? 2.) The root cause (really could be easier found with some error messages) is a plain simple permission problem caused by the strange behavior of starting the daemon. The init-script used in non-systemd versions, creates the pid file before the daemon is started with the privileges of the init-script (root usually) and changes its ownership to the user/group configured to start the daemon.
Now with CentOS/RHEL 7 systemd is starting the grafana-server with reduced priviledges. This causes the gravana-server to fail while trying to create the pid file under (for example /var/run/). ==> Again, this forensic search for the root cause would have been way faster with a error message from grafana-server. grafana/packaging/rpm/systemd/grafana-server.service Lines 10 to 11 in 40ae2ce
How to fix it?
If this procedure is applied manually, the grafana-server starts properly with a pid file as the directory the pid file should be created in is owned by the daemons user which allows the creation of files. I am not familiar with the packaging process used here but I guess the related lines should be added around this line ... grafana/packaging/rpm/control/postinst Line 47 in 40ae2ce
To activate this only on systemd machines, a simple check like it is done a little further down would be enough.
I assume the same needs to be done for the deb packages as they use systemd as well in resent releases. If my assumptions about the fix are correct I would be happy to submit a pull request if you want. |
Thanks for digging deeper into this. The issue with no log output when shutting down is strange, have never seen that not seen it reported, always reported via grafana log when shutting down |
Well, when grafana-server is shut down, there are a few log messages usually. It seems as if it is just in this special case where he cannot create the pidfile. If I would need to guess, I would think grafana-server is trying to create the pid before any log or output was generated and dies without an error massage at that point. It's less of an issue that the logfile does not show any error. The biggest issue is the missing output of the dieing process (stdout/stderr). If there would have been one, systemd would have wrote it to the journal. Or you would see it while trying to start the daemon manually. |
oh, that is probably it, it dies before any logging is setup. There are some logging calls if pid directory does not exist or pid file creation fails but because the logging is not configured at that point it probably goes nowhere |
Before it goes nowhere, stderr would be a nice place to dump those messages. :) |
I hope I fixed the pid issue (and improved the logging) in c3cffeb introduce a PID_FILE_DIR env variable that is used on systemd systems (post install script creates the dir and sets the permission, the systemd service spec uses it to set --pidfile argument). This way there is no change for non systemd systems. |
Hi, I am really sorry but I was digging deeper into the complete issue and realized something else. On CentOS7, per default the /var/run/ is a link to /run which is a tempfs and therefore all files and directories will not survive a reboot. That means the changes in the "postinst" scripts will not have any effect until the server was rebooted. The changes to create the /var/run/grafana/ directory needs to be added to the systemd unit file. As the grafana-server is already started by systemd with droped priiviledges, the directory needs to be created before the start from systemd. I found the following possibility. This will instruct systemd to start the daemon with the user and group. grafana/packaging/deb/systemd/grafana-server.service Lines 8 to 20 in 4eabf6c
When changed according to this example, systemd will execute the two commands (as root) before starting the daemon. That should ensure the rights to create the var/run/grafana/ directory before the daemon is started.
Together with the new introduced variable for the PID directory, that should work. |
Maybe we can use
? |
Seems to work on ubuntu 16 atleast, and is the approach elasticsearch is using |
And where should this runtime directory be?? It reads like a relative path. But from where?? |
https://blog.hqcodeshop.fi/archives/93-Handling-varrun-with-systemd.html There is even the possibility to specify the PIDFile variable for systemd. Depending on the behaviour of the daemon, this might make sense. See details here: https://lists.debian.org/debian-user/2016/10/msg00422.html |
Thanks @torkelo, I did some reading on what you suggested. It seems this setting is exactly the option ment to do what we need. See detailed description of the setting here. At first I did not know where the directory would be created. But it seems the name is relative to the /run/ directory. https://www.freedesktop.org/software/systemd/man/systemd.exec.html#RuntimeDirectory= So a directive like the following would do the trick.
Thanks a lot @torkelo |
imports a fix that sets a PID_FILE_DIR variable in /etc/defaults/grafana-server see grafana/grafana#9133 see grafana/grafana@c3cffeb#diff-ad598638c92a28d5d7ffdaba305d92b2
What did you do?
I tried to setup monitoring for the grafana-server. To do this I was looking for the pid file.
What was the expected result?
I expected to find a pid file in the configured path or at "/var/run/...".
What happened instead?
There was no pid file found on the system.
Detailed Description
Grafana was installed using yum/rpm from the grafana repository. The system is started/stopped via systemd (systemctl command). According to the systemd unit file, the pidfile is set from a variable which is loaded from "/etc/sysconfig/grafana-server".
The referenced file does not even contain the variable "PID_FILE" nor does it set a value.
A search through the documentation for the grafana.ini did not reveal any possibility to configure the pidfile.
The workaround is the same as the solution. The config file /etc/sysconfig/grafana-server should include the PID_FILE variable and set it to a default location like this.
This setting would have been expected to be in the file deployed via the rpm.
The text was updated successfully, but these errors were encountered: