# openbts - Range Networks RAN for GSM and GPRS
#
# This service runs openbts from the point the system is
# started until it is shut down again.

start on stopped rc RUNLEVEL=[2345]
stop on runlevel [!2345]

respawn
script
	cd /OpenBTS
# Uncomment this line and comment out the default ./OpenBTS line to enable automatic gdb backtraces to /OpenBTS/gdb.txt (via .gdbinit)
#	exec gdb
	exec ./OpenBTS
end script

pre-start script
	# Since Ubuntu clears /var/run on reboot, create this before we try to start
	if [ ! -e /var/run/OpenBTS ]; then
		mkdir /var/run/OpenBTS
	fi

	if [ ! -e /var/run/rrlp ]; then
		mkdir /var/run/rrlp
		chmod 777 /var/run/rrlp
	fi

	# place for CRD data
	if [ ! -e /var/lib/OpenBTS ]; then
		mkdir /var/lib/OpenBTS
	fi

# make sure permissions are set up correctly
if [ -d /var/lib/asterisk/sqlite3dir ]; then
	chown -R asterisk:www-data /var/lib/asterisk/sqlite3dir
	chmod 775 /var/lib/asterisk/sqlite3dir
	chmod 664 /var/lib/asterisk/sqlite3dir/sqlite3*
fi
end script

post-stop script
	if pgrep transceiver; then killall transceiver; fi
end script
