86 lines
2.2 KiB
Bash
Executable file
86 lines
2.2 KiB
Bash
Executable file
#!/bin/sh
|
|
|
|
# fgfs-launch-server -- script to launch fgfs scenery construction server
|
|
#
|
|
# Written by Curtis Olson, started May 1999.
|
|
#
|
|
# Copyright (C) 1999 Curtis L. Olson - curt@flightgear.org
|
|
#
|
|
# This program is free software; you can redistribute it and/or
|
|
# modify it under the terms of the GNU General Public License as
|
|
# published by the Free Software Foundation; either version 2 of the
|
|
# License, or (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful, but
|
|
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
# General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program; if not, write to the Free Software
|
|
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
#
|
|
# $Id$
|
|
|
|
SERVER=fgfs-tools-server
|
|
|
|
# check usage
|
|
if [ $# != 1 ]; then
|
|
echo "Usage: $0 base_dir"
|
|
exit
|
|
else
|
|
BASE_DIR=$1
|
|
WORK_BASE="${BASE_DIR}/work"
|
|
OUTPUT_DIR="${BASE_DIR}/FlightGear"
|
|
MASTER_ON="${WORK_BASE}.status/MASTER_ON"
|
|
LOG_DIR="${BASE_DIR}/work.status"
|
|
LOG_FILE="${LOG_DIR}/server.log"
|
|
echo "Base directory is $BASE_DIR"
|
|
echo "Work base is $WORK_BASE"
|
|
echo "Output base is $OUTPUT_DIR"
|
|
echo "Logging to $LOG_FILE"
|
|
fi
|
|
|
|
# check if server binary exists
|
|
if type $SERVER > /dev/null; then
|
|
echo "server: `type $SERVER`"
|
|
else
|
|
echo "cannot locate $SERVER"
|
|
exit
|
|
fi
|
|
|
|
# check if log directory exists, and if not, make it
|
|
if [ ! -d $LOG_DIR ]; then
|
|
mkdir -p $LOG_DIR
|
|
fi
|
|
|
|
# kill any existing copies of the server
|
|
killall $SERVER
|
|
|
|
# launch the server in the background
|
|
SERVER_HOST=`hostname -f`
|
|
COMMAND="$SERVER $WORK_BASE $OUTPUT_DIR"
|
|
echo "Launching the server with the following options:"
|
|
echo ""
|
|
echo "$COMMAND"
|
|
echo ""
|
|
echo "Server launched on host: $SERVER_HOST" > $LOG_FILE
|
|
$COMMAND >> $LOG_FILE 2>&1 &
|
|
|
|
# grab the PID
|
|
SERVER_PID=`echo $!`
|
|
|
|
# wait for a moment
|
|
sleep 1
|
|
|
|
# grab the port number
|
|
SERVER_PORT=`grep port $LOG_FILE | awk '{ print $7 }'`
|
|
|
|
# turn on the master switch
|
|
echo $SERVER_PORT > $MASTER_ON
|
|
|
|
# finish
|
|
echo "server is now running in background:"
|
|
echo " host = $SERVER_HOST"
|
|
echo " pid = $SERVER_PID"
|
|
echo " port = $SERVER_PORT"
|