How do i stop an agent using CLI

I am trying to stop my client agent in order to restart with an updated hcl file. The only way I know to end the agent is using Ctrl^C, however I have since closed that terminal page. I am looking for a method to kill the agent from anywhere in the vm or restart the agent with the updated file.

I was able to reset the agent by manually rebooting my linode. I then was able to start both the server and clients agents. However, I don’t think this is the idea solution.

The Nomad client and server agents can be configured by an init system like systemd that should allow you to restart the agent. Here is an example of a systemd file for a Nomad client.

[Unit]
Description=Nomad
Documentation=https://nomadproject.io/docs/
[Service]
ExecStart=/usr/local/bin/nomad agent -config /etc/nomad
ExecReload=/bin/kill -HUP $MAINPID
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target

You can create a service file /etc/systemd/system/nomad.service

I assume once the file is present I can issue a command like systemd restart nomad?

Yes, if you have systemd installed then you should be able to run systemctl restart nomad.

Note: The service file is just an example. You can customize it as needed for your use case.

A more comprehensive systemd unit can be found in the Nomad repository. Installing Nomad from package will also install a systemd unit for you automatically.

Hope this helps!
Charlie Voiselle
Product Education Engineer, Nomad

1 Like

The service file is gone from the GH repo, but here is a copy

[Unit]
Description=Nomad
Documentation=https://nomadproject.io/docs/
Wants=network-online.target
After=network-online.target

# When using Nomad with Consul it is not necessary to start Consul first. These
# lines start Consul before Nomad as an optimization to avoid Nomad logging
# that Consul is unavailable at startup.
#Wants=consul.service
#After=consul.service

[Service]
EnvironmentFile=/etc/nomad.d/nomad.env
ExecReload=/bin/kill -HUP $MAINPID
ExecStart=/usr/bin/nomad agent -config /etc/nomad.d
KillMode=process
KillSignal=SIGINT
LimitNOFILE=65536
LimitNPROC=infinity
Restart=on-failure
RestartSec=2
StartLimitBurst=3
StartLimitInterval=10
TasksMax=infinity
OOMScoreAdjust=-1000

[Install]
WantedBy=multi-user.target

from before it was deleted.