Created
September 3, 2016 18:08
-
-
Save simonmorley/c7527016d94d431b994f651c6f521b25 to your computer and use it in GitHub Desktop.
OpenWRT init file for coova chilli, including support for multiple coova instances
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/sh | |
### BEGIN INIT INFO | |
# Provides: chilli | |
# Required-Start: $remote_fs $syslog $network | |
# Required-Stop: $remote_fs $syslog $network | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: Start CoovaChilli daemon at boot time | |
# Description: Enable CoovaChilli service provided by daemon. | |
### END INIT INFO | |
PATH=/sbin:/bin:/usr/sbin:/usr/bin | |
DAEMON=/usr/sbin/chilli | |
NAME=chilli | |
DESC=chilli | |
START_CHILLI=1 | |
if [ -f /etc/default/chilli ] ; then | |
. /etc/default/chilli | |
fi | |
if [ "$START_CHILLI" != "1" ] ; then | |
echo "Chilli default off. Look at /etc/default/chilli" | |
exit 0 | |
fi | |
test -f $DAEMON || exit 0 | |
. /etc/chilli/functions | |
MULTI=$(ls /etc/chilli/*/chilli.conf 2>/dev/null) | |
[ -z "$DHCPIF" ] && [ -n "$MULTI" ] && { | |
for c in $MULTI; | |
do | |
echo "Found configuration $c" | |
DHCPIF=$(basename $(echo $c|sed 's#/chilli.conf##')) | |
export DHCPIF | |
echo "Running DHCPIF=$DHCPIF $0 $*" | |
sh $0 $* | |
done | |
exit | |
} | |
if [ -n "$DHCPIF" ]; then | |
CONFIG=/etc/chilli/$DHCPIF/chilli.conf | |
else | |
CONFIG=/etc/chilli.conf | |
fi | |
[ -f $CONFIG ] || { | |
echo "$CONFIG Not found" | |
exit 0 | |
} | |
check_required | |
RETVAL=0 | |
prog="chilli" | |
case "$1" in | |
start) | |
echo -n "Starting $DESC: " | |
/sbin/modprobe tun >/dev/null 2>&1 | |
echo 1 > /proc/sys/net/ipv4/ip_forward | |
writeconfig | |
radiusconfig | |
test ${HS_ADMINTERVAL:-0} -gt 0 && { | |
(crontab -l 2>&- | grep -v $0 | |
echo "*/$HS_ADMINTERVAL * * * * $0 radconfig" | |
) | crontab - 2>&- | |
} | |
ifconfig $HS_LANIF 0.0.0.0 | |
$DAEMON -c $CONFIG --pidfile /var/run/$NAME.$HS_LANIF.pid & | |
sleep 5 | |
;; | |
radconfig) | |
[ -e $MAIN_CONF ] || writeconfig | |
radiusconfig | |
;; | |
restart) | |
$0 stop | |
sleep 1 | |
$0 start | |
RETVAL=$? | |
;; | |
stop) | |
echo -n "Stopping $DESC: " | |
crontab -l 2>&- | grep -v $0 | crontab - | |
kill $(cat /var/run/$NAME.$HS_LANIF.pid) | |
rm /var/run/$NAME.$HS_LANIF* | |
sleep 3 | |
;; | |
reload) | |
$0 stop | |
sleep 1 | |
$0 start | |
RETVAL=$? | |
;; | |
status) | |
status chilli | |
RETVAL=$? | |
;; | |
*) | |
N=/etc/init.d/$NAME | |
echo "Usage: $N {start|stop|restart|condrestart|status|reload|radconfig}" >&2 | |
exit 1 | |
;; | |
esac | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment