Improved install script for packaged telegraf:

* Start/stop service on Debian/Ubuntu
* Disable init-script/Systemd-unit on package removal

closes #747
This commit is contained in:
Pierre Fersing 2016-02-23 18:25:07 +01:00 committed by Cameron Sparr
parent 035e4cf90a
commit e4e7d7fbfc
4 changed files with 70 additions and 0 deletions

View File

@ -31,6 +31,8 @@ DEFAULT_CONFIG = "etc/telegraf.conf"
DEFAULT_WINDOWS_CONFIG = "etc/telegraf_windows.conf" DEFAULT_WINDOWS_CONFIG = "etc/telegraf_windows.conf"
POSTINST_SCRIPT = "scripts/post-install.sh" POSTINST_SCRIPT = "scripts/post-install.sh"
PREINST_SCRIPT = "scripts/pre-install.sh" PREINST_SCRIPT = "scripts/pre-install.sh"
POSTREMOVE_SCRIPT = "scripts/post-remove.sh"
PREREMOVE_SCRIPT = "scripts/pre-remove.sh"
# Default AWS S3 bucket for uploads # Default AWS S3 bucket for uploads
DEFAULT_BUCKET = "get.influxdb.org/telegraf" DEFAULT_BUCKET = "get.influxdb.org/telegraf"
@ -61,6 +63,8 @@ fpm_common_args = "-f -s dir --log error \
--config-files {} \ --config-files {} \
--after-install {} \ --after-install {} \
--before-install {} \ --before-install {} \
--after-remove {} \
--before-remove {} \
--description \"{}\"".format( --description \"{}\"".format(
VENDOR, VENDOR,
PACKAGE_URL, PACKAGE_URL,
@ -70,6 +74,8 @@ fpm_common_args = "-f -s dir --log error \
LOGROTATE_DIR + '/telegraf', LOGROTATE_DIR + '/telegraf',
POSTINST_SCRIPT, POSTINST_SCRIPT,
PREINST_SCRIPT, PREINST_SCRIPT,
POSTREMOVE_SCRIPT,
PREREMOVE_SCRIPT,
DESCRIPTION) DESCRIPTION)
targets = { targets = {

View File

@ -13,6 +13,7 @@ function install_init {
function install_systemd { function install_systemd {
cp -f $SCRIPT_DIR/telegraf.service /lib/systemd/system/telegraf.service cp -f $SCRIPT_DIR/telegraf.service /lib/systemd/system/telegraf.service
systemctl enable telegraf systemctl enable telegraf
systemctl daemon-reload || true
} }
function install_update_rcd { function install_update_rcd {
@ -63,10 +64,12 @@ elif [[ -f /etc/debian_version ]]; then
which systemctl &>/dev/null which systemctl &>/dev/null
if [[ $? -eq 0 ]]; then if [[ $? -eq 0 ]]; then
install_systemd install_systemd
deb-systemd-invoke restart telegraf.service
else else
# Assuming sysv # Assuming sysv
install_init install_init
install_update_rcd install_update_rcd
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

46
scripts/post-remove.sh Normal file
View File

@ -0,0 +1,46 @@
#!/bin/bash
function disable_systemd {
systemctl disable telegraf
rm -f /lib/systemd/system/telegraf.service
}
function disable_update_rcd {
update-rc.d -f telegraf remove
rm -f /etc/init.d/telegraf
}
function disable_chkconfig {
chkconfig --del telegraf
rm -f /etc/init.d/telegraf
}
if [[ -f /etc/redhat-release ]]; then
# RHEL-variant logic
if [[ "$1" = "0" ]]; then
# InfluxDB is no longer installed, remove from init system
rm -f /etc/default/telegraf
which systemctl &>/dev/null
if [[ $? -eq 0 ]]; then
disable_systemd
else
# Assuming sysv
disable_chkconfig
fi
fi
elif [[ -f /etc/debian_version ]]; then
# Debian/Ubuntu logic
if [[ "$1" != "upgrade" ]]; then
# Remove/purge
rm -f /etc/default/telegraf
which systemctl &>/dev/null
if [[ $? -eq 0 ]]; then
disable_systemd
else
# Assuming sysv
disable_update_rcd
fi
fi
fi

15
scripts/pre-remove.sh Normal file
View File

@ -0,0 +1,15 @@
#!/bin/bash
BIN_DIR=/usr/bin
# Distribution-specific logic
if [[ -f /etc/debian_version ]]; then
# Debian/Ubuntu logic
which systemctl &>/dev/null
if [[ $? -eq 0 ]]; then
deb-systemd-invoke stop telegraf.service
else
# Assuming sysv
invoke-rc.d telegraf stop
fi
fi