Table of Contents

Running Multiple Instances of the Crossfire Server

Running multiple instances of the server is possible, be it for debugging purposes or just for the personal experience.
And my personal experience on a 2-Core Intel CPU with 2,67 GHz BIOS year 2008 is very pleasing: 8 instances were running, without much CPU-usage as shown by the xosview application.

Problems when running multiple instances

There are some problems when running multiple instances of the server; mainly the LOCALDIR and LIBDIR (DATADIR) handling may confuse the (other) servers, if these are shared.
One solution would be to pass positional parameters to the server at start up time, the other solution would be to use environment variables .

Example Bash Script to launch multiple servers

This is just a snipplet to demonstrate the usage of parameters :

#!/bin/bash
 
# VARIABLES
SERVER_NUM=${*:-$SERVER_NUM} # number of servers to launch
SERVER_NUM=${SERVER_NUM:-3}
 
MY_SERVER_OPTYS=""  # -d
 
PREFIX=`pwd`
PREFIX=${PREFIX%/*}
DATA_DIR_DEF=$PREFIX/share/crossfire
# more default path for dirs and files here ...
 
for i in `seq 1 1 ${SERVER_NUM:-1}`; do
 
# assign variables here
DATA_DIR=$DATA_DIR_DEF.$i
# more assignments here ...
 
# now start server ...
#./crossfire-server -csport $((13227+i)) -detach
./crossfire -csport $((13227+i)) $MY_SERVER_OPTS -detach  \
 -log         $LOG_FILE       \
 -conf        $CONF_DIR       \
 -tmpdir      $TMP_DIR        \
 -data        $DATA_DIR       \
  -maps        $MAPS_DIR      \
  -arch        $ARCH_FILE     \
  -regions     $REGIONS_FILE  \
  -treasures   $TREASURE_FILE \
 -local       $LOCAL_DIR      \
  -templatedir $TEMPL_DIR     \
  -uniquedir   $UNIQUE_DIR    \
  -playerdir   $PLAYER_DIR    \
 
sleep 5
done

You may find a whole script one day here .

What does the above scribble do ?

1.) It needs to assign a bunch of default variable names; those can then be used as template to assign the “real” variable name in the for loop below. Example : DATA_DIR becomes DATA_DIR_DEF with a simple .i added at the end; where i would stand for the current number of the for loop is provided by the seq command. I use the seq command instead of {1..$SERVER_NUM} because I think that it is more portable, since the busybox ash shell does not know such syntax until today.

2.) Inside the for loop the 4 absolute directory variables CONF_DIR, DATA_DIR, LOCAL_DIR, TMP_DIR get their assignments and the 1 absolute file LOG_FILE . Then these PATH_DIRs need to be checked if they exist, and maybe created if not existent like the arch/ and maps/ packages.

3.) Each server needs an unique port number. This is achieved by passing the command-line option

-csport $((13227 + i)) 

to the server start line.
:!: Note: Some people do not like bash math without adding the variable-indicator sign $, but I have better experience, when the $ is omitted. Example:

bash-3.00# A=
bash-3.00# B=1
bash-3.00# echo $(( $B + $A ))
bash: 1 +  : syntax error: operand expected (error token is " ")
bash-3.00# echo $(( B + A ))
1

4.) Server start line : The syntax ./program indicates, that this start-up script is located inside the directory, where the crossfire server resides. program would launch the program that is found in the PATH variable ( echo $PATH should show which folders are in the path , and which <program> should show the first location of the found names of program ; bash only : type -a crossfire would show all locations of the executable named 'crossfire' ) .
:!: Note: Today the crossfire server executable is named crossfire-server by the default server compiling scripts.
The crossfire executable is launched then with the many -parameter options to make each instance having its own temporary, player, map and other files.

5.) Sleep 5 seconds before launching the next number the for loop still has left.

Server Startup Errors and Crashes

1.) Do not think, that while the -maps option at least is responsible for the maps package, that the -arch option would be meant for the arch package; it should be named -archetypesfile .
2.) The -maps are huge space consumers when installed and decompressed. But the -maps option does not want an absolute path suggested like /mnt/my-big-data-partition/crossfire/maps . If you want to use absolute path, you need to set the -datadir as absolute path and place your maps/ directory inside that.