ubuntugrafana

Starting Grafana-server always gives me bind: address already in use even though I change port


I'm using Ansible to automatically install Grafana, Promethus and Node exporter. Everything else works well, but I'm having issues starting the Grafana server. So I tried to SSH into the server and run sudo grafana-server --config grafana.ini --homepath "/usr/share/grafana". My HTTP options for Grafana is this:

# HTTP options
[server]
http_addr = 0.0.0.0
http_port = 1339
domain = ansiblevirtualbox
root_url = http://0.0.0.0:1337
cert_key = 
enforce_domain = False
protocol = http
socket = 
enable_gzip = False
cert_file = 
static_root_path = public
router_logging = False

As you see, I'm currently using port 1339. Which gives me the error address already in use. I can change to port 3000, 1337 etc. I always get that error.

Here below is the log for the recent try to start the server.

t=2019-09-19T06:26:44+0000 lvl=info msg="Starting Grafana" logger=server version=6.3.5 commit=67bad72 branch=HEAD compiled=2019-09-02T09:34:49+0000
t=2019-09-19T06:26:44+0000 lvl=info msg="Config loaded from" logger=settings file=/usr/share/grafana/conf/defaults.ini
t=2019-09-19T06:26:44+0000 lvl=info msg="Config loaded from" logger=settings file=grafana.ini
t=2019-09-19T06:26:44+0000 lvl=info msg="Path Home" logger=settings path=/usr/share/grafana
t=2019-09-19T06:26:44+0000 lvl=info msg="Path Data" logger=settings path=/var/lib/grafana
t=2019-09-19T06:26:44+0000 lvl=info msg="Path Logs" logger=settings path=/var/log/grafana
t=2019-09-19T06:26:44+0000 lvl=info msg="Path Plugins" logger=settings path=/var/lib/grafana/plugins
t=2019-09-19T06:26:44+0000 lvl=info msg="Path Provisioning" logger=settings path=/usr/share/grafana/conf/provisioning
t=2019-09-19T06:26:44+0000 lvl=info msg="App mode production" logger=settings
t=2019-09-19T06:26:44+0000 lvl=info msg="Initializing SqlStore" logger=server
t=2019-09-19T06:26:44+0000 lvl=info msg="Connecting to DB" logger=sqlstore dbtype=sqlite3
t=2019-09-19T06:26:44+0000 lvl=info msg="Starting DB migration" logger=migrator
t=2019-09-19T06:26:44+0000 lvl=info msg="Initializing HTTPServer" logger=server
t=2019-09-19T06:26:44+0000 lvl=info msg="Initializing InternalMetricsService" logger=server
t=2019-09-19T06:26:44+0000 lvl=info msg="Initializing RemoteCache" logger=server
t=2019-09-19T06:26:44+0000 lvl=info msg="Initializing QuotaService" logger=server
t=2019-09-19T06:26:44+0000 lvl=info msg="Initializing PluginManager" logger=server
t=2019-09-19T06:26:44+0000 lvl=info msg="Starting plugin search" logger=plugins
t=2019-09-19T06:26:44+0000 lvl=info msg="Initializing RenderingService" logger=server
t=2019-09-19T06:26:44+0000 lvl=info msg="Initializing AlertEngine" logger=server
t=2019-09-19T06:26:44+0000 lvl=info msg="Initializing DatasourceCacheService" logger=server
t=2019-09-19T06:26:44+0000 lvl=info msg="Initializing HooksService" logger=server
t=2019-09-19T06:26:44+0000 lvl=info msg="Initializing LoginService" logger=server
t=2019-09-19T06:26:44+0000 lvl=info msg="Initializing SearchService" logger=server
t=2019-09-19T06:26:44+0000 lvl=info msg="Initializing ServerLockService" logger=server
t=2019-09-19T06:26:44+0000 lvl=info msg="Initializing TracingService" logger=server
t=2019-09-19T06:26:44+0000 lvl=info msg="Initializing UsageStatsService" logger=server
t=2019-09-19T06:26:44+0000 lvl=info msg="Initializing UserAuthTokenService" logger=server
t=2019-09-19T06:26:44+0000 lvl=info msg="Initializing CleanUpService" logger=server
t=2019-09-19T06:26:44+0000 lvl=info msg="Initializing NotificationService" logger=server
t=2019-09-19T06:26:44+0000 lvl=info msg="Initializing provisioningServiceImpl" logger=server
t=2019-09-19T06:26:44+0000 lvl=info msg="Initializing Stream Manager"
t=2019-09-19T06:26:44+0000 lvl=info msg="HTTP Server Listen" logger=http.server address=0.0.0.0:1339 protocol=http subUrl= socket=
t=2019-09-19T06:26:44+0000 lvl=eror msg="Stopped HTTPServer" logger=server reason="listen tcp 0.0.0.0:1339: bind: address already in use"
t=2019-09-19T06:26:44+0000 lvl=info msg="Stopped Stream Manager"
t=2019-09-19T06:26:44+0000 lvl=info msg="Stopped NotificationService" logger=server reason="context canceled"
t=2019-09-19T06:26:44+0000 lvl=info msg="Stopped CleanUpService" logger=server reason="context canceled"
t=2019-09-19T06:26:44+0000 lvl=info msg="Stopped UserAuthTokenService" logger=server reason="context canceled"
t=2019-09-19T06:26:44+0000 lvl=info msg="Stopped UsageStatsService" logger=server reason="context canceled"
t=2019-09-19T06:26:44+0000 lvl=info msg="Stopped TracingService" logger=server reason=nil
t=2019-09-19T06:26:44+0000 lvl=info msg="Stopped RenderingService" logger=server reason=nil
t=2019-09-19T06:26:44+0000 lvl=info msg="Stopped RemoteCache" logger=server reason="context canceled"
t=2019-09-19T06:26:44+0000 lvl=info msg="Stopped InternalMetricsService" logger=server reason="context canceled"
t=2019-09-19T06:26:44+0000 lvl=info msg="Stopped provisioningServiceImpl" logger=server reason="context canceled"
t=2019-09-19T06:26:44+0000 lvl=info msg="Stopped AlertEngine" logger=server reason="context canceled"
t=2019-09-19T06:26:45+0000 lvl=info msg="Stopped PluginManager" logger=server reason="context canceled"
t=2019-09-19T06:26:45+0000 lvl=eror msg="Server shutdown" logger=server reason="listen tcp 0.0.0.0:1339: bind: address already in use"

What could be the issue? If I run netstat -tulpn, it doesn't say anything about listening to the ports I have been using. I'm using Ubuntu 18.04


Solution

  • Run netstat with sudo. You can also try to sudo lsof -ti:1339 to see which process uses that port.

    You can kill it with sudo lsof -ti:1339 | xargs kill -9.

    Also, try to run it with only: grafana-server -homepath /usr/share/grafana