Skip to content

Commit

Permalink
Fixed install/remove of kapacitor on non-systemd Debian/Ubuntu systems
Browse files Browse the repository at this point in the history
Also added distribution-specific install/remove logic with code copied from telegraf/influxdb scripts. For more rationale, see: influxdata/telegraf#2360
  • Loading branch information
martinseener authored and nathanielc committed Nov 8, 2017
1 parent 15d9a38 commit ac36203
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 27 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ For more details on the alerting system see the full documentation [here](https:
### Bugfixes

- [#1323](https://github.com/influxdata/kapacitor/pull/1323): Fix issue where credentials to InfluxDB could not be updated dynamically.
- [#1161](https://github.com/influxdata/kapacitor/pull/1161): Fixed install/remove of kapacitor on non-systemd Debian/Ubuntu systems

## v1.2.0 [2017-01-23]

Expand Down
75 changes: 60 additions & 15 deletions scripts/post-install.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,30 @@
#!/bin/sh
#!/bin/bash

BIN_DIR=/usr/bin
DATA_DIR=/var/lib/kapacitor
LOG_DIR=/var/log/kapacitor
SCRIPT_DIR=/usr/lib/kapacitor/scripts

function install_init {
cp -f $SCRIPT_DIR/init.sh /etc/init.d/kapacitor
chmod +x /etc/init.d/kapacitor
}

function install_systemd {
cp -f $SCRIPT_DIR/kapacitor.service /lib/systemd/system/kapacitor.service
systemctl enable kapacitor
}

function install_update_rcd {
update-rc.d kapacitor defaults
}

function install_chkconfig {
chkconfig --add kapacitor
}

if ! id kapacitor >/dev/null 2>&1; then
useradd --system -U -M kapacitor -s /bin/false -d $DATA_DIR
useradd --system -U -M kapacitor -s /bin/false -d $DATA_DIR
fi
chmod a+rX $BIN_DIR/kapacitor*

Expand All @@ -16,19 +35,45 @@ chown -R -L kapacitor:kapacitor $DATA_DIR

test -f /etc/default/kapacitor || touch /etc/default/kapacitor

# Systemd
if which systemctl > /dev/null 2>&1 ; then
cp -f $SCRIPT_DIR/kapacitor.service /lib/systemd/system/kapacitor.service
systemctl enable kapacitor

# Sysv
else
cp -f $SCRIPT_DIR/init.sh /etc/init.d/kapacitor
chmod +x /etc/init.d/kapacitor
if which update-rc.d > /dev/null 2>&1 ; then
update-rc.d -f kapacitor remove
update-rc.d kapacitor defaults
# Distribution-specific logic
if [[ -f /etc/redhat-release ]]; then
# RHEL-variant logic
if [[ "$(readlink /proc/1/exe)" == */systemd ]]; then
install_systemd
else
# 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/debian_version ]]; then
# Debian/Ubuntu logic
if [[ "$(readlink /proc/1/exe)" == */systemd ]]; then
install_systemd
else
chkconfig --add kapacitor
# 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 [[ $ID = "amzn" ]]; 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
fi
fi
61 changes: 49 additions & 12 deletions scripts/post-uninstall.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,54 @@
#!/bin/sh
#!/bin/bash

rm -f /etc/default/kapacitor

# Systemd
if which systemctl > /dev/null 2>&1 ; then
function disable_systemd {
systemctl disable kapacitor
rm -f /lib/systemd/system/kapacitor.service
# Sysv
else
if which update-rc.d > /dev/null 2>&1 ; then
update-rc.d -f kapacitor remove
else
chkconfig --del kapacitor
fi
}

function disable_update_rcd {
update-rc.d kapacitor remove
rm -f /etc/init.d/kapacitor
}

function disable_chkconfig {
chkconfig --del kapacitor
rm -f /etc/init.d/kapacitor
}

if [[ -f /etc/redhat-release ]]; then
# RHEL-variant logic
if [[ "$1" = "0" ]]; then
# Kapacitor is no longer installed, remove from init system
rm -f /etc/default/kapacitor

if [[ "$(readlink /proc/1/exe)" == */systemd ]]; 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/kapacitor

if [[ "$(readlink /proc/1/exe)" == */systemd ]]; then
disable_systemd
else
# Assuming sysv
disable_update_rcd
fi
fi
elif [[ -f /etc/os-release ]]; then
source /etc/os-release
if [[ $ID = "amzn" ]]; then
# Amazon Linux logic
if [[ "$1" = "0" ]]; then
# Kapacitor is no longer installed, remove from init system
rm -f /etc/default/kapacitor
disable_chkconfig
fi
fi
fi

0 comments on commit ac36203

Please sign in to comment.