-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed install/remove of telegraf on non-systemd Debian/Ubuntu systems #2360
Changes from all commits
23ad6b3
61307f8
59287ff
fb4ea0a
0f349da
3539da8
a0f0990
4577a14
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,10 +24,8 @@ function install_chkconfig { | |
chkconfig --add telegraf | ||
} | ||
|
||
id telegraf &>/dev/null | ||
if [[ $? -ne 0 ]]; then | ||
grep "^telegraf:" /etc/group &>/dev/null | ||
if [[ $? -ne 0 ]]; then | ||
if ! id telegraf &>/dev/null; then | ||
if ! grep "^telegraf:" /etc/group &>/dev/null; then | ||
useradd -r -K USERGROUPS_ENAB=yes -M telegraf -s /bin/false -d /etc/telegraf | ||
else | ||
useradd -r -K USERGROUPS_ENAB=yes -M telegraf -s /bin/false -d /etc/telegraf -g telegraf | ||
|
@@ -60,31 +58,44 @@ fi | |
# Distribution-specific logic | ||
if [[ -f /etc/redhat-release ]]; then | ||
# RHEL-variant logic | ||
which systemctl &>/dev/null | ||
if [[ $? -eq 0 ]]; then | ||
install_systemd | ||
if [[ "$(readlink /proc/1/exe)" == */systemd ]]; then | ||
install_systemd | ||
else | ||
# Assuming sysv | ||
install_init | ||
install_chkconfig | ||
# 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 | ||
which systemctl &>/dev/null | ||
if [[ $? -eq 0 ]]; then | ||
install_systemd | ||
systemctl restart telegraf || echo "WARNING: systemd not running." | ||
if [[ "$(readlink /proc/1/exe)" == */systemd ]]; then | ||
install_systemd | ||
systemctl restart telegraf || echo "WARNING: systemd not running." | ||
else | ||
# Assuming sysv | ||
install_init | ||
install_update_rcd | ||
invoke-rc.d telegraf restart | ||
# 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why would we try this on debian? It looks like debian does have chkconfig, but the last version it was packaged for was jessie. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See above. You shouldn't depend on users only using Debian or Ubuntu. There are a ton of derivates which can use either update-rc.d or chkconfig, so this script should be as flexible as possible. what's you real problem here? i made it really flexible and tested it on several distributions (debian and non-debian) that it works. and it does perfectly. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, so if we want to add support for chkconfig here we should also support it in the post-remove script. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're totally right, it's missing there. I'll rework the script and add support for it. Should be an easy quick fix. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @danielnelson chkconfig support for debian based systems in post-remove.sh has now been added |
||
fi | ||
invoke-rc.d telegraf restart | ||
fi | ||
elif [[ -f /etc/os-release ]]; then | ||
source /etc/os-release | ||
if [[ $ID = "amzn" ]]; then | ||
# Amazon Linux logic | ||
install_init | ||
install_chkconfig | ||
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,16 @@ | ||
#!/bin/bash | ||
|
||
if [[ -f /etc/opt/telegraf/telegraf.conf ]]; then | ||
if [[ -d /etc/opt/telegraf ]]; then | ||
# Legacy configuration found | ||
if [[ ! -d /etc/telegraf ]]; then | ||
# New configuration does not exist, move legacy configuration to new location | ||
echo -e "Please note, Telegraf's configuration is now located at '/etc/telegraf' (previously '/etc/opt/telegraf')." | ||
mv /etc/opt/telegraf /etc/telegraf | ||
# New configuration does not exist, move legacy configuration to new location | ||
echo -e "Please note, Telegraf's configuration is now located at '/etc/telegraf' (previously '/etc/opt/telegraf')." | ||
mv -vn /etc/opt/telegraf /etc/telegraf | ||
|
||
backup_name="telegraf.conf.$(date +%s).backup" | ||
echo "A backup of your current configuration can be found at: /etc/telegraf/$backup_name" | ||
cp -a /etc/telegraf/telegraf.conf /etc/telegraf/$backup_name | ||
if [[ -f /etc/telegraf/telegraf.conf ]]; then | ||
backup_name="telegraf.conf.$(date +%s).backup" | ||
echo "A backup of your current configuration can be found at: /etc/telegraf/${backup_name}" | ||
cp -a "/etc/telegraf/telegraf.conf" "/etc/telegraf/${backup_name}" | ||
fi | ||
fi | ||
fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we try this? I expect redhat would never have these scripts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because we don't know on which Debian-Derivate the .deb package is being executed on later and so you don't know if it uses update-rc.d or chkconfig in advance. this is why we need both (so this .deb package can be run on as most distros as possible!)