Issue with Nomad Service Restart: Node not eligible after bash script execution

Hi Hashicorp Enthusiasts,

I encountered an issue with Nomad service restarts. Following a restart, the node fails to become eligible. I’ve scripted the process, which involves starting the Nomad agent and enabling node eligibility. Here’s a breakdown of the bash script’s actions:

nomad agent -config /home/hashicorp/nomad
nomad eligibility -enable -self

While running the nomad eligibility -enable -self command directly in the terminal successfully enables the node, executing the bash script results in an error:

Error querying agent info: failed querying self endpoint: Get „http://127.0.0.1:4646/v1/agent/self”: dial tcp 127.0.0.1:4646: connect: connection refused

Even after attempting to replace NOMAD_ADDR to match the host IP, the issue persists. Any insights into why the command works when run directly from the terminal but fails within the bash script?

Nomad version: 1.7.3

I found a solution it looks like 15sec sleep between nomad start and nomad eligibility is not enough. After changing sleep to 20sec everything is working fine