Skip to content

Commit

Permalink
Update init.d scripts to check if datadog config is present before st…
Browse files Browse the repository at this point in the history
…arting. Fix #544
  • Loading branch information
elijahandrews committed Jun 14, 2013
1 parent 3c8d481 commit abf09e3
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packaging/datadog-agent-base-deb/datadog-agent.init
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
PATH=$PATH:/sbin # add the location of start-stop-daemon on Debian

AGENTPATH="/usr/bin/dd-agent"
AGENTCONF="/etc/dd-agent/datadog.conf"
DOGSTATSDPATH="/usr/bin/dogstatsd"
AGENTUSER="dd-agent"
USE_SUPERVISOR="/usr/bin/dd-forwarder"
Expand All @@ -33,6 +34,11 @@ if [ ! -x $AGENTPATH ]; then
exit 0
fi

if [ ! -f $AGENTCONF ]; then
echo "$AGENTCONF not found. Exiting."
exit 3
fi

check_status() {
if [ -f $USE_SUPERVISOR ]; then
# If the socket exists, we can use supervisorctl
Expand Down
13 changes: 13 additions & 0 deletions packaging/datadog-agent-base-deb/postinst
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,24 @@ case "$1" in
chown -h root:root /usr/bin/dogstatsd
chown -h root:root /usr/bin/dd-agent

set +e

if which invoke-rc.d >/dev/null 2>&1; then
invoke-rc.d datadog-agent restart
else
/etc/init.d/datadog-agent restart
fi

RETVAL=$?
if [ $RETVAL -ne 0 ]; then
if [ $RETVAL -eq 3 ]; then
# No datadog.conf file is present. The user is probably following
# the step-by-step instructions and will add the config file next.
exit 0
else
exit $RETVAL
fi
fi
;;

abort-upgrade|abort-remove|abort-deconfigure)
Expand Down
6 changes: 6 additions & 0 deletions packaging/datadog-agent-base-rpm/datadog-agent-redhat
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
### END INIT INFO

AGENTPATH="/usr/share/datadog/agent/agent.py"
AGENTCONF="/etc/dd-agent/datadog.conf"
DOGSTATSDPATH="/usr/share/datadog/agent/dogstatsd.py"
AGENTUSER="dd-agent"
PIDPATH="/var/run/dd-agent/"
Expand All @@ -35,6 +36,11 @@ else
PYTHON="/usr/bin/python"
fi

if [ ! -f $AGENTCONF ]; then
echo "$AGENTCONF not found. Exiting."
exit 3
fi

# Source function library.
. /etc/rc.d/init.d/functions

Expand Down
11 changes: 11 additions & 0 deletions packaging/datadog-agent-base-rpm/post_install
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,15 @@ chown -R dd-agent /var/log/datadog/
chkconfig --add datadog-agent

/etc/init.d/datadog-agent restart
RETVAL=$?
if [ $RETVAL -ne 0 ]; then
if [ $RETVAL -eq 3 ]; then
# No datadog.conf file is present. The user is probably following
# the step-by-step instructions and will add the config file next.
exit 0
else
exit $RETVAL
fi
fi

exit 0
13 changes: 13 additions & 0 deletions packaging/datadog-agent-deb/postinst
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,24 @@ case "$1" in
chown -h root:root /usr/bin/dd-agent
chown -h root:root /usr/bin/dd-forwarder

set +e

if which invoke-rc.d >/dev/null 2>&1; then
invoke-rc.d datadog-agent restart
else
/etc/init.d/datadog-agent restart
fi

RETVAL=$?
if [ $RETVAL -ne 0 ]; then
if [ $RETVAL -eq 3 ]; then
# No datadog.conf file is present. The user is probably following
# the step-by-step instructions and will add the config file next.
exit 0
else
exit $?
fi
fi
;;
abort-upgrade|abort-remove|abort-deconfigure)
;;
Expand Down
11 changes: 11 additions & 0 deletions packaging/datadog-agent-rpm/postinst
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,15 @@ chown -R dd-agent /var/log/datadog/
chkconfig --add datadog-agent

/etc/init.d/datadog-agent restart
RETVAL=$?
if [ $RETVAL -ne 0 ]; then
if [ $RETVAL -eq 3 ]; then
# No datadog.conf file is present. The user is probably following
# the step-by-step instructions and will add the config file next.
exit 0
else
exit $RETVAL
fi
fi

exit 0

0 comments on commit abf09e3

Please sign in to comment.