2016-01-08 15:47:09 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
BIN_DIR=/usr/bin
|
|
|
|
LOG_DIR=/var/log/telegraf
|
|
|
|
SCRIPT_DIR=/usr/lib/telegraf/scripts
|
|
|
|
LOGROTATE_DIR=/etc/logrotate.d
|
|
|
|
|
|
|
|
function install_init {
|
|
|
|
cp -f $SCRIPT_DIR/init.sh /etc/init.d/telegraf
|
|
|
|
chmod +x /etc/init.d/telegraf
|
|
|
|
}
|
|
|
|
|
|
|
|
function install_systemd {
|
2017-05-05 21:04:33 +00:00
|
|
|
cp -f $SCRIPT_DIR/telegraf.service $1
|
2016-04-19 00:32:15 +00:00
|
|
|
systemctl enable telegraf || true
|
2016-02-23 17:25:07 +00:00
|
|
|
systemctl daemon-reload || true
|
2016-01-08 15:47:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function install_update_rcd {
|
|
|
|
update-rc.d telegraf defaults
|
|
|
|
}
|
|
|
|
|
|
|
|
function install_chkconfig {
|
|
|
|
chkconfig --add telegraf
|
|
|
|
}
|
|
|
|
|
2017-05-05 21:29:40 +00:00
|
|
|
if ! grep "^telegraf:" /etc/group &>/dev/null; then
|
|
|
|
groupadd -r telegraf
|
|
|
|
fi
|
|
|
|
|
2017-04-20 18:19:33 +00:00
|
|
|
if ! id telegraf &>/dev/null; then
|
2017-05-05 21:29:40 +00:00
|
|
|
useradd -r -M telegraf -s /bin/false -d /etc/telegraf -g telegraf
|
2016-01-08 15:47:09 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Remove legacy symlink, if it exists
|
|
|
|
if [[ -L /etc/init.d/telegraf ]]; then
|
|
|
|
rm -f /etc/init.d/telegraf
|
|
|
|
fi
|
2016-07-14 21:53:05 +00:00
|
|
|
# Remove legacy symlink, if it exists
|
|
|
|
if [[ -L /etc/systemd/system/telegraf.service ]]; then
|
|
|
|
rm -f /etc/systemd/system/telegraf.service
|
|
|
|
fi
|
2016-01-08 15:47:09 +00:00
|
|
|
|
|
|
|
# Add defaults file, if it doesn't exist
|
|
|
|
if [[ ! -f /etc/default/telegraf ]]; then
|
|
|
|
touch /etc/default/telegraf
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Add .d configuration directory
|
|
|
|
if [[ ! -d /etc/telegraf/telegraf.d ]]; then
|
|
|
|
mkdir -p /etc/telegraf/telegraf.d
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Distribution-specific logic
|
2017-05-05 21:04:33 +00:00
|
|
|
if [[ -f /etc/redhat-release ]] || [[ -f /etc/SuSE-release ]]; then
|
2016-01-08 15:47:09 +00:00
|
|
|
# RHEL-variant logic
|
2017-04-20 18:19:33 +00:00
|
|
|
if [[ "$(readlink /proc/1/exe)" == */systemd ]]; then
|
2017-05-05 21:04:33 +00:00
|
|
|
install_systemd /usr/lib/systemd/system/telegraf.service
|
2016-01-08 15:47:09 +00:00
|
|
|
else
|
2017-04-20 18:19:33 +00:00
|
|
|
# Assuming SysVinit
|
|
|
|
install_init
|
|
|
|
# Run update-rc.d or fallback to chkconfig if not available
|
|
|
|
if which update-rc.d &>/dev/null; then
|
|
|
|
install_update_rcd
|
|
|
|
else
|
|
|
|
install_chkconfig
|
|
|
|
fi
|
2016-01-08 15:47:09 +00:00
|
|
|
fi
|
2016-01-15 15:51:04 +00:00
|
|
|
elif [[ -f /etc/debian_version ]]; then
|
2016-01-08 15:47:09 +00:00
|
|
|
# Debian/Ubuntu logic
|
2019-04-15 23:07:47 +00:00
|
|
|
|
|
|
|
# Ownership for RH-based platforms is set in build.py via the `rmp-attr` option.
|
|
|
|
# We perform ownership change only for Debian-based systems.
|
|
|
|
# Moving these lines out of this if statement would make `rmp -V` fail after installation.
|
|
|
|
test -d $LOG_DIR || mkdir -p $LOG_DIR
|
|
|
|
chown -R -L telegraf:telegraf $LOG_DIR
|
|
|
|
chmod 755 $LOG_DIR
|
|
|
|
|
2017-04-20 18:19:33 +00:00
|
|
|
if [[ "$(readlink /proc/1/exe)" == */systemd ]]; then
|
2017-05-05 21:04:33 +00:00
|
|
|
install_systemd /lib/systemd/system/telegraf.service
|
2017-11-28 01:05:32 +00:00
|
|
|
deb-systemd-invoke restart telegraf.service || echo "WARNING: systemd not running."
|
2016-01-08 15:47:09 +00:00
|
|
|
else
|
2017-05-05 21:29:40 +00:00
|
|
|
# Assuming SysVinit
|
2017-04-20 18:19:33 +00:00
|
|
|
install_init
|
|
|
|
# Run update-rc.d or fallback to chkconfig if not available
|
|
|
|
if which update-rc.d &>/dev/null; then
|
|
|
|
install_update_rcd
|
|
|
|
else
|
|
|
|
install_chkconfig
|
|
|
|
fi
|
|
|
|
invoke-rc.d telegraf restart
|
2016-01-08 15:47:09 +00:00
|
|
|
fi
|
2016-01-25 21:19:51 +00:00
|
|
|
elif [[ -f /etc/os-release ]]; then
|
|
|
|
source /etc/os-release
|
2019-02-07 00:17:11 +00:00
|
|
|
if [[ "$NAME" = "Amazon Linux" ]]; then
|
|
|
|
# Amazon Linux 2+ logic
|
|
|
|
install_systemd /usr/lib/systemd/system/telegraf.service
|
|
|
|
elif [[ "$NAME" = "Amazon Linux AMI" ]]; then
|
2017-05-05 21:29:40 +00:00
|
|
|
# Amazon Linux logic
|
2017-04-20 18:19:33 +00:00
|
|
|
install_init
|
|
|
|
# Run update-rc.d or fallback to chkconfig if not available
|
|
|
|
if which update-rc.d &>/dev/null; then
|
|
|
|
install_update_rcd
|
|
|
|
else
|
|
|
|
install_chkconfig
|
|
|
|
fi
|
2016-01-25 21:19:51 +00:00
|
|
|
fi
|
2016-01-08 15:47:09 +00:00
|
|
|
fi
|