Skip to content
Open
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
25 changes: 23 additions & 2 deletions src/systemd/rb-exporter
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/bash
# $Id$
#
# rb-exporter Start/Stop the rb-exporter daemon.
Expand Down Expand Up @@ -31,6 +31,7 @@ SYSTEMCTL_SKIP_REDIRECT=true


RETVAL=0
STARTED_ANY=0
prog="pmacctd"
binary=/usr/sbin/pmacctd

Expand All @@ -42,21 +43,35 @@ set_lock_file() {
lockfile=/var/lock/rb-exporter-$1
}

cleanup_stale_state() {
if [ -f "$pidfile" ]; then
PID=$(cat "$pidfile")
if [ -n "$PID" ] && ! kill -0 "$PID" 2>/dev/null; then
echo "Found stale pidfile for $prog on $iface (PID $PID not running), cleaning up"
rm -f "$pidfile"
rm -f "$lockfile"
fi
fi
}

start() {

cleanup_stale_state

if [ -d /etc/rb-exporter/$iface -a -f /etc/rb-exporter/$iface/rb-exporter.conf ]; then
OPTIONS="-i ${iface} -F ${pidfile} -f /etc/rb-exporter/$iface/rb-exporter.conf"
[ -x $binary ] || exit 5
echo -n $"Starting $prog: on $iface "
daemon --pidfile=$pidfile $binary $OPTIONS
RETVAL=$?
[ $RETVAL -eq 0 ] && STARTED_ANY=1
[ $RETVAL -eq 0 ] && touch $lockfile
echo
return $RETVAL
else
echo "no config file for $prog on $iface"
echo
return 0
return 1
fi

}
Expand Down Expand Up @@ -176,5 +191,11 @@ do
esac

done

if [ "$1" = "start" ] && [ "$STARTED_ANY" -eq 0 ]; then
echo "rb-exporter: no pmacctd instances were started"
exit 1
fi

# echo $"RETVAL IS $RETVAL"
exit $RETVAL
4 changes: 2 additions & 2 deletions src/systemd/rb-exporter.service
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ Type=forking
TimeoutSec=30
IgnoreSIGPIPE=no
GuessMainPID=no
RemainAfterExit=yes
#RemainAfterExit=yes
Restart=no
KillMode=process

ExecStart=/etc/rc.d/init.d/rb-exporter start
ExecStop=/etc/rc.d/init.d/rb-exporter stop
ExecStop=/etc/rc.d/init.d/rb-exporter stop