2016-01-08 23:47:09 +08: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-06 05:04:33 +08:00
|
|
|
cp -f $SCRIPT_DIR/telegraf.service $1
|
2016-04-19 08:32:15 +08:00
|
|
|
systemctl enable telegraf || true
|
2016-02-24 01:25:07 +08:00
|
|
|
systemctl daemon-reload || true
|
2016-01-08 23:47:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function install_update_rcd {
|
|
|
|
|
update-rc.d telegraf defaults
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function install_chkconfig {
|
|
|
|
|
chkconfig --add telegraf
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Remove legacy symlink, if it exists
|
|
|
|
|
if [[ -L /etc/init.d/telegraf ]]; then
|
|
|
|
|
rm -f /etc/init.d/telegraf
|
|
|
|
|
fi
|
2016-07-15 05:53:05 +08: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 23:47:09 +08: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
|
|
|
|
|
|
2020-07-28 23:26:09 +08:00
|
|
|
# If 'telegraf.conf' is not present use package's sample (fresh install)
|
|
|
|
|
if [[ ! -f /etc/telegraf/telegraf.conf ]] && [[ -f /etc/telegraf/telegraf.conf.sample ]]; then
|
|
|
|
|
cp /etc/telegraf/telegraf.conf.sample /etc/telegraf/telegraf.conf
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
test -d $LOG_DIR || mkdir -p $LOG_DIR
|
|
|
|
|
chown -R -L telegraf:telegraf $LOG_DIR
|
|
|
|
|
chmod 755 $LOG_DIR
|
|
|
|
|
|
2016-01-08 23:47:09 +08:00
|
|
|
# Distribution-specific logic
|
2017-05-06 05:04:33 +08:00
|
|
|
if [[ -f /etc/redhat-release ]] || [[ -f /etc/SuSE-release ]]; then
|
2016-01-08 23:47:09 +08:00
|
|
|
# RHEL-variant logic
|
2017-04-21 02:19:33 +08:00
|
|
|
if [[ "$(readlink /proc/1/exe)" == */systemd ]]; then
|
2017-05-06 05:04:33 +08:00
|
|
|
install_systemd /usr/lib/systemd/system/telegraf.service
|
2016-01-08 23:47:09 +08:00
|
|
|
else
|
2017-04-21 02:19:33 +08: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 23:47:09 +08:00
|
|
|
fi
|
2016-01-26 05:19:51 +08:00
|
|
|
elif [[ -f /etc/os-release ]]; then
|
|
|
|
|
source /etc/os-release
|
2019-02-07 08:17:11 +08: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-06 05:29:40 +08:00
|
|
|
# Amazon Linux logic
|
2017-04-21 02:19:33 +08: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
|
2020-06-03 14:20:45 +08:00
|
|
|
elif [[ "$NAME" = "Solus" ]]; then
|
|
|
|
|
# Solus logic
|
|
|
|
|
install_systemd /usr/lib/systemd/system/telegraf.service
|
2016-01-26 05:19:51 +08:00
|
|
|
fi
|
2016-01-08 23:47:09 +08:00
|
|
|
fi
|