Fixed install/remove of telegraf on non-systemd Debian/Ubuntu systems (#2360)

This commit is contained in:
Martin 2017-04-20 20:19:33 +02:00 committed by Daniel Nelson
parent 7e07d17b64
commit c0daa68e00
5 changed files with 81 additions and 51 deletions

View File

@ -85,6 +85,7 @@ be deprecated eventually.
- [#2356](https://github.com/influxdata/telegraf/issues/2356): cpu input panic when /proc/stat is empty. - [#2356](https://github.com/influxdata/telegraf/issues/2356): cpu input panic when /proc/stat is empty.
- [#2341](https://github.com/influxdata/telegraf/issues/2341): telegraf swallowing panics in --test mode. - [#2341](https://github.com/influxdata/telegraf/issues/2341): telegraf swallowing panics in --test mode.
- [#2358](https://github.com/influxdata/telegraf/pull/2358): Create pidfile with 644 permissions & defer file deletion. - [#2358](https://github.com/influxdata/telegraf/pull/2358): Create pidfile with 644 permissions & defer file deletion.
- [#2360](https://github.com/influxdata/telegraf/pull/2360): Fixed install/remove of telegraf on non-systemd Debian/Ubuntu systems
- [#2282](https://github.com/influxdata/telegraf/issues/2282): Reloading telegraf freezes prometheus output. - [#2282](https://github.com/influxdata/telegraf/issues/2282): Reloading telegraf freezes prometheus output.
- [#2390](https://github.com/influxdata/telegraf/issues/2390): Empty tag value causes error on InfluxDB output. - [#2390](https://github.com/influxdata/telegraf/issues/2390): Empty tag value causes error on InfluxDB output.
- [#2380](https://github.com/influxdata/telegraf/issues/2380): buffer_size field value is negative number from "internal" plugin. - [#2380](https://github.com/influxdata/telegraf/issues/2380): buffer_size field value is negative number from "internal" plugin.

View File

@ -24,10 +24,8 @@ function install_chkconfig {
chkconfig --add telegraf chkconfig --add telegraf
} }
id telegraf &>/dev/null if ! id telegraf &>/dev/null; then
if [[ $? -ne 0 ]]; then if ! grep "^telegraf:" /etc/group &>/dev/null; then
grep "^telegraf:" /etc/group &>/dev/null
if [[ $? -ne 0 ]]; then
useradd -r -K USERGROUPS_ENAB=yes -M telegraf -s /bin/false -d /etc/telegraf useradd -r -K USERGROUPS_ENAB=yes -M telegraf -s /bin/false -d /etc/telegraf
else else
useradd -r -K USERGROUPS_ENAB=yes -M telegraf -s /bin/false -d /etc/telegraf -g telegraf useradd -r -K USERGROUPS_ENAB=yes -M telegraf -s /bin/false -d /etc/telegraf -g telegraf
@ -60,31 +58,44 @@ fi
# Distribution-specific logic # Distribution-specific logic
if [[ -f /etc/redhat-release ]]; then if [[ -f /etc/redhat-release ]]; then
# RHEL-variant logic # RHEL-variant logic
which systemctl &>/dev/null if [[ "$(readlink /proc/1/exe)" == */systemd ]]; then
if [[ $? -eq 0 ]]; then install_systemd
install_systemd
else else
# Assuming sysv # Assuming SysVinit
install_init install_init
install_chkconfig # 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
fi fi
elif [[ -f /etc/debian_version ]]; then elif [[ -f /etc/debian_version ]]; then
# Debian/Ubuntu logic # Debian/Ubuntu logic
which systemctl &>/dev/null if [[ "$(readlink /proc/1/exe)" == */systemd ]]; then
if [[ $? -eq 0 ]]; then install_systemd
install_systemd systemctl restart telegraf || echo "WARNING: systemd not running."
systemctl restart telegraf || echo "WARNING: systemd not running."
else else
# Assuming sysv # Assuming SysVinit
install_init install_init
install_update_rcd # Run update-rc.d or fallback to chkconfig if not available
invoke-rc.d telegraf restart if which update-rc.d &>/dev/null; then
install_update_rcd
else
install_chkconfig
fi
invoke-rc.d telegraf restart
fi fi
elif [[ -f /etc/os-release ]]; then elif [[ -f /etc/os-release ]]; then
source /etc/os-release source /etc/os-release
if [[ $ID = "amzn" ]]; then if [[ $ID = "amzn" ]]; then
# Amazon Linux logic # Amazon Linux logic
install_init install_init
install_chkconfig # 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
fi fi
fi fi

View File

@ -15,28 +15,45 @@ function disable_chkconfig {
rm -f /etc/init.d/telegraf rm -f /etc/init.d/telegraf
} }
if [[ "$1" == "0" ]]; then if [[ -f /etc/redhat-release ]]; then
# RHEL and any distribution that follow RHEL, Amazon Linux covered # RHEL-variant logic
# telegraf is no longer installed, remove from init system if [[ "$1" = "0" ]]; then
rm -f /etc/default/telegraf # InfluxDB is no longer installed, remove from init system
rm -f /etc/default/telegraf
which systemctl &>/dev/null if [[ "$(readlink /proc/1/exe)" == */systemd ]]; then
if [[ $? -eq 0 ]]; then disable_systemd
disable_systemd else
else # Assuming sysv
# Assuming sysv disable_chkconfig
disable_chkconfig fi
fi fi
elif [ "$1" == "remove" -o "$1" == "purge" ]; then elif [[ -f /etc/debian_version ]]; then
# Debian/Ubuntu logic # Debian/Ubuntu logic
# Remove/purge if [ "$1" == "remove" -o "$1" == "purge" ]; then
rm -f /etc/default/telegraf # Remove/purge
rm -f /etc/default/telegraf
which systemctl &>/dev/null if [[ "$(readlink /proc/1/exe)" == */systemd ]]; then
if [[ $? -eq 0 ]]; then disable_systemd
disable_systemd else
else # Assuming sysv
# Assuming sysv # Run update-rc.d or fallback to chkconfig if not available
disable_update_rcd if which update-rc.d &>/dev/null; then
disable_update_rcd
else
disable_chkconfig
fi
fi
fi
elif [[ -f /etc/os-release ]]; then
source /etc/os-release
if [[ $ID = "amzn" ]]; then
# Amazon Linux logic
if [[ "$1" = "0" ]]; then
# InfluxDB is no longer installed, remove from init system
rm -f /etc/default/telegraf
disable_chkconfig
fi
fi fi
fi fi

View File

@ -1,14 +1,16 @@
#!/bin/bash #!/bin/bash
if [[ -f /etc/opt/telegraf/telegraf.conf ]]; then if [[ -d /etc/opt/telegraf ]]; then
# Legacy configuration found # Legacy configuration found
if [[ ! -d /etc/telegraf ]]; then if [[ ! -d /etc/telegraf ]]; then
# New configuration does not exist, move legacy configuration to new location # New configuration does not exist, move legacy configuration to new location
echo -e "Please note, Telegraf's configuration is now located at '/etc/telegraf' (previously '/etc/opt/telegraf')." echo -e "Please note, Telegraf's configuration is now located at '/etc/telegraf' (previously '/etc/opt/telegraf')."
mv /etc/opt/telegraf /etc/telegraf mv -vn /etc/opt/telegraf /etc/telegraf
backup_name="telegraf.conf.$(date +%s).backup" if [[ -f /etc/telegraf/telegraf.conf ]]; then
echo "A backup of your current configuration can be found at: /etc/telegraf/$backup_name" backup_name="telegraf.conf.$(date +%s).backup"
cp -a /etc/telegraf/telegraf.conf /etc/telegraf/$backup_name echo "A backup of your current configuration can be found at: /etc/telegraf/${backup_name}"
cp -a "/etc/telegraf/telegraf.conf" "/etc/telegraf/${backup_name}"
fi
fi fi
fi fi

View File

@ -5,11 +5,10 @@ BIN_DIR=/usr/bin
# Distribution-specific logic # Distribution-specific logic
if [[ -f /etc/debian_version ]]; then if [[ -f /etc/debian_version ]]; then
# Debian/Ubuntu logic # Debian/Ubuntu logic
which systemctl &>/dev/null if [[ "$(readlink /proc/1/exe)" == */systemd ]]; then
if [[ $? -eq 0 ]]; then deb-systemd-invoke stop telegraf.service
deb-systemd-invoke stop telegraf.service
else else
# Assuming sysv # Assuming sysv
invoke-rc.d telegraf stop invoke-rc.d telegraf stop
fi fi
fi fi