Header

How can I run the DeployHQ agent automatically on my server during startup?

The following example is a systemd script, which defines a simple process that is run during startup. This is compatible with most Linux-based systems but you may need to implement a different solution on another operating system.

Simply save this file as a useful name within your /etc/systemd/system directory, as follows:

/etc/systemd/system/deploy-agent.service

The file will contain the following:

[Unit]
Description=Deploy Agent

[Service]
User=deployhq
ExecStart=/usr/local/bin/deploy-agent run
ExecStop=/usr/local/bin/deploy-agent stop
Restart=on-failure

[Install]
WantedBy=multi-user.target

You'll need to replace the User value as appropriate for the user you installed the agent with.

Once the file has been created and populated, you'll need to set permissions for it, reload systemd and then enable the service:

sudo chmod 644 /etc/systemd/system/deploy-agent.service
sudo systemctl daemon-reload
sudo systemctl enable deploy-agent.service

This will cause the agent to be started on boot, and if you wish to start it immediately, you can run:

sudo systemctl start deploy-agent.service

If you need to check that the agent is running correctly at any time, you can run:

$ sudo systemctl status deploy-agent.service
* deploy-agent.service - Deploy Agent
   Loaded: loaded (/etc/systemd/system/deploy-agent.service; enabled; vendor preset: enabled)
   Active: active (running) since Wed 2019-10-09 10:22:49 BST; 48s ago
 Main PID: 526 (deploy-agent)
   CGroup: /system.slice/deploy-agent.service
           `-526 /usr/bin/ruby2.3 /usr/local/bin/deploy-agent run
Tree

Proudly powered by Katapult. Running on 100% renewable energy.