Added a build.py script for compiling and packaging. Added post and pre install scripts to handle installation and upgrades in a cleaner way. Minor fixes to the init script and service unit file.

This commit is contained in:
Ross McDonald
2016-01-08 09:47:09 -06:00
parent fd6daaa73b
commit 07b4a4dbca
7 changed files with 762 additions and 15 deletions

View File

@@ -51,7 +51,6 @@ if [ ! -f "$STDERR" ]; then
mkdir -p `dirname $STDERR`
fi
OPEN_FILE_LIMIT=65536
function pidofproc() {
@@ -98,7 +97,7 @@ function log_success_msg() {
name=telegraf
# Daemon name, where is the actual executable
daemon=/opt/telegraf/telegraf
daemon=/usr/bin/telegraf
# pid file for the daemon
pidfile=/var/run/telegraf/telegraf.pid
@@ -106,12 +105,12 @@ piddir=`dirname $pidfile`
if [ ! -d "$piddir" ]; then
mkdir -p $piddir
chown $GROUP:$USER $piddir
chown $USER:$GROUP $piddir
fi
# Configuration file
config=/etc/opt/telegraf/telegraf.conf
confdir=/etc/opt/telegraf/telegraf.d
config=/etc/telegraf/telegraf.conf
confdir=/etc/telegraf/telegraf.d
# If the daemon is not there, then exit.
[ -x $daemon ] || exit 5
@@ -137,7 +136,7 @@ case $1 in
log_success_msg "Starting the process" "$name"
if which start-stop-daemon > /dev/null 2>&1; then
start-stop-daemon --chuid $GROUP:$USER --start --quiet --pidfile $pidfile --exec $daemon -- -pidfile $pidfile -config $config -config-directory $confdir $TELEGRAF_OPTS >>$STDOUT 2>>$STDERR &
start-stop-daemon --chuid $USER:$GROUP --start --quiet --pidfile $pidfile --exec $daemon -- -pidfile $pidfile -config $config -config-directory $confdir $TELEGRAF_OPTS >>$STDOUT 2>>$STDERR &
else
nohup $daemon -pidfile $pidfile -config $config -config-directory $confdir $TELEGRAF_OPTS >>$STDOUT 2>>$STDERR &
fi

69
scripts/post-install.sh Normal file
View File

@@ -0,0 +1,69 @@
#!/bin/bash
BIN_DIR=/usr/bin
LOG_DIR=/var/log/telegraf
SCRIPT_DIR=/usr/lib/telegraf/scripts
LOGROTATE_DIR=/etc/logrotate.d
function install_init {
cp -f $SCRIPT_DIR/init.sh /etc/init.d/telegraf
chmod +x /etc/init.d/telegraf
}
function install_systemd {
cp -f $SCRIPT_DIR/telegraf.service /lib/systemd/system/telegraf.service
systemctl enable telegraf
}
function install_update_rcd {
update-rc.d telegraf defaults
}
function install_chkconfig {
chkconfig --add telegraf
}
id telegraf &>/dev/null
if [[ $? -ne 0 ]]; then
useradd --system -U -M telegraf -s /bin/false -d /etc/telegraf
fi
chown -R -L telegraf:telegraf $LOG_DIR
# Remove legacy symlink, if it exists
if [[ -L /etc/init.d/telegraf ]]; then
rm -f /etc/init.d/telegraf
fi
# Add defaults file, if it doesn't exist
if [[ ! -f /etc/default/telegraf ]]; then
touch /etc/default/telegraf
fi
# Add .d configuration directory
if [[ ! -d /etc/telegraf/telegraf.d ]]; then
mkdir -p /etc/telegraf/telegraf.d
fi
# Distribution-specific logic
if [[ -f /etc/redhat-release ]]; then
# RHEL-variant logic
which systemctl &>/dev/null
if [[ $? -eq 0 ]]; then
install_systemd
else
# Assuming sysv
install_init
install_chkconfig
fi
elif [[ -f /etc/lsb-release ]]; then
# Debian/Ubuntu logic
which systemctl &>/dev/null
if [[ $? -eq 0 ]]; then
install_systemd
else
# Assuming sysv
install_init
install_update_rcd
fi
fi

14
scripts/pre-install.sh Normal file
View File

@@ -0,0 +1,14 @@
#!/bin/bash
if [[ -f /etc/opt/telegraf/telegraf.conf ]]; 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
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

View File

@@ -6,7 +6,7 @@ After=network.target
[Service]
EnvironmentFile=-/etc/default/telegraf
User=telegraf
ExecStart=/opt/telegraf/telegraf -config /etc/opt/telegraf/telegraf.conf -config-directory /etc/opt/telegraf/telegraf.d $TELEGRAF_OPTS
ExecStart=/usr/bin/telegraf -config /etc/telegraf/telegraf.conf -config-directory /etc/telegraf/telegraf.d ${TELEGRAF_OPTS}
Restart=on-failure
KillMode=process