Skip to content

Commit

Permalink
Improved install script for packaged telegraf:
Browse files Browse the repository at this point in the history
* Start/stop service on Debian/Ubuntu
* Disable init-script/Systemd-unit on package removal
  • Loading branch information
PierreF committed Mar 16, 2016
1 parent 18fff4a commit f0252fb
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 0 deletions.
6 changes: 6 additions & 0 deletions scripts/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
DEFAULT_WINDOWS_CONFIG = "etc/telegraf_windows.conf"
POSTINST_SCRIPT = "scripts/post-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_BUCKET = "get.influxdb.org/telegraf"
Expand Down Expand Up @@ -61,6 +63,8 @@
--config-files {} \
--after-install {} \
--before-install {} \
--after-remove {} \
--before-remove {} \
--description \"{}\"".format(
VENDOR,
PACKAGE_URL,
Expand All @@ -70,6 +74,8 @@
LOGROTATE_DIR + '/telegraf',
POSTINST_SCRIPT,
PREINST_SCRIPT,
POSTREMOVE_SCRIPT,
PREREMOVE_SCRIPT,
DESCRIPTION)

targets = {
Expand Down
3 changes: 3 additions & 0 deletions scripts/post-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ function install_init {
function install_systemd {
cp -f $SCRIPT_DIR/telegraf.service /lib/systemd/system/telegraf.service
systemctl enable telegraf
systemctl daemon-reload || true
}

function install_update_rcd {
Expand Down Expand Up @@ -63,10 +64,12 @@ elif [[ -f /etc/debian_version ]]; then
which systemctl &>/dev/null
if [[ $? -eq 0 ]]; then
install_systemd
deb-systemd-invoke restart telegraf.service
else
# Assuming sysv
install_init
install_update_rcd
invoke-rc.d telegraf restart
fi
elif [[ -f /etc/os-release ]]; then
source /etc/os-release
Expand Down
46 changes: 46 additions & 0 deletions scripts/post-remove.sh
Original file line number Diff line number Diff line change
@@ -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 changes: 15 additions & 0 deletions scripts/pre-remove.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit f0252fb

Please sign in to comment.