-
Notifications
You must be signed in to change notification settings - Fork 21
/
preinst
executable file
·118 lines (97 loc) · 4.58 KB
/
preinst
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#! /bin/sh
INSTALL_DIR=/opt/datadog-agent
LOG_DIR=/var/log/datadog
mkdir -p $LOG_DIR
KNOWN_DISTRIBUTION="(Debian|Ubuntu|RedHat|CentOS|openSUSE|Amazon|Arista|SUSE)"
DISTRIBUTION=$(lsb_release -d 2>/dev/null | grep -Eo $KNOWN_DISTRIBUTION || grep -Eo $KNOWN_DISTRIBUTION /etc/issue 2>/dev/null || grep -Eo $KNOWN_DISTRIBUTION /etc/Eos-release 2>/dev/null || uname -s)
# Linux installation
if [ "$DISTRIBUTION" != "Darwin" ]; then
if [ -f "/etc/debian_version" ] || [ "$DISTRIBUTION" = "Debian" ] || [ "$DISTRIBUTION" = "Ubuntu" ]; then
set -e
if [ -f "/etc/init.d/datadog-agent" ]; then
if command -v invoke-rc.d >/dev/null 2>&1; then
invoke-rc.d datadog-agent stop || true
else
/etc/init.d/datadog-agent stop || true
fi
fi
# Since we now package our own supervisor config, we no longer want
# the old config to be loaded. Since supervisor automatically loads
# configs in conf.d, we have to delete the old config file.
if [ -f "/etc/supervisor/conf.d/ddagent.conf" ]; then
echo "Removing old configuration from system supervisord"
rm /etc/supervisor/conf.d/ddagent.conf
fi
# Previous versions of dd-agent created this file but didn't do
# anything with it.
if [ -f "/etc/dd-agent/supervisor_ddagent.conf" ]; then
rm /etc/dd-agent/supervisor_ddagent.conf
fi
#DEBHELPER#
elif [ -f "/etc/redhat-release" ] || [ -f "/etc/system-release" ] || [ -f "/etc/SuSE-release" ] || [ "$DISTRIBUTION" = "RedHat" ] || [ "$DISTRIBUTION" = "CentOS" ] || [ "$DISTRIBUTION" = "openSUSE" ] || [ "$DISTRIBUTION" = "Amazon" ] || [ "$DISTRIBUTION" = "SUSE" ] || [ "$DISTRIBUTION" = "Arista" ]; then
getent group dd-agent >/dev/null || groupadd -r dd-agent
getent passwd dd-agent >/dev/null || \
useradd -r -M -g dd-agent -d $INSTALL_DIR -s /bin/sh \
-c "Datadog Agent" dd-agent && \
usermod -L dd-agent
# Stop the old agent before installing
if [ -f "/etc/init.d/datadog-agent" ]; then
/etc/init.d/datadog-agent stop || true
fi
# Delete all the .pyc/.pyo files in the embedded dir that are part of the old agent's package
if [ -f "/opt/datadog-agent/embedded/.py_compiled_files.txt" ]; then
# (commented lines are filtered out)
cat /opt/datadog-agent/embedded/.py_compiled_files.txt | grep -v '^#' | xargs rm -f
fi
else
echo "[ ${Red}FAILED ${RCol}]\tYour system is currently not supported by this script.";
exit 1;
fi
# Delete .pyc files
# FIXME: it shouldn't be done there, but only in prerm (see 6.6
# of https://www.debian.org/doc/debian-policy/ch-maintainerscripts.html)
# It is also here because version < 5.4 didn't delete .pyc,
# so we need to be sure to clean them here (if a file is deleted for instance)
find $INSTALL_DIR/agent -name '*.py[co]' -type f -delete >/dev/null 2>&1 || true
# FIXME: remove when CentOS5 support is dropped (03/31/2017) or when everybody
# has stopped using dd-agent 5.3 (and older versions ofc)
rm -f $INSTALL_DIR/agent/checks/utils.py
elif [ "$DISTRIBUTION" = "Darwin" ]; then
DD_COMMAND="$INSTALL_DIR/bin/datadog-agent"
CONF_DIR="$INSTALL_DIR/etc"
APP_DIR="/Applications/Datadog Agent.app"
LOG_FILE="$LOG_DIR/preinstall.log"
exec > $LOG_FILE 2>&1
if [ -e "$CONF_DIR/datadog.conf" ]; then
echo "# State at the beginning"
echo "## Agent version"
grep AGENT_VERSION $INSTALL_DIR/agent/config.py || echo "No config file"
echo "## $INSTALL_DIR"
ls -al $INSTALL_DIR || echo "No agent installed"
echo "## $APP_DIR/Contents/Resources"
ls -al "$APP_DIR/Contents/Resources" || echo "No app installed"
echo '# Stop old agent'
$DD_COMMAND stop || true
kill `ps aux | grep 'Datadog Agent.app' | grep -v grep | cut -d ' ' -f 4` || true
echo '# Stop old GUI'okill `ps aux | grep 'Datadog Agent.app' | grep -v grep | awk '{ print $2 }'` || true
# Save old conf
mkdir -vp /tmp/{conf,checks}.d
rm -rvf /tmp/{checks,conf}.d/* /tmp/datadog.conf
cp -vf $CONF_DIR/datadog.conf /tmp
cp -vf $CONF_DIR/conf.d/*.yaml /tmp/conf.d
cp -vfR $CONF_DIR/checks.d/* /tmp/checks.d
fi
echo '# Deleting old datadog-agent link'
rm -vf /usr/local/bin/datadog-agent
echo '# Deleting old datadog-agent files'
rm -rf $INSTALL_DIR/agent || true
# Debriefing time
echo "# State at the end"
echo "## Agent version"
grep AGENT_VERSION $INSTALL_DIR/agent/config.py || echo "No config file"
echo "## $INSTALL_DIR"
ls -al $INSTALL_DIR || echo "No agent installed"
echo "## $APP_DIR/Contents/Resources"
ls -al "$APP_DIR/Contents/Resources" || echo "No app installed"
fi
exit 0