2. git clone this repository into that user's home directory and rename it to .minetest
3. cd into .minetest
4. run scripts/setup.sh - this will automatically install minetest and screen. Also, it initialized the submodules - all external mods and MineClone2 are installed automatically. It will also install multiserver and its dependencies.
-5. run scripts/start.sh - this will automatically start all worlds. If one world crashes / shuts down it will automatically restart.
+5. run scripts/start.sh - this will automatically start all worlds and multiserver. If one world or multiserver crashes / shuts down it will automatically restart.
-To update, run scripts/update.sh, to restart all worlds run scripts/restart.sh and to stop all worlds run scripts/stop.sh
+To update, run scripts/update.sh, to restart all worlds and multiserver run scripts/restart.sh and to stop all worlds and multiserver run scripts/stop.sh
Organisation structure
-------------------
scripts/update.sh: This will pull the repository including all submodules. Also, it will update minetest, screen and multiserver.
-scripts/start.sh: You can use this to start one or all worlds from the worlds folder. If you pass an argument to it, it will start the specified world, else it will start everything. You can use this script even if some worlds are already running. The worlds will be started in a hidden screen and restarted when killed, shut down using /shutdown or crash. Any started world will have a lock file in the /tmp directory that contains the PID of the current minetest process. When the world is stopped, the lock file is deleted.
+scripts/start.sh: You can use this to start one or all worlds from the worlds folder. If you pass an argument to it, it will start the specified world, else it will start everything. You can use this script even if some worlds are already running. The worlds will be started in a hidden screen and restarted when killed, shut down using /shutdown or crash. Any started world will have a lock file in the /tmp directory that contains the PID of the current minetest process. When the world is stopped, the lock file is deleted. If --multiserver is used, multiserver is started instead of any worlds, and if all worlds are started, multiserver is started as well.
-scripts/stop.sh: You can use this to stop one or all worlds from the worlds folder started using the start script. If you pass an argument to it, it will stop the specified world, else it will stop everything. You can use this script even if some worlds are not running.
+scripts/stop.sh: You can use this to stop one or all worlds from the worlds folder started using the start script. If you pass an argument to it, it will stop the specified world, else it will stop everything. You can use this script even if some worlds are not running. If --multiserver is used, multiserver is stopped instead of any worlds, and if all worlds are stopped, multiserver is stopped as well.
-scripts/restart.sh: You can use this to restart one or all running worlds. You can use this script even if some worlds are not running. It will only restart the running worlds.
+scripts/restart.sh: You can use this to restart one or all running worlds. You can use this script even if some worlds are not running. It will only restart the running worlds. If --multiserver is used, multiserver is restarted instead of any worlds (in case it is running) and if all worlds are restarted, multiserver is restarted as well (in case it is running).
-scripts/console.sh: You can used this to access the console of the world specified in the argument. (minetest --terminal running in a screen)
+scripts/console.sh: You can used this to access the console of the world specified in the argument (minetest --terminal running in a screen). If --multiserver is used, the multiserver screen will be shown.
scripts/common.sh: This script should not be started, it contains common functions imported by other scripts. You can modify it to e.g. change the paths of lock files or screen names.
echo "/tmp/ElidragonV2_$1_lock"
}
+function multiserver_lock {
+ echo "/tmp/ElidragonV2_Multiserver_lock"
+}
+
function world_screenname {
echo "Elidragon v2 - $1"
}
+function multiserver_screenname {
+ echo "Elidragon v2 - Multiserver"
+}
+
function kill_world {
kill `cat \`world_lock $1\``
}
-function is_running {
- return $(test -f `world_lock $1`)
+function kill_multiserver {
+ kill -2 `cat \`multiserver_lock\``
}
-function loop_worlds {
- WORLDS=`ls worlds`
- for WORLD in $WORLDS; do
- $1 $WORLD
- done
+function world_running {
+ return $([ -f `world_lock $1` ])
+}
+
+function multiserver_running {
+ return $([ -f `multiserver_lock` ])
}
function assert_running {
- if ! is_running $1; then
+ if ! world_running $1; then
echo -e "\e[31mWorld $1 is not running\e[0m"
- if [ -z "$2" ]; then
+ if [ -z $2 ]; then
exit 1
else
return 1
}
function assert_not_running {
- if is_running $1; then
+ if world_running $1; then
echo -e "\e[31mWorld $1 is already running\e[0m"
- if [ -z "$2" ]; then
+ if [ -z $2 ]; then
exit 1
else
return 1
fi
}
+function loop_worlds {
+ WORLDS=`ls worlds`
+ for WORLD in $WORLDS; do
+ $1 $WORLD
+ done
+}
+
+function run_one_or_all {
+ if [ -z $2 ]; then
+ loop_worlds $1
+ return 0
+ else
+ $1 $2
+ return 1
+ fi
+}
+
+function run_in_screen {
+ screen -dmS $1 bash -c "
+ touch $2
+ while [ -f $2; ] do
+ bash -c \"
+ echo \\$\\$ > $2
+ exec $3
+ \"
+ done
+ "
+}
+
+function start_multiserver {
+ echo -n "Starting Multiserver... "
+ if multiserver_running; then
+ echo -e "\e[31mMultiserver is already running\e[0m"
+ else
+ run_in_screen `multiserver_screenname` `multiserver_lock` "~/go/bin/multiserver"
+ echo -e "\e[32mDone\e[0m"
+ fi
+}
+
+function stop_multiserver {
+ echo -n "Stopping Multiserver... "
+ if multiserver_running; then
+ kill_multiserver
+ rm `multiserver_lock`
+
+ echo -e "\e[32mDone\e[0m"
+ else
+ echo -e "\e[31mMultiserver is not running\e[0m"
+ fi
+}
+
+function restart_multiserver {
+ echo -n "Multiserver..."
+ if multiserver_running; then
+ kill_multiserver
+
+ echo -e "\e[32mDone\e[0m"
+ else
+ echo -e "\e[31mMultiserver is not running\e[0m"
+ fi
+}
+
function start_world {
echo -n "Starting $1... "
if assert_not_running $1 "true"; then
- LOCK=`world_lock $1`
-
- screen -dmS `world_screenname $1` bash -c "
- while is_running $1; do
- bash -c \"
- echo \\$\\$ > $LOCK
- exec minetest --server --terminal --world worlds/$1 --config worlds/$1/minetest.conf --logfile worlds/$1/debug.txt
- \"
- done
- rm $LOCK
- "
-
+ run_in_screen `world_screenname $1` `world_lock $1` "minetest --server --terminal --world worlds/$1 --config worlds/$1/minetest.conf --logfile worlds/$1/debug.txt"
echo -e "\e[32mDone\e[0m"
fi
}
echo -e "\e[32mDone\e[0m"
fi
}
-
-function run_one_or_all {
- if [ -z "$2" ]; then
- loop_worlds $1
- else
- $1 $2
- fi
-}
#! /bin/bash
# Elidragon v2 console script
-# Attach to the console of a world
+# Attach to the console of a world or multiserver
# Arguments: <worldname>
source scripts/common.sh
-assert_running $1
-screen -r `world_screenname $1`
+if [[ $1 == "--multiserver" ]]; then
+ screen -r `multiserver_sceenname`
+else
+ assert_running $1
+ screen -r `world_screenname $1`
+fi
#! /bin/bash
# Elidragon v2 restart script
-# Restart one or all worlds
-# Arguments: [<worldname>]
+# Restart one or all worlds, or if --multiserver is used, the multiserver. If all worlds are restarted, multiserver is restarted as well
+# Arguments: [<worldname> | --multiserver]
source source scripts/common.sh
-run_one_or_all restart_world $1
+if [[ $1 == "--multiserver" || run_one_or_all restart_world $1 ]]; then
+ restart_multiserver
+fi
#! /bin/bash
# Elidragon v2 start script
-# Start one or all worlds
+# Start one or all worlds, or if --multiserver is used, the multiserver. If all worlds are started, multiserver is started as well
# Arguments: [<worldname>]
source source scripts/common.sh
-run_one_or_all start_world $1
+if [ $1 = "--multiserver" ] || run_one_or_all start_world $1; then
+ start_multiserver
+fi
#! /bin/bash
# Elidragon v2 stop script
-# Stop one or all worlds
+# Stop one or all worlds, or if --multiserver is used, the multiserver. If all worlds are stopped, multiserver is stopped as well
# Arguments: [<worldname>]
-source scripts/internal.sh
+source scripts/common.sh
-run_one_or_all stop_world $1
+if [[ $1 == "--multiserver" || run_one_or_all stop_world $1 ]]; then
+ stop_multiserver
+fi