Skip to content
jselbie edited this page Mar 16, 2012 · 5 revisions
I just wrote a small RC startup script for STUNT-MAN, works in Debian, should work elsewhere
...  thought this would be  useful to someone.

Thanks to the author of STUNT-MAN for for sharing his knowledge with the community!.
Cheers from Cartagena-Colombia (not ColUmbia) :-) .. pguillem

Copy this to /etc/init.d/stun (don´t forget to chmod 755)
##############################################################

#!/bin/sh
### BEGIN INIT INFO
# Provides:          stun
# Required-Start:    $syslog
# Required-Stop:     $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: STUNT-MAN Stun server Debian RC script
# Description: Provides Start/Stop scripts for STUNT-MAN STUN server
# 
#
### END INIT INFO

#TODO: Test if a secondd IP exists and run simple mode otherwise.
#TODO: Auto detect interfaces
#Requires: "killall" (apt-get install psutils)

#You should chmod the binary to 755 after moving "stunserver" to /usr/sbin
STUN_USER=root
STUN_HOME="/usr/sbin"
STUN_PROG="stunserver"

#CHANGE THIS TO SUIT YOUR ADAPTERS HOLDING THE PUBLIC IPS
ADAPTER1=eth0
ADAPTER2=eth0:1

#No more monkeys from here
###############################################################################
#Get our working IP addresses from the interface names
IPBIND1=$(ifconfig $ADAPTER1 | awk '/inet addr/ {split ($2,A,":"); print A[2]}')
IPBIND2=$(ifconfig $ADAPTER2 | awk '/inet addr/ {split ($2,A,":"); print A[2]}')

# You can also pass $ADAPTER1 and $ADAPTER2 as values for --primaryinterface and --altinterface
# The stunserver program will convert adapter names to ip addresses

test -x "$STUN_HOME/$STUN_PROG" || exit 5

case "$1" in
     start)
         echo -n "Starting STUN Server"
         echo -n " "
         cd $STUN_HOME
         su -s /bin/bash -c "$STUN_HOME/$STUN_PROG --mode full --primaryinterface $IPBIND1 --altinterface $IPBIND2 --verbosity 2&" $STUN_USER
         echo ""
         sleep 2
         ;;
     stop)
         echo -n "Shutting down STUN Server"
         echo -n " "
         su -s /bin/bash -c "killall -q $STUN_USER $STUN_PROG" $STUN_USER
         echo ""
         sleep 2
         ;;
     restart)
         $0 stop
         $0 start
         ;;
esac