]> git.lizzy.rs Git - elidragon_v2.git/commitdiff
Update scripts to include multiserver
authorElias Fleckenstein <eliasfleckenstein@web.de>
Sat, 20 Feb 2021 12:17:55 +0000 (13:17 +0100)
committerElias Fleckenstein <eliasfleckenstein@web.de>
Sat, 20 Feb 2021 12:17:55 +0000 (13:17 +0100)
README
scripts/common.sh
scripts/console.sh
scripts/restart.sh
scripts/start.sh
scripts/stop.sh

diff --git a/README b/README
index c33aec8ca71902ad8d6dc6b2526b99ac121388d5..6ca1b5ffc61f60b303d9cdd98290e3aa6ae7ce21 100644 (file)
--- a/README
+++ b/README
@@ -20,9 +20,9 @@ Elidragon v2 requires a GNU/Linux system to run. The setup and update scripts re
 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
 -------------------
@@ -38,13 +38,13 @@ scripts/setup.sh: This will install minetest and screen using sudo apt. For mine
 
 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.
 
index 2f65662991b647f98f4fa146144373470cda27a5..caa3dad3944372714da0b4ae12b1c8367404c805 100644 (file)
@@ -4,29 +4,38 @@ function world_lock {
        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
@@ -35,9 +44,9 @@ function assert_running {
 }
 
 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
@@ -45,21 +54,72 @@ function assert_not_running {
        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
 }
@@ -82,11 +142,3 @@ function restart_world {
                echo -e "\e[32mDone\e[0m"
        fi
 }
-
-function run_one_or_all {
-       if [ -z "$2" ]; then
-               loop_worlds $1
-       else
-               $1 $2
-       fi
-}
index 77d876db16bd233c9192fb0ff500dcfbb1193307..ef1538c175659fa9f1ac20bd8978da12404631e7 100755 (executable)
@@ -1,9 +1,13 @@
 #! /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
index f1e0f3a04998fc48ab218c57721a7e0d1e62819c..53a385f19e6a468b4932e9e1e2148442bba2ddd6 100755 (executable)
@@ -1,8 +1,10 @@
 #! /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
index 254b3a775962d8eb849837f221128f3b3b0aa986..06a96e2e7cdaebc9ad8bab35aafdf904a36eefff 100755 (executable)
@@ -1,8 +1,10 @@
 #! /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
index 7e95f2c040d86f033b4edb97ec35223f1230de77..8297ddc1e2c455cb7e4a9cc3eaae7b8e30f164f9 100755 (executable)
@@ -1,8 +1,10 @@
 #! /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