Reputation: 695
I am wanting to use a startup script that calls up iperf at boot time as well as something that I can specify with the chkconfig utility and just control iperf from the command line as a typical service if I so choose. Here is what I have so far:
#!/bin/bash
# chkconfig: - 50 50
# description: iperf
DAEMON=/usr/bin/iperf
service=iperf
info=$(pidof /usr/bin/iperf)
case "$1" in
start)
$DAEMON -s -D
;;
stop)
pidof $DAEMON | xargs kill -9
;;
status)
if (( $(ps -ef | grep -v grep | grep $service | wc -l) > 0 ))
then
echo $DAEMON pid $info is running!!!
else
echo $DAEMON is NOT running!!!
fi
;;
restart)
$DAEMON stop
$DAEMON start
;;
*)
echo "Usage: $0 {start|stop|status|restart}"
exit 1
;;
esac
Everything works fine so far. I can start and stop the service using the script. I can add it to chkconfig no problems. But I have noticed that even if iperf is not running, when I use the status command it still returns it as running:
With it running:
# service iperf status
/usr/bin/iperf pid 34828 is running!!!
Without it running:
# service iperf status
/usr/bin/iperf pid is running!!!
To this point I have not been able to figure out why this is happening. Can anyone help?
Upvotes: 0
Views: 109
Reputation: 290525
You are checking by saying:
if (( $(ps -ef | grep -v grep | grep $service | wc -l) > 0 ))
And you run the script with:
service iperf status
So my guess is that ps -ef | ... | grep iperf
also finds the call of this script. You can check by printing the output of ps -ef | grep -v grep | grep $service
.
Upvotes: 1