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 {
|
|
|
|
cp -f $SCRIPT_DIR/telegraf.service /lib/systemd/system/telegraf.service
|
|
|
|
systemctl enable telegraf
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
id telegraf &>/dev/null
|
|
|
|
if [[ $? -ne 0 ]]; then
|
|
|
|
useradd --system -U -M telegraf -s /bin/false -d /etc/telegraf
|
|
|
|
fi
|
|
|
|
|
2016-03-02 17:16:30 +00:00
|
|
|
test -d $LOG_DIR || mkdir -p $LOG_DIR
|
2016-01-08 15:47:09 +00:00
|
|
|
chown -R -L telegraf:telegraf $LOG_DIR
|
2016-03-02 17:16:30 +00:00
|
|
|
chmod 755 $LOG_DIR
|
2016-01-08 15:47:09 +00:00
|
|
|
|
|
|
|
# Remove legacy symlink, if it exists
|
|
|
|
if [[ -L /etc/init.d/telegraf ]]; then
|
|
|
|
rm -f /etc/init.d/telegraf
|
|
|
|
fi
|
|
|
|
|
|
|
|
# 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
|
|
|
|
if [[ -f /etc/redhat-release ]]; then
|
|
|
|
# RHEL-variant logic
|
|
|
|
which systemctl &>/dev/null
|
|
|
|
if [[ $? -eq 0 ]]; then
|
|
|
|
install_systemd
|
|
|
|
else
|
|
|
|
# Assuming sysv
|
|
|
|
install_init
|
|
|
|
install_chkconfig
|
|
|
|
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
|
|
|
|
which systemctl &>/dev/null
|
|
|
|
if [[ $? -eq 0 ]]; then
|
|
|
|
install_systemd
|
2016-02-23 17:25:07 +00:00
|
|
|
deb-systemd-invoke restart telegraf.service
|
2016-01-08 15:47:09 +00:00
|
|
|
else
|
|
|
|
# Assuming sysv
|
|
|
|
install_init
|
|
|
|
install_update_rcd
|
2016-02-23 17:25:07 +00:00
|
|
|
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
|
|
|
|
if [[ $ID = "amzn" ]]; then
|
|
|
|
# Amazon Linux logic
|
|
|
|
install_init
|
|
|
|
install_chkconfig
|
|
|
|
fi
|
2016-01-08 15:47:09 +00:00
|
|
|
fi
|