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 d87a9bd
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
36 changes: 26 additions & 10 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 @@ -157,16 +158,25 @@ generate_postinstall_script() {
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
# Systemd
if which systemctl > /dev/null 2>&1 ; then
ln -s $INSTALL_ROOT_DIR/versions/$version/scripts/telegraf.service /lib/systemd/system/telegraf.service
systemctl enable telegraf
# Sysv
else
chkconfig --add 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
# 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
fi
if ! id telegraf >/dev/null 2>&1; then
Expand Down Expand Up @@ -213,13 +223,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 d87a9bd

Please sign in to comment.