Skip to content

Instantly share code, notes, and snippets.

@muffycompo
Created March 23, 2017 16:00
Show Gist options
  • Save muffycompo/02131d5557ce9e14d167d06da5fccb66 to your computer and use it in GitHub Desktop.
Save muffycompo/02131d5557ce9e14d167d06da5fccb66 to your computer and use it in GitHub Desktop.
#! /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=0
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
start-stop-daemon --start --quiet --pidfile /var/run/$NAME.$HS_LANIF.pid \
--exec $DAEMON -- -c $CONFIG
RETVAL=$?
echo "$NAME."
;;
checkrunning)
check=`start-stop-daemon --start --exec $DAEMON --test`
if [ x"$check" != x"$DAEMON already running." ] ; then
$0 start
fi
;;
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 -
start-stop-daemon --oknodo --stop --quiet --pidfile /var/run/$NAME.$HS_LANIF.pid \
--exec $DAEMON
echo "$NAME."
;;
reload)
echo "Reloading $DESC."
start-stop-daemon --stop --signal 1 --quiet --pidfile \
/var/run/$NAME.$HS_LANIF.pid --exec $DAEMON
;;
condrestart)
check=`start-stop-daemon --start --exec $DAEMON --test`
if [ x"$check" != x"$DAEMON already running." ] ; then
$0 restart
RETVAL=$?
fi
;;
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