#!/bin/sh
# osdial  Startup script for OSDial services.
#
# chkconfig: 2345 98 02
# description:  OSDial firstrun and services
# processname:  osdial
# pidfile: /var/run/osdial/osdial.pid

# 90409-2204 - Added several startup functions.
# 90409-2220 - Added ip_relay.

# Source function library.
. /etc/rc.d/init.d/functions

[ -f "/mnt/live/config.txt" ] && . /mnt/live/config.txt
[ -f "/etc/sysconfig/osdial" ] && . /etc/sysconfig/osdial

[ -n "$OSDIAL_COMPANY" ] && COMPANY=$OSDIAL_COMPANY

[ -n "$OSDIAL_BINUSER" ] && BINUSER=$OSDIAL_BINUSER
[ -n "$OSDIAL_BINUSER" ] && ORIG_BINUSER=$OSDIAL_BINUSER
[ -z "$ORIG_BINUSER" ] && ORIG_BINUSER=100000

[ -n "$OSDIAL_BINPASS" ] && BINPASS=$OSDIAL_BINPASS
[ -n "$OSDIAL_BINPASS" ] && ORIG_BINPASS=$OSDIAL_BINPASS
[ -z "$ORIG_BINPASS" ] && ORIG_BINPASS=zzzzzzzz

RETVAL=0

PLACTIVE=0
# Test if we have Plymouth and if it is active.
if [ -f /usr/bin/plymouth ]; then
	/usr/bin/plymouth --has-active-vt
	# Its going to return, so we must invert the sense.
	[ "$?" -gt 0 ] && PLACTIVE=0 || PLACTIVE=1
fi

