fix: use os-agnositc systemd detection, remove sysv in RPM packaging (#10570)
This commit is contained in:
parent
1dc617ebdd
commit
a91ea982b2
|
|
@ -1,29 +1,5 @@
|
||||||
#!/bin/bash
|
#!/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 $1
|
|
||||||
systemctl enable telegraf || true
|
|
||||||
systemctl daemon-reload || true
|
|
||||||
}
|
|
||||||
|
|
||||||
function install_update_rcd {
|
|
||||||
update-rc.d telegraf defaults
|
|
||||||
}
|
|
||||||
|
|
||||||
function install_chkconfig {
|
|
||||||
chkconfig --add telegraf
|
|
||||||
}
|
|
||||||
|
|
||||||
# Remove legacy symlink, if it exists
|
# Remove legacy symlink, if it exists
|
||||||
if [[ -L /etc/init.d/telegraf ]]; then
|
if [[ -L /etc/init.d/telegraf ]]; then
|
||||||
rm -f /etc/init.d/telegraf
|
rm -f /etc/init.d/telegraf
|
||||||
|
|
@ -48,41 +24,16 @@ if [[ ! -f /etc/telegraf/telegraf.conf ]] && [[ -f /etc/telegraf/telegraf.conf.s
|
||||||
cp /etc/telegraf/telegraf.conf.sample /etc/telegraf/telegraf.conf
|
cp /etc/telegraf/telegraf.conf.sample /etc/telegraf/telegraf.conf
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Set up log directories
|
||||||
|
LOG_DIR=/var/log/telegraf
|
||||||
test -d $LOG_DIR || mkdir -p $LOG_DIR
|
test -d $LOG_DIR || mkdir -p $LOG_DIR
|
||||||
chown -R -L telegraf:telegraf $LOG_DIR
|
chown -R -L telegraf:telegraf $LOG_DIR
|
||||||
chmod 755 $LOG_DIR
|
chmod 755 $LOG_DIR
|
||||||
|
|
||||||
# Distribution-specific logic
|
# Set up systemd service - check if the systemd directory exists per:
|
||||||
if [[ -f /etc/redhat-release ]] || [[ -f /etc/SuSE-release ]]; then
|
# https://www.freedesktop.org/software/systemd/man/sd_booted.html
|
||||||
# RHEL-variant logic
|
if [[ -d /run/systemd/system ]]; then
|
||||||
if [[ "$(readlink /proc/1/exe)" == */systemd ]]; then
|
cp -f /usr/lib/telegraf/scripts/telegraf.service /usr/lib/systemd/system/telegraf.service
|
||||||
install_systemd /usr/lib/systemd/system/telegraf.service
|
systemctl enable telegraf
|
||||||
else
|
systemctl daemon-reload
|
||||||
# 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
|
|
||||||
fi
|
|
||||||
elif [[ -f /etc/os-release ]]; then
|
|
||||||
source /etc/os-release
|
|
||||||
if [[ "$NAME" = "Amazon Linux" ]]; then
|
|
||||||
# Amazon Linux 2+ logic
|
|
||||||
install_systemd /usr/lib/systemd/system/telegraf.service
|
|
||||||
elif [[ "$NAME" = "Amazon Linux AMI" ]]; then
|
|
||||||
# Amazon Linux logic
|
|
||||||
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
|
|
||||||
elif [[ "$NAME" = "Solus" ]]; then
|
|
||||||
# Solus logic
|
|
||||||
install_systemd /usr/lib/systemd/system/telegraf.service
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
|
||||||
|
|
@ -1,55 +1,19 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
function disable_systemd {
|
# Telegraf is no longer installed, remove from systemd
|
||||||
systemctl disable telegraf
|
if [[ "$1" = "0" ]]; then
|
||||||
rm -f $1
|
rm -f /etc/default/telegraf
|
||||||
}
|
|
||||||
|
|
||||||
function disable_update_rcd {
|
if [[ -d /run/systemd/system ]]; then
|
||||||
update-rc.d -f telegraf remove
|
systemctl disable telegraf
|
||||||
rm -f /etc/init.d/telegraf
|
rm -f /usr/lib/systemd/system/telegraf.service
|
||||||
}
|
systemctl daemon-reload
|
||||||
|
fi
|
||||||
function disable_chkconfig {
|
fi
|
||||||
chkconfig --del telegraf
|
|
||||||
rm -f /etc/init.d/telegraf
|
# Telegraf upgrade, restart service
|
||||||
}
|
if [[ $1 -ge 1 ]]; then
|
||||||
|
if [[ -d /run/systemd/system ]]; then
|
||||||
if [[ -f /etc/redhat-release ]] || [[ -f /etc/SuSE-release ]]; then
|
systemctl try-restart telegraf.service >/dev/null 2>&1 || :
|
||||||
# RHEL-variant logic
|
|
||||||
if [[ "$1" = "0" ]]; then
|
|
||||||
# InfluxDB is no longer installed, remove from init system
|
|
||||||
rm -f /etc/default/telegraf
|
|
||||||
|
|
||||||
if [[ "$(readlink /proc/1/exe)" == */systemd ]]; then
|
|
||||||
disable_systemd /usr/lib/systemd/system/telegraf.service
|
|
||||||
else
|
|
||||||
# Assuming sysv
|
|
||||||
disable_chkconfig
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
if [[ $1 -ge 1 ]]; then
|
|
||||||
# Package upgrade, not uninstall
|
|
||||||
|
|
||||||
if [[ "$(readlink /proc/1/exe)" == */systemd ]]; then
|
|
||||||
systemctl try-restart telegraf.service >/dev/null 2>&1 || :
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
elif [[ -f /etc/os-release ]]; then
|
|
||||||
source /etc/os-release
|
|
||||||
if [[ "$ID" = "amzn" ]] && [[ "$1" = "0" ]]; then
|
|
||||||
# InfluxDB is no longer installed, remove from init system
|
|
||||||
rm -f /etc/default/telegraf
|
|
||||||
|
|
||||||
if [[ "$NAME" = "Amazon Linux" ]]; then
|
|
||||||
# Amazon Linux 2+ logic
|
|
||||||
disable_systemd /usr/lib/systemd/system/telegraf.service
|
|
||||||
elif [[ "$NAME" = "Amazon Linux AMI" ]]; then
|
|
||||||
# Amazon Linux logic
|
|
||||||
disable_chkconfig
|
|
||||||
fi
|
|
||||||
elif [[ "$NAME" = "Solus" ]]; then
|
|
||||||
rm -f /etc/default/telegraf
|
|
||||||
disable_systemd /usr/lib/systemd/system/telegraf.service
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue