{"action":"created","issue":{"url":"https://api.github.com/repos/grafana/grafana/issues/9133","repository_url":"https://api.github.com/repos/grafana/grafana","labels_url":"https://api.github.com/repos/grafana/grafana/issues/9133/labels{/name}","comments_url":"https://api.github.com/repos/grafana/grafana/issues/9133/comments","events_url":"https://api.github.com/repos/grafana/grafana/issues/9133/events","html_url":"https://github.com/grafana/grafana/issues/9133","id":254263899,"number":9133,"title":"[Bug] PID_FILE not set and not created ","user":{"login":"gerhard-tinned","id":1536065,"avatar_url":"https://avatars0.githubusercontent.com/u/1536065?v=4","gravatar_id":"","url":"https://api.github.com/users/gerhard-tinned","html_url":"https://github.com/gerhard-tinned","followers_url":"https://api.github.com/users/gerhard-tinned/followers","following_url":"https://api.github.com/users/gerhard-tinned/following{/other_user}","gists_url":"https://api.github.com/users/gerhard-tinned/gists{/gist_id}","starred_url":"https://api.github.com/users/gerhard-tinned/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gerhard-tinned/subscriptions","organizations_url":"https://api.github.com/users/gerhard-tinned/orgs","repos_url":"https://api.github.com/users/gerhard-tinned/repos","events_url":"https://api.github.com/users/gerhard-tinned/events{/privacy}","received_events_url":"https://api.github.com/users/gerhard-tinned/received_events","type":"User","site_admin":false},"labels":[{"id":70176318,"url":"https://api.github.com/repos/grafana/grafana/labels/type:%20bug","name":"type: bug","color":"dddddd","default":false},{"id":258111638,"url":"https://api.github.com/repos/grafana/grafana/labels/type:%20build%20&%20packaging","name":"type: build & packaging","color":"dddddd","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/grafana/grafana/milestones/64","html_url":"https://github.com/grafana/grafana/milestone/64","labels_url":"https://api.github.com/repos/grafana/grafana/milestones/64/labels","id":2685826,"number":64,"title":"4.4.4","description":"","creator":{"login":"daniellee","id":434655,"avatar_url":"https://avatars3.githubusercontent.com/u/434655?v=4","gravatar_id":"","url":"https://api.github.com/users/daniellee","html_url":"https://github.com/daniellee","followers_url":"https://api.github.com/users/daniellee/followers","following_url":"https://api.github.com/users/daniellee/following{/other_user}","gists_url":"https://api.github.com/users/daniellee/gists{/gist_id}","starred_url":"https://api.github.com/users/daniellee/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/daniellee/subscriptions","organizations_url":"https://api.github.com/users/daniellee/orgs","repos_url":"https://api.github.com/users/daniellee/repos","events_url":"https://api.github.com/users/daniellee/events{/privacy}","received_events_url":"https://api.github.com/users/daniellee/received_events","type":"User","site_admin":false},"open_issues":1,"closed_issues":8,"state":"open","created_at":"2017-08-07T15:17:53Z","updated_at":"2017-08-31T09:57:09Z","due_on":null,"closed_at":null},"comments":3,"created_at":"2017-08-31T09:00:07Z","updated_at":"2017-08-31T17:30:45Z","closed_at":null,"author_association":"NONE","body":"- What Grafana version are you using?\r\n```\r\nInstalled Packages\r\nName        : grafana\r\nArch        : x86_64\r\nVersion     : 4.4.3\r\nRelease     : 1\r\n \r\nvia yum repository at baseurl https://packagecloud.io/grafana/stable/el/7/$basearch\r\n```\r\n\r\n- What OS are you running grafana on?\r\n```\r\nCentOS Linux release 7.3.1611 (Core) \r\n```\r\n\r\n- What did you do?\r\nI tried to setup monitoring for the grafana-server. To do this I was looking for the pid file.\r\n\r\n- What was the expected result?\r\nI expected to find a pid file in the configured path or at \"/var/run/...\".\r\n\r\n- What happened instead?\r\nThere was no pid file found on the system.\r\n \r\n- Detailed Description\r\n\r\nGrafana 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\".\r\n\r\n```\r\n[Service]\r\nEnvironmentFile=/etc/sysconfig/grafana-server\r\nUser=grafana\r\nGroup=grafana\r\nType=simple\r\nRestart=on-failure\r\nWorkingDirectory=/usr/share/grafana\r\nExecStart=/usr/sbin/grafana-server                                \\\r\n                            --config=${CONF_FILE}                 \\\r\n                            --pidfile=${PID_FILE}                 \\\r\n                            cfg:default.paths.logs=${LOG_DIR}     \\\r\n                            cfg:default.paths.data=${DATA_DIR}    \\\r\n                            cfg:default.paths.plugins=${PLUGINS_DIR}\r\n\r\n```\r\nThe referenced file does not even contain the variable \"PID_FILE\" nor does it set a value. \r\n\r\nA search through the documentation for the grafana.ini did not reveal any possibility to configure the pidfile.\r\n\r\n\r\n- Solution & Workaround\r\n\r\nThe 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.\r\n\r\n```\r\nPID_FILE=/var/run/grafana.pid\r\n```\r\n\r\nThis setting would have been expected to be in the file deployed via the rpm.\r\n\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/grafana/grafana/issues/comments/326367052","html_url":"https://github.com/grafana/grafana/issues/9133#issuecomment-326367052","issue_url":"https://api.github.com/repos/grafana/grafana/issues/9133","id":326367052,"user":{"login":"gerhard-tinned","id":1536065,"avatar_url":"https://avatars0.githubusercontent.com/u/1536065?v=4","gravatar_id":"","url":"https://api.github.com/users/gerhard-tinned","html_url":"https://github.com/gerhard-tinned","followers_url":"https://api.github.com/users/gerhard-tinned/followers","following_url":"https://api.github.com/users/gerhard-tinned/following{/other_user}","gists_url":"https://api.github.com/users/gerhard-tinned/gists{/gist_id}","starred_url":"https://api.github.com/users/gerhard-tinned/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gerhard-tinned/subscriptions","organizations_url":"https://api.github.com/users/gerhard-tinned/orgs","repos_url":"https://api.github.com/users/gerhard-tinned/repos","events_url":"https://api.github.com/users/gerhard-tinned/events{/privacy}","received_events_url":"https://api.github.com/users/gerhard-tinned/received_events","type":"User","site_admin":false},"created_at":"2017-08-31T17:30:45Z","updated_at":"2017-08-31T17:30:45Z","author_association":"NONE","body":"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)\r\n\r\n**What is the problem?**\r\n1.) The grafana-server is just \"not starting\" as many would report it. Usually you would expect some more details but the grafana-server dies without a single character of log or output! - This is definitive a BUG and should be fixed!\r\n\r\n2.) 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. \r\n\r\nThe 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. \r\nhttps://github.com/grafana/grafana/blob/40ae2cef383aed5fd216bef26267d945bae67614/packaging/rpm/init.d/grafana-server#L86\r\n\r\nNow 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.\r\nhttps://github.com/grafana/grafana/blob/40ae2cef383aed5fd216bef26267d945bae67614/packaging/rpm/systemd/grafana-server.service#L10-L11\r\n\r\n**How to fix it?**\r\n* The rpm should create a directory under /var/run/ like \"/var/run/grafana/\". This directories owner and group can be changed to the daemons user and group. \r\n* The rpm should provide the \"PID_FILE\" setting in the [/etc/sysconfig/grafana-serve](https://github.com/grafana/grafana/blob/master/packaging/rpm/sysconfig/grafana-server) with content like this. `PID_FILE=/var/run/grafana/grafana-server.pid`\r\n\r\nIf 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. \r\n\r\nI am not familiar with the packaging process used here but I guess the related lines should be added around this line ...\r\nhttps://github.com/grafana/grafana/blob/40ae2cef383aed5fd216bef26267d945bae67614/packaging/rpm/control/postinst#L47\r\n\r\nTo activate this only on systemd machines, a simple check like it is done a little further down would be enough. \r\n\r\n```\r\nif [ -x /bin/systemctl ] ; then\r\n  mkdir -p /var/run/grafana\r\n  chown -R $GRAFANA_USER:$GRAFANA_GROUP /var/run/grafana\r\nfi\r\n```\r\n\r\nI assume the same needs to be done for the deb packages as they use systemd al well in resent releases.\r\n"}}
{"actor":{"display_login":"gerhard-tinned"}}