Skip to content
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

Start telegraf after installation on Debian/Ubuntu #747

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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