start() {
	# Get INET address from eth0 or eth1
	INET=`/sbin/ip ad li dev eth0 | grep 'inet ' | cut -d ' ' -f 6 | cut -d '/' -f 1`
	if [ -z "$INET" ]; then
		INET=`/sbin/ip ad li dev eth1 | grep 'inet ' | cut -d ' ' -f 6 | cut -d '/' -f 1`
	fi

	if [ "$OSDIAL_FIRSTRUN" != "NO" ]; then
		TIMEOUT=60
		BINTIMEOUT=60
		[ "$COMPANY" = "Company Name Here" ] && COMPANY=""
		[ -n "$COMPANY" ] && TIMEOUT=3
		[ -n "$BINUSER" ] && BINTIMEOUT=3
		TEMP=/tmp/osdial_init.$$

		if [ -f "/opt/osdial/.osdial-all" -o -f "/opt/osdial/.osdial-install-all" -o -f "/opt/osdial/.osdial-control" -o -f "/opt/osdial/.osdial-install-control" -o -f "/opt/osdial/.osdial-sql" -o -f "/opt/osdial/.osdial-install-sql" -o -f "/opt/osdial/.osdial-live" ]; then
			[ "${PLACTIVE}" -gt 0 ] && (clear; /usr/bin/plymouth --hide-splash pause_progress) || :
			# Install DB
			[ "$OSDIAL_MYSQL_INSTALL" = "YES" ] && /opt/osdial/bin/sql/upgrade_sql.pl --install
			[ ! -f "/var/lib/mysql/osdial/system_settings.ibd" ] && /opt/osdial/bin/sql/upgrade_sql.pl --install
			[ "${PLACTIVE}" -gt 0 ] && (clear; /usr/bin/plymouth --show-splash unpause_progress) || :

			# Get server timezone and update in osdial database
			OSDTZ=`date +%:::z`
			[ -z "$OSDTZ" ] && OSDTZ="0"
			OSDTZ=`expr $OSDTZ + 0`
			[ "`date +%Z | grep DT`" != "" ] && OSDTZ=`expr $OSDTZ - 1`
			if [ -n "$OSDTZ" ]; then
				echo "UPDATE servers SET local_gmt='$OSDTZ';" | mysql osdial > /dev/null 2>&1
				echo "UPDATE phones SET local_gmt='$OSDTZ';" | mysql osdial > /dev/null 2>&1
			fi

			[ "${PLACTIVE}" -gt 0 ] && (clear; /usr/bin/plymouth --hide-splash pause_progress) || :
			# Direct them to setup their static IP address
			dialog --clear --timeout $TIMEOUT\
				--backtitle "OSDial - The OpenSource Dialer" \
				--title "OSDial FirstRun - Customize Login - Timeout: $TIMEOUT seconds" \
				--msgbox "\nNetwork Configuration\n\nThe default installation uses DHCP to auto-configure your network devices. While this is fine for evaluating OSDial, it is strongly recomended that you use a static IP addresses in a production environment.\n\nPress ENTER to configure your network devices now.\nTo postpone network device configuration, wait $TIMEOUT seconds." 15 75
			RET=$?
			[ "${PLACTIVE}" -gt 0 ] && (clear; /usr/bin/plymouth --show-splash unpause_progress) || :
			if [ "$RET" = "0" ]; then
				[ "${PLACTIVE}" -gt 0 ] && (clear; /usr/bin/plymouth --hide-splash pause_progress) || :
				/usr/sbin/system-config-network
				[ "${PLACTIVE}" -gt 0 ] && (clear; /usr/bin/plymouth --show-splash unpause_progress) || :
				/sbin/service network restart > /dev/null 2>&1
				# Get INET address from eth0 or eth1
				INET=`/sbin/ip ad li dev eth0 | grep 'inet ' | cut -d ' ' -f 6 | cut -d '/' -f 1`
				if [ -z "$INET" ]; then
					INET=`/sbin/ip ad li dev eth1 | grep 'inet ' | cut -d ' ' -f 6 | cut -d '/' -f 1`
				fi
				. /etc/sysconfig/network
				hostname $HOSTNAME
			fi

			[ "${PLACTIVE}" -gt 0 ] && (clear; /usr/bin/plymouth --hide-splash pause_progress) || :
			# Prompt for Company, Binfone Username and Password
			dialog --clear --timeout $TIMEOUT \
				--backtitle "OSDial - The OpenSource Dialer" \
				--title "OSDial FirstRun - Customize Login - Timeout: $TIMEOUT seconds" \
				--inputbox "Enter Company Name:" 9 65 "$COMPANY" 2> $TEMP
			RET=$?
			[ "${PLACTIVE}" -gt 0 ] && (clear; /usr/bin/plymouth --show-splash unpause_progress) || :
			[ "$RET" = "0" ] && COMPANY=`cat $TEMP`
			[ -z "$COMPANY" ] && COMPANY="Company Name Here"
			echo "UPDATE system_settings SET company_name='$COMPANY';" | mysql osdial > /dev/null 2>&1
		fi
	
		if [ -f "/opt/osdial/.osdial-all" -o -f "/opt/osdial/.osdial-install-all" -o -f "/opt/osdial/.osdial-dialer" -o -f "/opt/osdial/.osdial-install-dialer" -o -f "/opt/osdial/.osdial-live" ]; then
			[ "${PLACTIVE}" -gt 0 ] && (clear; /usr/bin/plymouth --hide-splash pause_progress) || :
			dialog --clear --timeout $BINTIMEOUT --backtitle "OSDial - The OpenSource Dialer" --title "Free VoIP Trial" \
				--form "\n                You may optionally contact\n      Call Center Service Group at 800-221-0251 (opt 2)\n   for a free trial with Binfone, a premier VoIP provider.\n\n        If you have an existing Binfone IAX extension,\n          you may also enter those credentials here.\n \n \n " 20 65 2 \
			"Binfone User/Ext#:" 1 15 "$BINUSER" 1 35 7 6 \
			"Binfone Password:" 2 15 "$BINPASS" 2 35 9 8 2> $TEMP
			RET=$?
			[ "${PLACTIVE}" -gt 0 ] && (clear; /usr/bin/plymouth --show-splash unpause_progress) || :
			if [ "$RET" = "0" ]; then
				set `cat $TEMP`
				BINUSER=$1
				BINPASS=$2
				clear
			fi
			if [ "$BINUSER" != "$ORIG_BINUSER" -a "$BINUSER" != "" ]; then
				/usr/bin/perl -pi -e "s|$ORIG_BINUSER|$BINUSER|" /etc/asterisk/osdial_iax_trunks.conf
				/usr/bin/perl -pi -e "s|$ORIG_BINPASS|$BINPASS|" /etc/asterisk/osdial_iax_trunks.conf
				/usr/bin/perl -pi -e "s|^;||" /etc/asterisk/osdial_iax_trunks.conf
			fi
			/usr/sbin/asterisk -rx "iax2 reload" > /dev/null 2>&1
		fi


		# Overwrite /etc/issue
		echo > /etc/issue
		echo >> /etc/issue
		echo >> /etc/issue
		echo >> /etc/issue
		echo >> /etc/issue
		echo "OSDial - The OpenSource Dialer" | awk '{l=length();s=int((79-l)/2); printf "%"(s+l)"s\n",$0}' >> /etc/issue
		echo >> /etc/issue
		[ -z "$COMPANY" ] && COMPANY="Company Name Here"
		echo "$COMPANY" | awk '{l=length();s=int((79-l)/2); printf "%"(s+l)"s\n",$0}' >> /etc/issue
		echo >> /etc/issue
		echo "Paid support available through Call Center Service Group" | awk '{l=length();s=int((79-l)/2); printf "%"(s+l)"s\n",$0}' >> /etc/issue
		echo "800-221-0251" | awk '{l=length();s=int((79-l)/2); printf "%"(s+l)"s\n",$0}' >> /etc/issue
		echo >> /etc/issue
		echo "OSDial is available for download at http://www.osdial.com/" | awk '{l=length();s=int((79-l)/2); printf "%"(s+l)"s\n",$0}' >> /etc/issue
		echo >> /etc/issue
		if [ -f "/opt/osdial/.osdial-all" -o -f "/opt/osdial/.osdial-install-all" -o -f "/opt/osdial/.osdial-control" -o -f "/opt/osdial/.osdial-install-control" -o -f "/opt/osdial/.osdial-sql" -o -f "/opt/osdial/.osdial-install-sql" -o -f "/opt/osdial/.osdial-live" ]; then
			echo "You may now boot the Agent-DemoCD in another computer" | awk '{l=length();s=int((79-l)/2); printf "%"(s+l)"s\n",$0}' >> /etc/issue
			echo "or point your Chrome or Firefox browser to http://$INET/" | awk '{l=length();s=int((79-l)/2); printf "%"(s+l)"s\n",$0}' >> /etc/issue
			echo >> /etc/issue
			echo "Admin Login and Password: admin / admin" | awk '{l=length();s=int((79-l)/2); printf "%"(s+l)"s\n",$0}' >> /etc/issue
			echo >> /etc/issue
			echo "Phone Login and Password:  1000 / 1000" | awk '{l=length();s=int((79-l)/2); printf "%"(s+l)"s\n",$0}' >> /etc/issue
			echo "Agent Login and Password:  1000 / 1000" | awk '{l=length();s=int((79-l)/2); printf "%"(s+l)"s\n",$0}' >> /etc/issue
			echo >> /etc/issue
		fi
		#echo "Temporary root password is osdial1234, change ASAP!" | awk '{l=length();s=int((79-l)/2); printf "%"(s+l)"s\n",$0}' >> /etc/issue
		echo "You may login to the console by using the username 'root'" | awk '{l=length();s=int((79-l)/2); printf "%"(s+l)"s\n",$0}' >> /etc/issue
		echo "and the password you chose during installation." | awk '{l=length();s=int((79-l)/2); printf "%"(s+l)"s\n",$0}' >> /etc/issue
		echo "The password can be changed by issuing the 'passwd' command after login." | awk '{l=length();s=int((79-l)/2); printf "%"(s+l)"s\n",$0}' >> /etc/issue
		echo >> /etc/issue
		echo " --- " >> /etc/issue

		# Saving options to /etc/sysconfig/osdial
		echo "OSDIAL_FIRSTRUN=\"NO\"" > /etc/sysconfig/osdial
		if [ -f "/opt/osdial/.osdial-all" -o -f "/opt/osdial/.osdial-install-all" -o -f "/opt/osdial/.osdial-control" -o -f "/opt/osdial/.osdial-install-control" -o -f "/opt/osdial/.osdial-sql" -o -f "/opt/osdial/.osdial-install-sql" -o -f "/opt/osdial/.osdial-live" ]; then
			echo "OSDIAL_COMPANY=\"$COMPANY\"" >> /etc/sysconfig/osdial
		fi
		if [ -f "/opt/osdial/.osdial-all" -o -f "/opt/osdial/.osdial-install-all" -o -f "/opt/osdial/.osdial-dialer" -o -f "/opt/osdial/.osdial-install-dialer" -o -f "/opt/osdial/.osdial-live" ]; then
			echo "OSDIAL_BINUSER=\"$BINUSER\"" >> /etc/sysconfig/osdial
			echo "OSDIAL_BINPASS=\"$BINPASS\"" >> /etc/sysconfig/osdial
		fi
	fi

	# Update /etc/issue with current IP and company name.
	grep 'OSDial - The OpenSource Dialer' /etc/issue > /dev/null 2>&1
	if [ ! "$?" -gt 0 ]; then
		/usr/bin/perl -pi -e "s|browser to http://(.*)/|browser to http://$INET/|" /etc/issue > /dev/null 2>&1
		COMPANY=`echo "SELECT company_name FROM system_settings;" | mysql osdial | tail -1 | awk '{l=length();s=int((79-l)/2); printf "%"(s+l)"s\n",$0}'`
		/bin/sed -e"8c\\${COMPANY}" -i /etc/issue > /dev/null 2>&1
	fi

	# Make tmpfs filesystem for recordings
	# Make sure it is not a live image.
	if [ ! -f "/opt/osdial/.osdial-profile-live" ]; then
		# Make sure this system runs asterisk
		/sbin/chkconfig --list asterisk | grep on > /dev/null 2>&1
		if [ ! "$?" -gt 0 ]; then
			# Set size if needed
			if [ -z "$OSDIAL_TMPFS_SIZE" ]; then
				OSDIAL_TMPFS_SIZE="0%"
				MEM=`head -1 /proc/meminfo | sed 's/MemTotal:\s*\(.*\) kB.*/\1/'`
				if [ "$MEM" -gt 512000 -a "$MEM" -lt 1024001 ]; then
					OSDIAL_TMPFS_SIZE="5%"
				elif [ "$MEM" -gt 1024000 -a "$MEM" -lt 2048001 ]; then
					OSDIAL_TMPFS_SIZE="10%"
				elif [ "$MEM" -gt 2048000 ]; then
					OSDIAL_TMPFS_SIZE="20%"
				fi
				echo "OSDIAL_TMPFS_SIZE=$OSDIAL_TMPFS_SIZE" >> /etc/sysconfig/osdial
			fi
			if [ -z "$OSDIAL_TMPFS_PATH" -o "$OSDIAL_TMPFS_PATH" = "/var/spool/asterisk/VDmonitor" ]; then
				OSDIAL_TMPFS_PATH="/mnt/ramdisk"
				echo "OSDIAL_TMPFS_PATH=$OSDIAL_TMPFS_PATH" >> /etc/sysconfig/osdial
			fi

			# Mount tmpfs...
			mkdir -p ${OSDIAL_TMPFS_PATH} > /dev/null 2>&1
			mocnt=`mount | grep "tmpfs on ${OSDIAL_TMPFS_PATH} type tmpfs" | wc -l`
			if [ ${mocnt} -eq 0 ]; then mount -t tmpfs -o size=${OSDIAL_TMPFS_SIZE},mode=777 tmpfs ${OSDIAL_TMPFS_PATH} > /dev/null 2>&1; fi
			mkdir -p ${OSDIAL_TMPFS_PATH}/VDmonitor > /dev/null 2>&1
			mkdir -p ${OSDIAL_TMPFS_PATH}/record_cache > /dev/null 2>&1
			if [ ! -L "/var/spool/asterisk/VDmonitor" ]; then
				if [ -d "/var/spool/asterisk/VDmonitor" ]; then
					monls=`ls /var/spool/asterisk/VDmonitor | wc -l`
					if [ ${monls} -gt 0 ]; then
						mv /var/spool/asterisk/VDmonitor/* ${OSDIAL_TMPFS_PATH}/VDmonitor > /dev/null 2>&1
					fi
					rm -rf /var/spool/asterisk/VDmonitor > /dev/null 2>&1
				fi
				ln -s ${OSDIAL_TMPFS_PATH}/VDmonitor /var/spool/asterisk/VDmonitor > /dev/null 2>&1
			fi
			if [ ! -L "/var/spool/asterisk/record_cache" ]; then
				if [ -d "/var/spool/asterisk/record_cache" ]; then
					monls=`ls /var/spool/asterisk/record_cache | wc -l`
					if [ ${monls} -gt 0 ]; then
						mv /var/spool/asterisk/record_cache/* ${OSDIAL_TMPFS_PATH}/record_cache > /dev/null 2>&1
					fi
					rm -rf /var/spool/asterisk/record_cache > /dev/null 2>&1
				fi
				ln -s ${OSDIAL_TMPFS_PATH}/record_cache /var/spool/asterisk/record_cache > /dev/null 2>&1
			fi
			chown -R asterisk:asterisk ${OSDIAL_TMPFS_PATH} > /dev/null 2>&1
			chown -R asterisk:asterisk /var/spool/asterisk > /dev/null 2>&1
		fi
	fi

	if [ -f /etc/openvpn/osdial.up ]; then
		[ -n "${OSDIAL_OPENVPN_NAME}" ] && HST=${OSDIAL_OPENVPN_NAME} || HST=`/bin/hostname -s`
		if [ "$HST" = "localhost" -o "$HST" = "osdial" -o "$HST" = "osdial-live" -o "$HST" = "osdial-ccsg" -o "$HST" = "osd" -o -z "$HST" ]; then
			OVHST=`/usr/bin/head -1 /etc/openvpn/osdial.up`
			if [ "$HST" = "localhost" -o "$OVHST" = "osdial" -o "$OVHST" = "osdial-live" -o "$OVHST" = "osdial-ccsg" -o "$OVHST" = "osd" -o -z "$OVHST" ]; then
				UUID=`/usr/bin/uuidgen | awk -F- '{ print $1 }'`
				HST="osdial-${UUID}"
				hostname ${HST}.osdial.com
				/usr/bin/perl -pi -e "s|^HOSTNAME=(.*)$|HOSTNAME=${HST}.osdial.com|" /etc/sysconfig/network > /dev/null 2>&1
				echo "127.0.0.1  ${HST}.osdial.com ${HST} osdial" >> /etc/hosts
			fi
		fi
		echo "${HST}" > /etc/openvpn/osdial.up
		echo "0o1s2d3i4a5l6${HST}6l5a4i3d2s1o0" >> /etc/openvpn/osdial.up
		if [ -f /var/run/openvpn/osdial.pid ]; then
			/sbin/service openvpn restart > /dev/null 2>&1
		fi
	fi

	# Processes to run before services start
	/usr/bin/setterm -blank > /dev/null 2>&1
	/usr/bin/setterm -powersave off > /dev/null 2>&1
	/usr/bin/setterm -powerdown > /dev/null 2>&1
	#/opt/osdial/bin/ADMIN_restart_roll_logs.pl > /dev/null 2>&1
	/opt/osdial/bin/AST_ntp_update.sh > /dev/null 2>&1 &
	/opt/osdial/bin/ADMIN_area_code_populate.pl > /dev/null 2>&1 &
	/opt/osdial/bin/osdial_astgen.pl -q &
	/opt/osdial/bin/AST_reset_mysql_vars.pl > /dev/null 2>&1 &
	/opt/osdial/bin/osdial-astsnds-ramfs.sh > /dev/null 2>&1 &
	# Only use VM as a last resort
	echo 1 > /proc/sys/vm/swappiness

	[ "${PLACTIVE}" -gt 0 ] && (clear; /usr/bin/plymouth --hide-splash pause_progress) || :
	/opt/osdial/bin/sql/upgrade_sql.pl --info
	[ "${PLACTIVE}" -gt 0 ] && (clear; /usr/bin/plymouth --show-splash unpause_progress) || :

	return 0
}

stop() {
	if [ -L "/var/spool/asterisk/VDmonitor" ]; then rm -f /var/spool/asterisk/VDmonitor > /dev/null 2>&1; fi
	if [ ! -d "/var/spool/asterisk/VDmonitor" ]; then mkdir -p /var/spool/asterisk/VDmonitor > /dev/null 2>&1; fi
	if [ -d "/mnt/ramdisk/VDmonitor" ]; then
		monls=`ls /mnt/ramdisk/VDmonitor | wc -l`
		if [ ${monls} -gt 0 ]; then mv /mnt/ramdisk/VDmonitor/* /var/spool/asterisk/VDmonitor > /dev/null 2>&1; fi
	fi

	if [ -L "/var/spool/asterisk/record_cache" ]; then rm -f /var/spool/asterisk/record_cache > /dev/null 2>&1; fi
	if [ ! -d "/var/spool/asterisk/record_cache" ]; then mkdir -p /var/spool/asterisk/record_cache > /dev/null 2>&1; fi
	if [ -d "/mnt/ramdisk/record_cache" ]; then
		monls=`ls /mnt/ramdisk/record_cache | wc -l`
		if [ ${monls} -gt 0 ]; then mv /mnt/ramdisk/record_cache/* /var/spool/asterisk/record_cache > /dev/null 2>&1; fi
	fi
	chown -R asterisk:asterisk /mnt/ramdisk > /dev/null 2>&1
	chown -R asterisk:asterisk /var/spool/asterisk > /dev/null 2>&1

	/opt/osdial/bin/AST_reset_mysql_vars.pl > /dev/null 2>&1 &
	echo
	return 0
}

reconfig() {
	OSDIAL_FIRSTRUN=YES
	start
}

start_relay() {
	ret=0
	if [ -f "/opt/osdial/bin/ip_relay" -a -f "/etc/asterisk/osdial_iax.conf" ]; then
		echo -n $"OSDial: Starting IP Relay: "
		/opt/osdial/bin/safe_ip_relay 40569 127.0.0.1    4569 9999999 > /dev/null 2>&1 &
		let ret+=$?;
		/opt/osdial/bin/safe_ip_relay 41569 127.0.0.1    4569 9999999 > /dev/null 2>&1 &
		let ret+=$?;
    		[ $ret -eq 0 ] && success || failure
		echo
	fi
	return $ret
}

stop_relay() {
	ret=0
	if [ -f "/opt/osdial/bin/ip_relay" -a -f "/etc/asterisk/osdial_iax.conf" ]; then
		echo -n $"OSDial: Stopping IP Relay: "
		kill `ps -C safe_ip_relay -o pid --no-heading` > /dev/null 2>&1
		let ret+=$?;
		kill `ps -C ip_relay -o pid --no-heading` > /dev/null 2>&1
		let ret+=$?;
    		[ $ret -eq 0 ] && success || failure
		echo
	fi
	return $ret
}

reload() {
	stop_relay
	start_relay
	ret=0

	echo -n $"OSDial: Clearing SQL Server States: "
	/opt/osdial/bin/AST_reset_mysql_vars.pl > /dev/null 2>&1
	let ret+=$?;
    	[ $ret -eq 0 ] && success || failure
	echo

	KFAGI=0
	if [ -n "`ps -ef | grep FastAGI | grep -v grep`" ]; then
		KFAGI=1
		echo -n $"OSDial: Stopping FastAGI: "
		kill -9 `ps -ef | grep FastAGI | awk '{ print $2 }' | grep -v grep` > /dev/null 2>&1
		let ret+=$?;
    		[ $ret -eq 0 ] && success || failure
		echo
	fi

	KAST=0
	if [ -n "`ps -ef | grep AST | grep -v grep`" ]; then
		KAST=1
		echo -n $"OSDial: Stopping AST processes: "
		kill -9 `ps -ef | grep AST | awk '{ print $2 }' | grep -v grep` > /dev/null 2>&1
		let ret+=$?;
    		[ $ret -eq 0 ] && success || failure
		echo
	fi

	KOSD=0
	if [ -n "`ps -ef | grep OSD | grep -v grep`" ]; then
		KOSD=1
		echo -n $"OSDial: Stopping OSD processes: "
		kill -9 `ps -ef | grep OSD | awk '{ print $2 }' | grep -v grep` > /dev/null 2>&1
		let ret+=$?;
    		[ $ret -eq 0 ] && success || failure
		echo
	fi

	if [ $KFAGI -eq 1 -o $KAST -eq 1 -o $KOSD -eq 1 ]; then
		TIME=`date +%H:%M:%S`
		SEC=`date +%S`
		let STS=60-$SEC
		echo -n $"OSDial: Starting in approx. ${STS}sec"
		#while [ $STS -gt 1 ]; do
		#	let STS=$STS-4
		#	echo -n "."
		#	sleep 4
		#done
		echo -n ": "
		let ret+=$?;
    		[ $ret -eq 0 ] && success || failure
		echo
	else
		echo -n $"OSDial: No Keepalives Active: "
    		success
		echo
	fi
	return $ret
}

# See how we were called.
case "$1" in
  start)
	start
	start_relay
	;;
  stop)
	stop_relay
	stop
	;;
  reload)
	reload
	;;
  reconfig)
	reconfig
	;;
  restart)
	reload
	;;
  start_relay)
	start_relay
	;;
  stop_relay)
	stop_relay
	;;
  *)
	echo "Usage: osdial {start|stop|restart|reload|reconfig| start_relay|stop_relay|restart_relay}"
	exit 1
esac

exit $?
