PirateBoxScripts_Webserver/piratebox/piratebox/init.d/piratebox

234 lines
6.8 KiB
Bash
Executable File

#! /bin/sh
# /etc/init.d/piratebox
### BEGIN INIT INFO
# Provides: piratebox
# Required-Start: $all
# Required-Stop: $network $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 6 1 0
# Short-Description: All services around piratebox
# Description: Based on /opt/piratebox/conf/piratebox.conf starts: * DNSMASQ * HOSTAPD * DROOPY * WLAN-config * CHAT
### END INIT INFO
###
# Default start-stop script for piratebox services on a laptop
# written by Matthias Strubel (matthias.strubel@aod-rpg.de) 2011-02-22
# licenced by gpl, feel free to improve and send me comments
. /lib/lsb/init-functions
[ -f /etc/default/rcS ] && . /etc/default/rcS
# PATH for /opt piratebox folder
PATH=$PATH:/opt/piratebox/bin
PIDFILE_DROOPY=/var/run/piratebox_droopy.pid
PIDFILE_HOSTAPN=/var/run/piratebox_hostapn.pid
PIDFILE_DNSMASQ=/var/run/piratebox_dnsmasq.pid
PIDFILE_LIGHTTPD=/opt/piratebox/tmp/lighttpd.pid
PIDFILE_SHOUTBOX=/opt/piratebox/tmp/shoutbox_daemon.pid
PIRATEBOX=/opt/piratebox
CONF=$PIRATEBOX/conf/piratebox.conf
#CONF_DROOPY=/opt/piratebox/conf/droopy.conf #not used
CONF_APN=$PIRATEBOX/conf/hostapd.conf
#Some extra config files for dnsmasq
CONF_DNSMASQ=$PIRATEBOX/conf/dnsmasq_generated.conf
CONF_LIGHTTPD=$PIRATEBOX/conf/lighttpd/lighttpd.conf
export PYTHONPATH=:$PYTHONPATH:$PIRATEBOX_PYTHONPATH
# Some things that run always
touch /var/lock/piratebox
if [ -f $CONF ] ; then
. $CONF
else
log_failure_msg "Configuration file not found"
exit 1
fi
if [ -f $PIRATEBOX/conf/init_done ] ; then
INIT=OK
else
$PIRATEBOX/bin/hooks/hook_pre_init.sh "$CONF"
$PIRATEBOX/bin/install_piratebox.sh "$CONF" part2
$PIRATEBOX/bin/hooks/hook_post_init.sh "$CONF"
touch $PIRATEBOX/conf/init_done
fi
# Command Line for DNSMASQ, use extra config file generated from command above
CMD_DNSMASQ="-x $PIDFILE_DNSMASQ -C $CONF_DNSMASQ "
# Carry out specific functions when asked to by the system
case "$1" in
start)
log_daemon_msg "Starting script piratebox "
echo ""
# Generate hosts & dnsmasq file
$PIRATEBOX/bin/generate_config_files.sh "$CONF"
$PIRATEBOX/bin/hooks/hook_piratebox_start.sh "$CONF"
echo "Empty tmp folder"
find $PIRATEBOX/tmp/ -exec rm {} \;
echo "Copy over design files"
$PIRATEBOX/bin/distribute_files.sh $SHARE_FOLDER/Shared
if [ "$DO_IW" = "yes" ] ; then
log_daemon_msg " Setting up Interface (iw) "
iw $PHY_IF interface add $INTERFACE type managed
fi
if [ "$PROBE_INTERFACE" = yes ] ; then
log_daemon_msg " Probing wlan"
#Setting up WLAN Interface
piratebox_setup_wlan.sh $CONF probe
fi
if [ $? -ne 0 ] ; then
log_failure_msg "failed probe Interface"
else
# Only activate
if [ "$USE_APN" = "yes" ] ; then
log_daemon_msg "Starting hostap... "
start-stop-daemon -m --start --background --pidfile $PIDFILE_HOSTAPN --exec /usr/sbin/hostapd -- $CONF_APN
log_end_msg $?
fi
if [ "$DO_IFCONFIG" = yes ] ; then
log_daemon_msg " Setting up wlan"
#Setting up WLAN Interface
piratebox_setup_wlan.sh $CONF start
if [ $? -ne 0 ] ; then
log_failure_msg "failed setting up Interface"
exit 99
fi
fi
#BRIDGE
if [ "$DO_BRIDGE" = "yes" ] ; then
log_daemon_msg "Adding $INTERFACE to bridge $BRIDGE // brctl addif $BRIDGE $INTERFACE "
sleep 1
BR_CMD="brctl addif $BRIDGE $INTERFACE"
( $BR_CMD ; )
log_end_msg $?
fi
if [ "$USE_DNSMASQ" = "yes" ] ; then
log_daemon_msg "Starting dnsmasq... "
# pidfile is written by dnsmasq
start-stop-daemon --start --quiet --exec /usr/sbin/dnsmasq -- $CMD_DNSMASQ
log_end_msg $?
fi
if [ "$DROOPY_ENABLED" = "yes" ] ; then
#Start here the PirateBox-Parts droopy i.e.
#Delete 0 Byte Files
delete_empty.sh $UPLOADFOLDER
find $UPLOADFOLDER/ -iname tmp\* -exec rm {} \;
DROOPY_USER=""
if [ "$DROOPY_USE_USER" = "yes" ] ; then
DROOPY_USER=" -c $LIGHTTPD_USER:$LIGHTTPD_GROUP "
fi
log_daemon_msg "Starting droopy..."
start-stop-daemon $DROOPY_USER -m --start --background --pidfile $PIDFILE_DROOPY --exec $PIRATEBOX/bin/droopy -- -d "$UPLOADFOLDER" -m "$DROOPY_TXT" --chmod $DROOPY_CHMOD $DROOPY_USERDIR $DROOPY_PORT
log_end_msg $?
fi
#Do shoutbox stuff
$PIRATEBOX/bin/shoutbox_stuff.sh $WWW_FOLDER $CONF
#Start here the lighttpd i.e.
log_daemon_msg "Starting lighttpd..."
start-stop-daemon --start --quiet --pidfile $PIDFILE_LIGHTTPD --exec /usr/sbin/lighttpd -- -f $CONF_LIGHTTPD
log_end_msg $?
#Start Global Chat daemon if needed.
if [ "$GLOBAL_CHAT" = "yes" ] ; then
log_daemon_msg "Starting global chat service..."
start-stop-daemon -m --start --background --pidfile $PIDFILE_SHOUTBOX --startas $PIRATEBOX/bin/shoutbox_daemon.sh -- $CONF
log_end_msg $?
fi
fi
$PIRATEBOX/bin/hooks/hook_piratebox_start_done.sh "$CONF"
;;
stop)
log_daemon_msg "Stopping script piratebox"
echo ""
$PIRATEBOX/bin/hooks/hook_piratebox_stop.sh "$CONF"
if [ "$USE_APN" = "yes" ] ; then
log_daemon_msg "Stopping hostap... "
start-stop-daemon --stop --quiet --pidfile $PIDFILE_HOSTAPN --oknodo --startas "hostapd"
log_end_msg $?
fi
if [ "$USE_DNSMASQ" = "yes" ] ; then
log_daemon_msg "Stopping dnsmasq..."
start-stop-daemon --stop --quiet --pidfile $PIDFILE_DNSMASQ
log_end_msg $?
fi
#Stop Global Chat daemon
if [ "$GLOBAL_CHAT" = "yes" ] ; then
log_daemon_msg "Stopping global chat service..."
start-stop-daemon --stop --quiet --pidfile $PIDFILE_SHOUTBOX
log_end_msg $?
fi
log_daemon_msg "Stopping lighttpd..."
start-stop-daemon --stop --retry 30 --quiet --pidfile $PIDFILE_LIGHTTPD
log_end_msg $?
if [ "$DROOPY_ENABLED" = "yes" ] ; then
#Kill Droopy
log_daemon_msg "Stopping droopy... "
start-stop-daemon --stop --quiet --pidfile $PIDFILE_DROOPY --oknodo --startas "python /opt/piratebox/bin/droopy"
log_end_msg $?
fi
if [ "$DO_IFCONFIG" = yes ] ; then
piratebox_setup_wlan.sh $CONF stop
fi
if [ "$DO_IW" = "yes" ] ; then
iw dev $INTERFACE del
fi
# REMOVE BRIDGE
if [ "$DO_BRIDGE" = "yes" ] ; then
log_daemon_msg "Remove Bridge..."
BR_CMD="brctl delif $BRIDGE $INTERFACE"
( $BR_CMD ; )
log_end_msg $?
fi
$PIRATEBOX/bin/hooks/hook_piratebox_stop_done.sh "$CONF"
;;
*)
echo "Usage: /etc/init.d/piratebox {start|stop}"
exit 1
;;
esac
exit 0