Read /var/log/grafana/grafana.log, then check the status number. Grafana logs the real reason there before it exits. If systemctl status grafana-server shows status=217/USER, the grafana user does not exist and Grafana never ran at all.
sudo tail -40 /var/log/grafana/grafana.log systemctl status grafana-server | grep -E 'Process|status=|Result'
The causes, in order of how often they appear
- Ownership of the data directory. Grafana runs as the grafana user and needs to write its SQLite database, sessions and plugins under
/var/lib/grafana. The classic trigger is installing a plugin withsudo grafana-cli, which leaves a root-owned plugin directory behind. Grafana then runs fine by hand as root and fails under systemd:sudo chown -R grafana:grafana /var/lib/grafana /var/log/grafana sudo systemctl restart grafana-server
- A bad edit in grafana.ini. A malformed line, usually in the
[smtp]or[auth.ldap]section after someone configured alerts or login, stops the server on startup. The log names the section. A;at the start of a line comments it out, which catches people who uncomment one line and leave the next commented. - Could not find config defaults. Grafana was started with the wrong home path, so it cannot find
conf/defaults.ini. It appears when a custom unit or an override drops the--homepath=/usr/share/grafanaargument. Compare your unit against the packaged one withsystemctl cat grafana-server. - A provisioning file that fails to parse. YAML under
/etc/grafana/provisioning/for datasources or dashboards is read at startup, and one bad indent or a tab character stops the whole server. The log names the file. - The SQLite database is locked or damaged. After a full disk or an unclean stop,
grafana.dbcan be left locked. Checkdf -hfirst, then look fordatabase is lockedin the log. Copy the file before touching it; it holds every dashboard and user. - Port 3000 already bound. Another dashboard tool or a development server often claims it:
sudo ss -tlnp | grep ':3000 '. Changehttp_portin grafana.ini or stop the other process.
If the status says start-limit-hit
Result: start-limit-hit is not a cause; it means Grafana crashed several times quickly and systemd stopped retrying. Fix the real failure from the log first, then clear the counter, or the next start is refused even though nothing is wrong any more:
sudo systemctl reset-failed grafana-server sudo systemctl start grafana-server
Reading the exit code
status=1/FAILURE means Grafana started and rejected something, so read its log. status=217/USER means the user in the unit does not exist, common when configuration management installs Grafana from a tarball rather than the package. status=203/EXEC means the binary path in the unit is wrong. The full table is in the nginx version of this error.
How to stop it happening again
Install plugins as the grafana user, never as root, and keep a copy of grafana.ini before each edit:
sudo -u grafana grafana-cli --pluginsDir /var/lib/grafana/plugins plugins install <plugin-id> sudo systemctl restart grafana-server
Back up grafana.db on a schedule. It is the single file holding your dashboards, users and alert rules, and the failure modes above that touch it are the only ones on this page that can lose work.
Related
- Job for elasticsearch.service failed: a common Grafana data source that fails on host settings.
- Job for mongod.service failed: another service whose YAML configuration rejects tabs.
- Job for nginx.service failed: the reverse proxy usually in front of Grafana, plus the full exit-code table.
Grafana runs when I start it by hand but not with systemctl
You are almost certainly running it by hand as root, which can write anywhere, while systemd runs it as the grafana user. A root-owned file under /var/lib/grafana, usually from a plugin install, is the difference. Fix the ownership as in cause 1.
Is the service grafana or grafana-server?
Packages install grafana-server.service. Some newer installs and container images use grafana.service. Check with systemctl list-unit-files 'grafana*' before assuming it is not installed.
Leave a Reply