Index: scripts/usr/local/bin/7dtd-backup.sh
===================================================================
--- scripts/usr/local/bin/7dtd-backup.sh	(revision 1)
+++ scripts/usr/local/bin/7dtd-backup.sh	(revision 9)
@@ -18,5 +18,5 @@
 fi
 
-$RSYNC -a --delete --numeric-ids --delete-excluded $SDTD_ROOT/Data/Worlds/./ $NewBackup
+$RSYNC -a --delete --numeric-ids --delete-excluded $SDTD_BASE/instances/./ $NewBackup
 touch $NewBackup
 
Index: scripts/usr/local/bin/7dtd-check_mem.sh
===================================================================
--- scripts/usr/local/bin/7dtd-check_mem.sh	(revision 1)
+++ 	(revision )
@@ -1,36 +1,0 @@
-#!/bin/bash
-. /etc/7dtd.conf
-
-if [[ "$MEM_NOTIFY_XMPP" = "no" ]]; then
-	if [[ "$MEM_NOTIFY_MAIL" = "no" ]]; then
-		exit
-	fi
-fi
-
-PID=`$PIDOF 7DaysToDie.exe`
-
-if [[ -z "$PID" ]]; then
-	exit 0
-fi
-
-USED_CUR_MB=`$FREE -m | $AWK '/buffers\/cache/{print $3;}'`
-#USED_CUR_MB=`cat /proc/$PID/status | $AWK '/VmRSS/{print int($2/1024);}'`
-TELNETPORT=$(($SDTD_PORT + 3))
-#USED_CHUNKS=`echo -e "cc" | nc -q 3 127.0.0.1 $TELNETPORT | grep -a Mem | awk '/Chunk/{print $3;}'`
-
-if [ "$USED_CUR_MB" -gt "$MEM_NOTIFY_MAX_RAM" ]
-then
-	MESSAGE="7dtd: $USED_CUR_MB MiB of memory used! Chunk memory: $USED_CHUNKS"
-	if [[ "$MEM_NOTIFY_XMPP" = "yes" ]]; then
-		echo $MESSAGE | sendxmpp -u $XMPP_USER -p $XMPP_PASSWORD -j $XMPP_SERVER -t $XMPP_TARGET
-	fi
-	if [[ "$MEM_NOTIFY_MAIL" = "yes" ]]; then
-		if [[ -n "$MAIL_USER" ]]; then
-			userparam="-xu $MAIL_USER"
-		fi
-		if [[ -n "$MAIL_PASS" ]]; then
-			passparam="-xp $MAIL_PASS"
-		fi
-		sendEmail -q -f $MAIL_FROM -t $MAIL_TO -u "$MAIL_SUBJECT" -m "$MESSAGE" -s $MAIL_SMTP $userparam $passparam
-	fi
-fi
Index: scripts/usr/local/bin/7dtd-common.sh
===================================================================
--- scripts/usr/local/bin/7dtd-common.sh	(revision 9)
+++ scripts/usr/local/bin/7dtd-common.sh	(revision 9)
@@ -0,0 +1,78 @@
+#!/bin/bash
+# Provides common functions for 7dtd-scripts. Not intended to be run directly.
+
+# Check if the script is run as root (exit otherwise) and load global config
+checkRootLoadConf() {
+	if [ `id -u` -ne 0 ]; then
+		echo "This script has to be run as root!"
+		exit 10
+	fi
+	. /etc/7dtd.conf
+}
+
+# Get the config path for the given instance
+# Params:
+#   1: Instance name
+# Returns:
+#   Config path for instance
+getInstancePath() {
+	echo $SDTD_BASE/instances/$1
+}
+
+# Check if the given instance name is an existing instance
+# On failure exit the script!
+# Params:
+#   1: Instance name
+checkInstance() {
+	if [ -z $1 ]; then
+		echo "No instance given!"
+		exit 2
+	fi
+	if [ ! -d $(getInstancePath $1) ]; then
+		echo "Instance $1 does not exist!"
+		exit 3
+	fi
+}
+
+# Check if the given instance is currently running
+# Params:
+#   1: Instance name
+# Returns:
+#   0 = not running
+#   1 = running
+isRunning() {
+	start-stop-daemon --status --pidfile $(getInstancePath $1)/7dtd.pid
+	if [ $? -eq 0 ]; then
+		echo 1
+	else
+		echo 0
+	fi
+}
+
+# Get a single value from a serverconfig
+# Params:
+#   1: Instance name
+#   2: Property name
+# Returns:
+#   Property value
+getConfigValue() {
+	CONF=$(getInstancePath $1)/serverconfig.xml
+	xmllint --xpath "string(/ServerSettings/property[@name='$2']/@value)" $CONF
+}
+
+# Send a single command to the telnet port
+# Params:
+#   1: Instance name
+#   2: Command
+# Returns:
+#   String of telnet output
+telnetCommand() {
+	TEL_ENABLED=$(getConfigValue $1 TelnetEnabled)
+	TEL_PORT=$(getConfigValue $1 TelnetPort)
+	TEL_PASS=$(getConfigValue $1 TelnetPassword)	
+	if [ "$TEL_ENABLED" = "true" ] && [ -n "$TEL_PASS" ]; then
+		echo -e "$TEL_PASS\n$2\nexit" | nc -q 2 127.0.0.1 $TEL_PORT
+	else
+		echo "Telnet not enabled or no password set."
+	fi
+}
Index: scripts/usr/local/bin/7dtd-instances.sh
===================================================================
--- scripts/usr/local/bin/7dtd-instances.sh	(revision 9)
+++ scripts/usr/local/bin/7dtd-instances.sh	(revision 9)
@@ -0,0 +1,27 @@
+#!/bin/bash
+# Lists available 7dtd instances.
+# Returns:
+#  0
+
+. /usr/local/bin/7dtd-common.sh
+checkRootLoadConf
+
+printf "%-*s | %-*s | %-*s\n" 20 "Instance name" 8 "Running" 7 "Players"
+printf -v line "%*s-+-%*s-+-%*s\n" 20 " " 8 " " 7 " "
+echo ${line// /-}
+for I in $SDTD_BASE/instances/*; do
+	ins=`basename $I`
+	run=$(isRunning $ins)
+	if [ $run -eq 1 ]; then
+		run="yes"
+	else
+		run="no"
+	fi
+
+	tel=$(telnetCommand $ins lp)
+	max=$(getConfigValue $ins ServerMaxPlayerCount)
+	cur=`echo $tel | sed "s/\r/\n/g" | sed "s/^ //g" | grep "Total of " | cut -d\  -f 3`
+	
+	printf "%-*s | %*s |   %2d/%2d\n" 20 "$ins" 8 "$run" $cur $max
+done
+exit 0
Index: scripts/usr/local/bin/7dtd-kill.sh
===================================================================
--- scripts/usr/local/bin/7dtd-kill.sh	(revision 1)
+++ scripts/usr/local/bin/7dtd-kill.sh	(revision 9)
@@ -1,2 +1,24 @@
 #!/bin/bash
-/etc/init.d/7dtd.sh stop
+# Tries to stop the 7dtd instance given as first parameter.
+# Returns:
+#  0 : Done
+#  1 : Was not running
+#  2 : No instance name given
+#  3 : No such instance
+
+. /usr/local/bin/7dtd-common.sh
+checkRootLoadConf
+
+checkInstance $1
+
+res=$(isRunning $1)
+if [ $res -eq 1 ]; then
+	telnetCommand shutdown
+	start-stop-daemon --stop --pidfile $(getInstancePath $1)/7dtd.pid
+	rm $(getInstancePath $1)/7dtd.pid
+	echo "Done"	
+	exit 0
+else
+	echo "7dtd instance $1 is NOT running"
+	exit 1
+fi
Index: scripts/usr/local/bin/7dtd-running.sh
===================================================================
--- scripts/usr/local/bin/7dtd-running.sh	(revision 9)
+++ scripts/usr/local/bin/7dtd-running.sh	(revision 9)
@@ -0,0 +1,23 @@
+#!/bin/bash
+# Checks if the 7dtd instance given as first parameter is running.
+# Returns:
+#  0 : Running
+#  1 : Not running
+#  2 : No instance name given
+#  3 : No such instance
+
+. /usr/local/bin/7dtd-common.sh
+checkRootLoadConf
+
+checkInstance $1
+
+res=$(isRunning $1)
+if [ $res -eq 1 ]; then
+	echo "7dtd instance $1 is running"
+	echo "Open ports:"
+	netstat -nlp | grep 15161 | sed -r 's/^.*[^ :]*:([^ ]*).*[^ :]*:[^ ]*.*/    \1/g' | sort
+	exit 0
+else
+	echo "7dtd instance $1 is NOT running"
+	exit 1
+fi
Index: scripts/usr/local/bin/7dtd-start.sh
===================================================================
--- scripts/usr/local/bin/7dtd-start.sh	(revision 1)
+++ scripts/usr/local/bin/7dtd-start.sh	(revision 9)
@@ -1,2 +1,43 @@
 #!/bin/bash
-/etc/init.d/7dtd.sh start
+# Tries to start the 7dtd instance given as first parameter.
+# Returns:
+#  0 : Done
+#  1 : Was already running
+#  2 : No instance name given
+#  3 : No such instance
+#  5 : Unknown error when starting engine
+
+. /usr/local/bin/7dtd-common.sh
+checkRootLoadConf
+
+checkInstance $1
+
+res=$(isRunning $1)
+if [ $res -eq 0 ]; then
+	if [ ! `pgrep Xvfb` ]; then
+		echo "Xvfb not yet running. Starting..."
+		su -c "/usr/bin/Xvfb :1 -screen 0 640x480x16" $SDTD_USER &> /dev/null &
+		sleep 3
+	fi
+	export DISPLAY=localhost:1.0
+	
+	SSD_PID="--pidfile $(getInstancePath $1)/7dtd.pid --make-pidfile"
+	SSD_DAEMON="--background --no-close"
+	SSD_USER="--chuid $SDTD_USER:$SDTD_GROUP --user $SDTD_USER"
+	OPTS="-quit -batchmode -nographics -configfile=$(getInstancePath $1)/serverconfig.xml -dedicated"
+	
+	start-stop-daemon --start $SSD_PID $SSD_DAEMON $SSD_USER --chdir $SDTD_ROOT --exec $WINE -- $SDTD_ROOT/7DaysToDie.exe $OPTS > $(getInstancePath $1)/stdout.log 2>&1
+	sleep 1
+	res=$(isRunning $1)
+	if [ $res -eq 1 ]; then
+		echo "Done!"
+		exit 0
+	else
+		echo "Failed!"
+		rm -f $(getInstancePath $1)/7dtd.pid
+		exit 5
+	fi
+else
+	echo "7dtd instance $1 is already running"
+	exit 1
+fi
Index: scripts/usr/local/bin/7dtd-update.sh
===================================================================
--- scripts/usr/local/bin/7dtd-update.sh	(revision 1)
+++ scripts/usr/local/bin/7dtd-update.sh	(revision 9)
@@ -1,4 +1,15 @@
 #!/bin/bash
-. /etc/7dtd.conf
+. /usr/local/bin/7dtd-common.sh
+checkRootLoadConf
+
+for I in $SDTD_BASE/instances/*; do
+	ins=`basename $I`
+	run=$(isRunning $ins)
+	if [ $run -eq 1 ]; then
+		echo "At least one instance is still running."
+		echo "Before updating the engine please stop all instances!"
+		exit 1
+	fi
+done
 
 if [ ! -e $STEAMCMD_ROOT ]; then
@@ -13,5 +24,5 @@
 cd $STEAMCMD_ROOT
 
-./steamcmd.sh +@sSteamCmdForcePlatformType windows +login $STEAM_USER $STEAM_PASS +force_install_dir $SDTD_ROOT +app_update 251570 validate +quit
+./steamcmd.sh +@sSteamCmdForcePlatformType windows +login $STEAM_USER $STEAM_PASS +force_install_dir $SDTD_ROOT "+app_update 251570" validate +quit
 chown $SDTD_USER.$SDTD_GROUP -R $SDTD_ROOT
 
@@ -19,3 +30,3 @@
 cp $SDTD_ROOT/Install/32bit/mono.dll $SDTD_ROOT/7DaysToDie_Data/Mono/
 cp $SDTD_ROOT/Install/32bit/SteamworksManaged.dll $SDTD_ROOT/7DaysToDie_Data/Managed/
-cp $SDTD_ROOT/../msvcr100.dll $SDTD_ROOT/
+cp $SDTD_BASE/msvcr100.dll $SDTD_ROOT/
