Skip to content

Instantly share code, notes, and snippets.

@kchenery
Last active January 26, 2020 07:58
Show Gist options
  • Save kchenery/0012e098938f660e933cf84ce09d1b12 to your computer and use it in GitHub Desktop.
Save kchenery/0012e098938f660e933cf84ce09d1b12 to your computer and use it in GitHub Desktop.
Steps for setting up DataDog agent as a systemd service on a Raspberry PI

Install the requirements

sudo apt-get install sysstat

Install the agent from Datadog "from source". You'll get a command to run on the Pi that looks like this:

DD_API_KEY=0123456789abcdef0123456789abcdef sh -c "$(curl -L https://raw.githubusercontent.com/DataDog/dd-agent/master/packaging/datadog-agent/source/setup_agent.sh)"

Run that and wait for it to install and the agent to start running. Once its running, stop it with Ctrl+C cause we're going to move it all to /opt/datadog-agent

Copying the agent

# Create Datadog Agent directory
sudo mkdir /opt/datadog-agent
sudo cp -r ~/.datadog-agent/* /opt/datadog-agent

# Fix the python references to the new directory
# cd /opt/datadog-agent/venv/bin

path=$HOME
path=${path//\//\\\/}
sedcmd="s/$path\/.datadog-agent/\/opt\/datadog-agent/g"

for i in /opt/datadog-agent/venv/bin/*;
do
    echo $i
    sudo sed -i $sedcmd $i
done

Fix the venv references

cd /opt/datadog-agent/venv/local/

for i in *;
do
    echo $i
    sudo rm $i && sudo ln -s ../$i $i
done

Create a start_agent.sh script in /opt/datadog-agent Copy the following to the file:

#!/bin/sh

PATH=/opt/datadog-agent/venv/bin:/opt/datadog-agent/bin:$PATH

exec /opt/datadog-agent/venv/bin/supervisord -c /opt/datadog-agent/agent/supervisor.conf

Creating the datadog user

sudo useradd -r datadog

Change the owner of the datadog directory and contents to the datadog user

sudo chown datadog:datadog -R /opt/datadog-agent

Make the script executable:

sudo chmod ug+x start_agent.sh

Modify the file /opt/datadog-agent/agent/supervisor.conf

Change the line:

nodaemon = true

to

nodaemon = false

Create a datadog-agent.service file in /etc/systemd/system Copy the following into the file:

[Unit]
Description="Datadog Agent"
After=network.target

[Service]
Type=forking
User=datadog
WorkingDirectory=/opt/datadog-agent
ExecStart=/opt/datadog-agent/start_agent.sh
ExecStop=/opt/datadog-agent/venv/bin/supervisorctl -c /opt/datadog-agent/agent/supervisor.conf shutdown

[Install]
WantedBy=multi-user.target

Reload systemd

sudo systemctl daemon-reload

Enable the service

sudo systemctl enable datadog-agent.service

Start the service

sudo systemctl start datadog-agent.service
@YorkAARGH
Copy link

I stumbled across this as I'm trying to get datadog running as a service on my raspberry pi 2 model b.

I've hit a roadblock at the Fix the python references to the new directory section, you show a directory, but not any actual instructions to proceed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment