Can't deregister Consul service

Hi,
I am running Consul on RHEL 8.x box and consul version is 1.15.2.
I am trying to deregister the service and I get the following error:

Error: config: Open failed on shipments. open shipments: no such file or directory

I know the requirement of Consul that I need to deregister the service from the agent that it was registered on.

Here is my consul catalog output
image

As seen in screenshot, shipment service is registered

Change I see on RHEL side is that, consul is upgraded from 1.15.0 to 1.15.2

I appreciate help to clear my registrations.
Thanks

@tigeroftexas The error you provided does not look it came from Consul. Can you provide more detail on how you are trying to deregister this service?

@blake Here is the command I used:

consul services deregister shipments

Hi @tigeroftexas,

I see what is happening here. consul services deregister can take a service name specified via the -id= argument, or it can read the deregistration payload from a file that is specified as a positional argument.

consul services deregister shipments is doing the latter. It is trying to read a file named shipments, and is generating that error because the file does not exist.

You can resolve this by creating the file, or deregistering the service using the service ID.

$ cat << EOF > shipments
{
  "Service": {
    "Name": "shipments"
  }
}
EOF

$ consul services deregister shipments

## Alternate solution

$ consul services deregister -id=shipments

Keep in mind that this command needs to be ran against the same agent where this service is registered. If you have multiple Consul agents in your environment, you can locate the appropriate agent(s) by looking at the service catalog.

$ curl --no-progress-meter $CONSUL_HTTP_ADDR/v1/catalog/service/shipments | \
  jq 'map({Node: .Node, Name: .ServiceName, ID: .ServiceID})'
[
  {
    "Node": "test-node.example.com",
    "Name": "shipments",
    "ID": "shipments-1"
  }
]

# Run this command against the Consul agent running on test-node
$ consul services deregister -id=shipments-1

@blake,
Thanks for an awesome explanation. That indeed was a problem, I registered service using the consul services register so there was no service file and it was complaining about it. I deregistered with id and it worked.
Thanks again for write up. I learnt something new today

1 Like

@blake
I have the same problem, only my Consul agent who registered the service is not available at the moment.
Is there another way to deregister the service?

Hi @udirctera,

If the Consul agent is no longer part of the cluster, you can remove the service from the catalog using the /v1/catalog/deregister API.

I hope this helps.