# Failed to cleanup /run/elastic-agent.sock

**URL:** <https://discuss.elastic.co/t/failed-to-cleanup-run-elastic-agent-sock/259809>\
**Category:** Beats\
**Tags:** filebeat, elastic-agent\
**Created:** [December 29, 2020, 3:31pm UTC](https://discuss.elastic.co/t/failed-to-cleanup-run-elastic-agent-sock/259809 "2020-12-29T15:31:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mostlyjason](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mostlyjason/32/60849_2.png) [@mostlyjason](https://discuss.elastic.co/u/mostlyjason)\
**Post date:** [December 29, 2020, 3:31pm UTC](https://discuss.elastic.co/t/failed-to-cleanup-run-elastic-agent-sock/259809/1 "2020-12-29T15:31:46Z")

</div>

I'm getting an error after installing Elastic Agent that says:

```
2020-12-29T15:16:12.945Z INFO application/application.go:58 Detecting execution mode
2020-12-29T15:16:12.945Z INFO application/application.go:71 Agent is managed by Fleet
2020-12-29T15:16:13.071Z ERROR [control] server/listener.go:52 Failed to cleanup /run/elastic-agent.sock: remove /run/elastic-agent.sock: no such file or directory

```

I tried uninstalling and then reinstalling Elastic Agent and I still get the same error message. I'm using version 7.10.1 on Debian using the Linux 64 bit installer. Any idea why it is looking to clean up a file that doesn't exist, especially after a fresh install?

---

<div class="post-metadata">

**Author:** ![mostlyjason](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mostlyjason/32/60849_2.png) [@mostlyjason](https://discuss.elastic.co/u/mostlyjason)\
**Post date:** [January 10, 2021, 12:37pm UTC](https://discuss.elastic.co/t/failed-to-cleanup-run-elastic-agent-sock/259809/2 "2021-01-10T12:37:38Z")

</div>

Looks like its coming from this line [https://github.com/elastic/beats/blob/ef6274d0d1e36308a333cbed69846a1bd63528ae/x-pack/elastic-agent/pkg/agent/control/server/listener.go#L52](https://github.com/elastic/beats/blob/ef6274d0d1e36308a333cbed69846a1bd63528ae/x-pack/elastic-agent/pkg/agent/control/server/listener.go#L52)

I only see one reference to this function in the GRPC stop function [https://github.com/elastic/beats/blob/c858dd0f3188793ffd52d8975c8120ce0f442ff8/x-pack/elastic-agent/pkg/agent/control/server/server.go#L82](https://github.com/elastic/beats/blob/c858dd0f3188793ffd52d8975c8120ce0f442ff8/x-pack/elastic-agent/pkg/agent/control/server/server.go#L82)

Why would it stop the GRPC server right after starting up? There must be some other error which causes it to stop the GRPC server, which is not logged.

I'm not a Go programmer, but looking at the Start function for the GRPC server, I don't see any check to validate whether the server is nil before using it. [https://github.com/elastic/beats/blob/c858dd0f3188793ffd52d8975c8120ce0f442ff8/x-pack/elastic-agent/pkg/agent/control/server/server.go#L63](https://github.com/elastic/beats/blob/c858dd0f3188793ffd52d8975c8120ce0f442ff8/x-pack/elastic-agent/pkg/agent/control/server/server.go#L63)

---

<div class="post-metadata">

**Author:** ![mostlyjason](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mostlyjason/32/60849_2.png) [@mostlyjason](https://discuss.elastic.co/u/mostlyjason)\
**Post date:** [January 13, 2021, 2:19pm UTC](https://discuss.elastic.co/t/failed-to-cleanup-run-elastic-agent-sock/259809/3 "2021-01-13T14:19:15Z")

</div>

Ok we figured it out! Turns out I had to print my journald logs to see the error message:

```
$ journalctl -u elastic-agent.service
elastic-agent[17671]: starting GRPC listener: listen tcp 127.0.0.1:6789: bind: address already in use

```

The solution was to change the grpc port in my elastic-agent.yml file. My agent is enrolled into fleet, but I can still add this to the file in my elastic-agent install directory. On debian, it's `/opt/Elastic/Agent/elastic-agent.yml`.

```
agent:
  grpc:
    port: 7777

```

The port conflict came from my unifi controller [https://help.ui.com/hc/en-us/articles/218506997-UniFi-Ports-Used](https://help.ui.com/hc/en-us/articles/218506997-UniFi-Ports-Used)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [February 10, 2021, 4:19pm UTC](https://discuss.elastic.co/t/failed-to-cleanup-run-elastic-agent-sock/259809/4 "2021-02-10T16:19:33Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
