Skip to content

Commit

Permalink
Update telegraf.service and packaging script for systemd
Browse files Browse the repository at this point in the history
Deals with most of #170
  • Loading branch information
sparrc committed Sep 8, 2015
1 parent 8c5e1ff commit 8717f6b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 13 deletions.
46 changes: 33 additions & 13 deletions package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ LOGROTATE_DIR=/etc/logrotate.d
SAMPLE_CONFIGURATION=etc/config.sample.toml
LOGROTATE_CONFIGURATION=etc/logrotate.d/telegraf
INITD_SCRIPT=scripts/init.sh
SYSTEMD_SCRIPT=scripts/telegraf.service

TMP_WORK_DIR=`mktemp -d`
POST_INSTALL_PATH=`mktemp`
Expand Down Expand Up @@ -156,17 +157,32 @@ generate_postinstall_script() {
cat <<EOF >$POST_INSTALL_PATH
rm -f $INSTALL_ROOT_DIR/telegraf
rm -f $INSTALL_ROOT_DIR/init.sh
ln -s $INSTALL_ROOT_DIR/versions/$version/telegraf $INSTALL_ROOT_DIR/telegraf
ln -s $INSTALL_ROOT_DIR/versions/$version/scripts/init.sh $INSTALL_ROOT_DIR/init.sh
rm -f /etc/init.d/telegraf
ln -sfn $INSTALL_ROOT_DIR/init.sh /etc/init.d/telegraf
chmod +x /etc/init.d/telegraf
if which update-rc.d > /dev/null 2>&1 ; then
update-rc.d -f telegraf remove
update-rc.d telegraf defaults
ln -sfn $INSTALL_ROOT_DIR/versions/$version/telegraf $INSTALL_ROOT_DIR/telegraf
# Systemd
if which systemctl > /dev/null 2>&1 ; then
ln -sfn $INSTALL_ROOT_DIR/versions/$version/scripts/telegraf.service \
/lib/systemd/system/telegraf.service
systemctl enable telegraf
# Sysv
else
chkconfig --add telegraf
ln -sfn $INSTALL_ROOT_DIR/versions/$version/scripts/init.sh \
$INSTALL_ROOT_DIR/init.sh
rm -f /etc/init.d/telegraf
ln -sfn $INSTALL_ROOT_DIR/init.sh /etc/init.d/telegraf
chmod +x /etc/init.d/telegraf
# update-rc.d sysv service:
if which update-rc.d > /dev/null 2>&1 ; then
update-rc.d -f telegraf remove
update-rc.d telegraf defaults
# CentOS-style sysv:
else
chkconfig --add telegraf
fi
mkdir -p $TELEGRAF_LOG_DIR
chown -R -L telegraf:telegraf $TELEGRAF_LOG_DIR
fi
if ! id telegraf >/dev/null 2>&1; then
Expand All @@ -175,8 +191,6 @@ fi
chown -R -L telegraf:telegraf $INSTALL_ROOT_DIR
chmod -R a+rX $INSTALL_ROOT_DIR
mkdir -p $TELEGRAF_LOG_DIR
chown -R -L telegraf:telegraf $TELEGRAF_LOG_DIR
EOF
echo "Post-install script created successfully at $POST_INSTALL_PATH"
}
Expand Down Expand Up @@ -213,13 +227,19 @@ done
echo "${BINS[*]} copied to $TMP_WORK_DIR/$INSTALL_ROOT_DIR/versions/$VERSION"

cp $INITD_SCRIPT $TMP_WORK_DIR/$INSTALL_ROOT_DIR/versions/$VERSION/scripts

if [ $? -ne 0 ]; then
echo "Failed to copy init.d script to packaging directory -- aborting."
cleanup_exit 1
fi
echo "$INITD_SCRIPT copied to $TMP_WORK_DIR/$INSTALL_ROOT_DIR/versions/$VERSION/scripts"

cp $SYSTEMD_SCRIPT $TMP_WORK_DIR/$INSTALL_ROOT_DIR/versions/$VERSION/scripts
if [ $? -ne 0 ]; then
echo "Failed to copy systemd file to packaging directory -- aborting."
cleanup_exit 1
fi
echo "$SYSTEMD_SCRIPT copied to $TMP_WORK_DIR/$INSTALL_ROOT_DIR/versions/$VERSION/scripts"

cp $SAMPLE_CONFIGURATION $TMP_WORK_DIR/$CONFIG_ROOT_DIR/telegraf.conf
if [ $? -ne 0 ]; then
echo "Failed to copy $SAMPLE_CONFIGURATION to packaging directory -- aborting."
Expand Down
2 changes: 2 additions & 0 deletions scripts/telegraf.service
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ EnvironmentFile=-/etc/default/telegraf
User=telegraf
ExecStart=/opt/telegraf/telegraf -config /etc/opt/telegraf/telegraf.conf $TELEGRAF_OPTS
Restart=on-failure
KillMode=process

[Install]
WantedBy=multi-user.target
Alias=telegraf.service

0 comments on commit 8717f6b

Please sign in to comment.