Skip to content

Commit 36d4dd0

Browse files
martinseenerVladislav Mugultyanov (Lazada Group)
authored andcommitted
Fixed install/remove of telegraf on non-systemd Debian/Ubuntu systems (influxdata#2360)
1 parent 54a3d56 commit 36d4dd0

File tree

5 files changed

+81
-51
lines changed

5 files changed

+81
-51
lines changed

CHANGELOG.md

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

scripts/post-install.sh

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,8 @@ function install_chkconfig {
2424
chkconfig --add telegraf
2525
}
2626

27-
id telegraf &>/dev/null
28-
if [[ $? -ne 0 ]]; then
29-
grep "^telegraf:" /etc/group &>/dev/null
30-
if [[ $? -ne 0 ]]; then
27+
if ! id telegraf &>/dev/null; then
28+
if ! grep "^telegraf:" /etc/group &>/dev/null; then
3129
useradd -r -K USERGROUPS_ENAB=yes -M telegraf -s /bin/false -d /etc/telegraf
3230
else
3331
useradd -r -K USERGROUPS_ENAB=yes -M telegraf -s /bin/false -d /etc/telegraf -g telegraf
@@ -60,31 +58,44 @@ fi
6058
# Distribution-specific logic
6159
if [[ -f /etc/redhat-release ]]; then
6260
# RHEL-variant logic
63-
which systemctl &>/dev/null
64-
if [[ $? -eq 0 ]]; then
65-
install_systemd
61+
if [[ "$(readlink /proc/1/exe)" == */systemd ]]; then
62+
install_systemd
6663
else
67-
# Assuming sysv
68-
install_init
69-
install_chkconfig
64+
# Assuming SysVinit
65+
install_init
66+
# Run update-rc.d or fallback to chkconfig if not available
67+
if which update-rc.d &>/dev/null; then
68+
install_update_rcd
69+
else
70+
install_chkconfig
71+
fi
7072
fi
7173
elif [[ -f /etc/debian_version ]]; then
7274
# Debian/Ubuntu logic
73-
which systemctl &>/dev/null
74-
if [[ $? -eq 0 ]]; then
75-
install_systemd
76-
systemctl restart telegraf || echo "WARNING: systemd not running."
75+
if [[ "$(readlink /proc/1/exe)" == */systemd ]]; then
76+
install_systemd
77+
systemctl restart telegraf || echo "WARNING: systemd not running."
7778
else
78-
# Assuming sysv
79-
install_init
80-
install_update_rcd
81-
invoke-rc.d telegraf restart
79+
# Assuming SysVinit
80+
install_init
81+
# Run update-rc.d or fallback to chkconfig if not available
82+
if which update-rc.d &>/dev/null; then
83+
install_update_rcd
84+
else
85+
install_chkconfig
86+
fi
87+
invoke-rc.d telegraf restart
8288
fi
8389
elif [[ -f /etc/os-release ]]; then
8490
source /etc/os-release
8591
if [[ $ID = "amzn" ]]; then
8692
# Amazon Linux logic
87-
install_init
88-
install_chkconfig
93+
install_init
94+
# Run update-rc.d or fallback to chkconfig if not available
95+
if which update-rc.d &>/dev/null; then
96+
install_update_rcd
97+
else
98+
install_chkconfig
99+
fi
89100
fi
90101
fi

scripts/post-remove.sh

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,45 @@ function disable_chkconfig {
1515
rm -f /etc/init.d/telegraf
1616
}
1717

18-
if [[ "$1" == "0" ]]; then
19-
# RHEL and any distribution that follow RHEL, Amazon Linux covered
20-
# telegraf is no longer installed, remove from init system
21-
rm -f /etc/default/telegraf
18+
if [[ -f /etc/redhat-release ]]; then
19+
# RHEL-variant logic
20+
if [[ "$1" = "0" ]]; then
21+
# InfluxDB is no longer installed, remove from init system
22+
rm -f /etc/default/telegraf
2223

23-
which systemctl &>/dev/null
24-
if [[ $? -eq 0 ]]; then
25-
disable_systemd
26-
else
27-
# Assuming sysv
28-
disable_chkconfig
24+
if [[ "$(readlink /proc/1/exe)" == */systemd ]]; then
25+
disable_systemd
26+
else
27+
# Assuming sysv
28+
disable_chkconfig
29+
fi
2930
fi
30-
elif [ "$1" == "remove" -o "$1" == "purge" ]; then
31+
elif [[ -f /etc/debian_version ]]; then
3132
# Debian/Ubuntu logic
32-
# Remove/purge
33-
rm -f /etc/default/telegraf
33+
if [ "$1" == "remove" -o "$1" == "purge" ]; then
34+
# Remove/purge
35+
rm -f /etc/default/telegraf
3436

35-
which systemctl &>/dev/null
36-
if [[ $? -eq 0 ]]; then
37-
disable_systemd
38-
else
39-
# Assuming sysv
40-
disable_update_rcd
37+
if [[ "$(readlink /proc/1/exe)" == */systemd ]]; then
38+
disable_systemd
39+
else
40+
# Assuming sysv
41+
# Run update-rc.d or fallback to chkconfig if not available
42+
if which update-rc.d &>/dev/null; then
43+
disable_update_rcd
44+
else
45+
disable_chkconfig
46+
fi
47+
fi
48+
fi
49+
elif [[ -f /etc/os-release ]]; then
50+
source /etc/os-release
51+
if [[ $ID = "amzn" ]]; then
52+
# Amazon Linux logic
53+
if [[ "$1" = "0" ]]; then
54+
# InfluxDB is no longer installed, remove from init system
55+
rm -f /etc/default/telegraf
56+
disable_chkconfig
57+
fi
4158
fi
4259
fi

scripts/pre-install.sh

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
#!/bin/bash
22

3-
if [[ -f /etc/opt/telegraf/telegraf.conf ]]; then
3+
if [[ -d /etc/opt/telegraf ]]; then
44
# Legacy configuration found
55
if [[ ! -d /etc/telegraf ]]; then
6-
# New configuration does not exist, move legacy configuration to new location
7-
echo -e "Please note, Telegraf's configuration is now located at '/etc/telegraf' (previously '/etc/opt/telegraf')."
8-
mv /etc/opt/telegraf /etc/telegraf
6+
# New configuration does not exist, move legacy configuration to new location
7+
echo -e "Please note, Telegraf's configuration is now located at '/etc/telegraf' (previously '/etc/opt/telegraf')."
8+
mv -vn /etc/opt/telegraf /etc/telegraf
99

10-
backup_name="telegraf.conf.$(date +%s).backup"
11-
echo "A backup of your current configuration can be found at: /etc/telegraf/$backup_name"
12-
cp -a /etc/telegraf/telegraf.conf /etc/telegraf/$backup_name
10+
if [[ -f /etc/telegraf/telegraf.conf ]]; then
11+
backup_name="telegraf.conf.$(date +%s).backup"
12+
echo "A backup of your current configuration can be found at: /etc/telegraf/${backup_name}"
13+
cp -a "/etc/telegraf/telegraf.conf" "/etc/telegraf/${backup_name}"
14+
fi
1315
fi
1416
fi

scripts/pre-remove.sh

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@ BIN_DIR=/usr/bin
55
# Distribution-specific logic
66
if [[ -f /etc/debian_version ]]; then
77
# Debian/Ubuntu logic
8-
which systemctl &>/dev/null
9-
if [[ $? -eq 0 ]]; then
10-
deb-systemd-invoke stop telegraf.service
8+
if [[ "$(readlink /proc/1/exe)" == */systemd ]]; then
9+
deb-systemd-invoke stop telegraf.service
1110
else
12-
# Assuming sysv
13-
invoke-rc.d telegraf stop
11+
# Assuming sysv
12+
invoke-rc.d telegraf stop
1413
fi
1514
fi

0 commit comments

Comments
 (0)