From 101805a494119c035a91d6265adff3d95bbc8eca Mon Sep 17 00:00:00 2001 From: Etienne LAFARGE Date: Tue, 14 Apr 2015 20:53:37 -0400 Subject: [PATCH] [systemd] Package updated to be systemd compliant The install script has been modified (it uses updated-rc.d to restart the agent, which will implicitly call systemd if available) and the datadog-agent.service systemd descriptor has been added as part of the package (so that omnibus puts it in the .deb packages). This service declaration is basically pluging supervisord into systemd, nothing more (as shown here https://gist.github.com/tonyseek/ddc7e3a89f0d78e685d6 for instance) The supervisord start call has been ut in a separate script. It allows us to have access to the PATH (/bin/sh is called to run the script) while keeping a one-level forking scheme thanks to exec (/bin/sh gets replaced by supervisord that will then fork and launch the different components of our agent. Being a direct child of systemd, the forked processes are too). --- packaging/datadog-agent/source/install_agent.sh | 8 ++++++-- packaging/debian/datadog-agent.service | 11 +++++++++++ packaging/debian/start_agent.sh | 5 +++++ 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 packaging/debian/datadog-agent.service create mode 100644 packaging/debian/start_agent.sh diff --git a/packaging/datadog-agent/source/install_agent.sh b/packaging/datadog-agent/source/install_agent.sh index 9ada275974..74b1a75664 100755 --- a/packaging/datadog-agent/source/install_agent.sh +++ b/packaging/datadog-agent/source/install_agent.sh @@ -5,7 +5,7 @@ logfile="ddagent-install.log" gist_request=/tmp/agent-gist-request.tmp gist_response=/tmp/agent-gist-response.tmp -if [ $(which curl) ]; then +if [ $(command -v curl) ]; then dl_cmd="curl -f" else dl_cmd="wget --quiet" @@ -144,7 +144,11 @@ else fi printf "\033[34m* Starting the Agent...\n\033[0m\n" -$sudo_cmd /etc/init.d/datadog-agent restart +if command -v invoke-rc.d >/dev/null 2>&1; then + $sudo_cmd invoke-rc.d datadog-agent restart +else + $sudo_cmd /etc/init.d/datadog-agent restart +fi # Wait for metrics to be submitted by the forwarder printf "\033[32m diff --git a/packaging/debian/datadog-agent.service b/packaging/debian/datadog-agent.service new file mode 100644 index 0000000000..27ee2fb85a --- /dev/null +++ b/packaging/debian/datadog-agent.service @@ -0,0 +1,11 @@ +[Unit] +Description="Datadog Agent" +After=network.target + +[Service] +Type=forking +ExecStart=/opt/datadog-agent/bin/start_agent.sh +ExecStop=/opt/datadog-agent/bin/supervisorctl -c /etc/dd-agent/supervisor.conf shutdown + +[Install] +WantedBy=multi-user.target diff --git a/packaging/debian/start_agent.sh b/packaging/debian/start_agent.sh new file mode 100644 index 0000000000..700db7ec6f --- /dev/null +++ b/packaging/debian/start_agent.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +PATH=/opt/datadog-agent/embedded/bin:/opt/datadog-agent/bin:$PATH + +exec /opt/datadog-agent/bin/supervisord -c /etc/dd-agent/supervisor.conf --pidfile /var/run/datadog-supervisord.pid