aboutsummarylogtreecommitdiffstats
diff options
context:
space:
mode:
authorGordian Edenhofer2021-12-22 16:18:11 +0100
committerGordian Edenhofer2021-12-22 16:25:33 +0100
commit387f3f655e8858d74295eaa128805280cb00eb00 (patch)
tree98f4779619fb96460c6a7a6dc788b85fd4612c10
parent264c0d286decc8df1efabb281b330f70ba8616e9 (diff)
downloadaur-387f3f655e8858d74295eaa128805280cb00eb00.tar.gz
upgpkg: minecraft-server 1.18.1-2
Fork all files relating to managing a minecraft server into a dedicated repository. Alert the user of this change by adding READMEs in the directories of the server. upgpkg: cuberite 1.12.2c1_1be14eb-1 upgpkg: cuberite-bin 1.12.2b293-3 upgpkg: papermc 1.18.1+b68-2 upgpkg: spigot 1.18.1+b141-5
-rw-r--r--.SRCINFO18
-rwxr-xr-xPKGBUILD48
-rw-r--r--README.md6
-rw-r--r--spigot-backup.service12
-rw-r--r--spigot-backup.timer10
-rw-r--r--spigot.conf27
-rwxr-xr-xspigot.service13
-rwxr-xr-xspigot.sh549
-rw-r--r--spigot.sysusers1
-rw-r--r--spigot.tmpfiles5
10 files changed, 33 insertions, 656 deletions
diff --git a/.SRCINFO b/.SRCINFO
index e9d9942ab71f..595633c71d31 100644
--- a/.SRCINFO
+++ b/.SRCINFO
@@ -1,7 +1,7 @@
pkgbase = spigot
pkgdesc = High performance Minecraft server implementation
pkgver = 1.18.1+b141
- pkgrel = 4
+ pkgrel = 5
url = https://www.spigotmc.org/
install = spigot.install
arch = any
@@ -25,20 +25,8 @@ pkgbase = spigot
conflicts = spigot-patcher
backup = etc/conf.d/spigot
source = BuildTools-1.18.1+b141.jar::https://hub.spigotmc.org/jenkins/job/BuildTools/141/artifact/target/BuildTools.jar
- source = spigot-backup.service
- source = spigot-backup.timer
- source = spigot.service
- source = spigot.sysusers
- source = spigot.tmpfiles
- source = spigot.conf
- source = spigot.sh
+ source = minecraft-server-1.0.0.tar.gz::https://github.com/Edenhofer/minecraft-server/archive/refs/tags/v1.0.0.tar.gz
sha512sums = d4ffaf205dd8565f133c0045e8eee1e6ef3cadaff899fa5c04deada1f9727cd025e41e0dbbfdb20a403406e502d92e20cbe62396e78a5f2a7a738976e51571de
- sha512sums = 03ba1032b687553831021cfb0bed489e6301d0446c3b4f56d989d203855952911f3b1caaa00596f4731060ddf6684f66c3d674f3c5546b600cbe6585fc8560fb
- sha512sums = 76c77e47c442b477216e968db2213612579b24add54cf0e0512f808498673500b4d24e59bce70b1e7479d724a9a897ceb154e937b88a476beb11c8776258b36c
- sha512sums = 5a32439ff4b8fa9db89e9242206cf99109e0b00f29f87711c25342dda522171d999f7e18fb2013437ddf62cfec05b6677601933233aaf42bcb5d67eb7a1469ee
- sha512sums = eac1deb53fa9d522af272fa2d9093b98e7d51aa4c0730471e5c575752733500b84a06bc19d1fe83b4c48e41b7f0e11efb23881bfadce4a40d2bfed7cbe5a5bf7
- sha512sums = f3b3005a8ee643cb7d8fa24a3d1141604157efd2147d07aa7f839b070370cbed66ccf3c34317181e9601f2aadb5224002617226c99e36b677c0fc3de0b42d0d8
- sha512sums = 2f5d71911c9ee7e7763d3300f335245a531a9e00d23e4d007ce76f4175dd7ecd9d8f0425af86a885797764690db64bfa558b49719f3d9d85a46df89443bcdf7b
- sha512sums = 49414f963ad4c8ea49c8dcc05c47f2c2df1733eaaef99980b243d7b158c414c90398493dfcd0e3388d103784c3e6a28a63bf39d9a4261b1024ebbb87d9c62e5a
+ sha512sums = e315277da81cb28de338e870f477dc58dc9d8f8542594431ab5321150c92ff5634ace2be8c6778d1edb718fdeb6850d7021bffcbd3cae2a00f20e3a64caa3d92
pkgname = spigot
diff --git a/PKGBUILD b/PKGBUILD
index db3a1183c41a..3c8c47e50762 100755
--- a/PKGBUILD
+++ b/PKGBUILD
@@ -5,7 +5,8 @@ pkgname=spigot
_pkgver=1.18.1
_build=141
pkgver="${_pkgver}+b${_build}"
-pkgrel=4
+pkgrel=5
+_mng_ver=1.0.0
pkgdesc="High performance Minecraft server implementation"
arch=('any')
url="https://www.spigotmc.org/"
@@ -19,21 +20,9 @@ conflicts=("bukkit" "craftbukkit" "spigot-patcher")
backup=("etc/conf.d/${pkgname}")
install="${pkgname}.install"
source=("BuildTools-${_pkgver}+b${_build}.jar::https://hub.spigotmc.org/jenkins/job/BuildTools/${_build}/artifact/target/BuildTools.jar"
- "${pkgname}-backup.service"
- "${pkgname}-backup.timer"
- "${pkgname}.service"
- "${pkgname}.sysusers"
- "${pkgname}.tmpfiles"
- "${pkgname}.conf"
- "${pkgname}.sh")
+ "minecraft-server-${_mng_ver}.tar.gz"::"https://github.com/Edenhofer/minecraft-server/archive/refs/tags/v${_mng_ver}.tar.gz")
sha512sums=('d4ffaf205dd8565f133c0045e8eee1e6ef3cadaff899fa5c04deada1f9727cd025e41e0dbbfdb20a403406e502d92e20cbe62396e78a5f2a7a738976e51571de'
- '03ba1032b687553831021cfb0bed489e6301d0446c3b4f56d989d203855952911f3b1caaa00596f4731060ddf6684f66c3d674f3c5546b600cbe6585fc8560fb'
- '76c77e47c442b477216e968db2213612579b24add54cf0e0512f808498673500b4d24e59bce70b1e7479d724a9a897ceb154e937b88a476beb11c8776258b36c'
- '5a32439ff4b8fa9db89e9242206cf99109e0b00f29f87711c25342dda522171d999f7e18fb2013437ddf62cfec05b6677601933233aaf42bcb5d67eb7a1469ee'
- 'eac1deb53fa9d522af272fa2d9093b98e7d51aa4c0730471e5c575752733500b84a06bc19d1fe83b4c48e41b7f0e11efb23881bfadce4a40d2bfed7cbe5a5bf7'
- 'f3b3005a8ee643cb7d8fa24a3d1141604157efd2147d07aa7f839b070370cbed66ccf3c34317181e9601f2aadb5224002617226c99e36b677c0fc3de0b42d0d8'
- '2f5d71911c9ee7e7763d3300f335245a531a9e00d23e4d007ce76f4175dd7ecd9d8f0425af86a885797764690db64bfa558b49719f3d9d85a46df89443bcdf7b'
- '49414f963ad4c8ea49c8dcc05c47f2c2df1733eaaef99980b243d7b158c414c90398493dfcd0e3388d103784c3e6a28a63bf39d9a4261b1024ebbb87d9c62e5a')
+ 'e315277da81cb28de338e870f477dc58dc9d8f8542594431ab5321150c92ff5634ace2be8c6778d1edb718fdeb6850d7021bffcbd3cae2a00f20e3a64caa3d92')
_game="spigot"
_server_root="/srv/craftbukkit"
@@ -41,27 +30,38 @@ _server_root="/srv/craftbukkit"
build() {
export MAVEN_OPTS="-Xmx2g"
java -jar "BuildTools-${_pkgver}+b${_build}.jar" --rev "${_pkgver}"
+
+ make -C "${srcdir}/minecraft-server-${_mng_ver}" clean
+
+ make -C "${srcdir}/minecraft-server-${_mng_ver}" \
+ GAME=${_game} \
+ MYNAME=${_game} \
+ SERVER_ROOT=${_server_root} \
+ BACKUP_PATHS="world world_nether world_the_end" \
+ GAME_USER=craftbukkit \
+ MAIN_EXECUTABLE=spigot.jar \
+ SERVER_START_CMD="java -Xms512M -Xmx1024M -jar ./spigot.jar nogui" \
+ all
}
package() {
- install -Dm644 "${_game}.conf" "${pkgdir}/etc/conf.d/${_game}"
- install -Dm755 "${_game}.sh" "${pkgdir}/usr/bin/${_game}"
- install -Dm644 "${_game}.service" "${pkgdir}/usr/lib/systemd/system/${_game}.service"
- install -Dm644 "${_game}-backup.service" "${pkgdir}/usr/lib/systemd/system/${_game}-backup.service"
- install -Dm644 "${_game}-backup.timer" "${pkgdir}/usr/lib/systemd/system/${_game}-backup.timer"
+ make -C "${srcdir}/minecraft-server-${_mng_ver}" \
+ DESTDIR="${pkgdir}" \
+ GAME=${_game} \
+ MYNAME=${_game} \
+ install
+
install -Dm644 "${_game}-${_pkgver}.jar" "${pkgdir}${_server_root}/${_game}.${_pkgver}.jar"
- install -Dm644 "${_game}.sysusers" "${pkgdir}/usr/lib/sysusers.d/${_game}.conf"
- install -Dm644 "${_game}.tmpfiles" "${pkgdir}/usr/lib/tmpfiles.d/${_game}.conf"
ln -s "${_game}.${_pkgver}.jar" "${pkgdir}${_server_root}/${_game}.jar"
# Link the log files
mkdir -p "${pkgdir}/var/log/"
- install -dm775 "${pkgdir}/${_server_root}/logs"
+ install -dm2775 "${pkgdir}/${_server_root}/logs"
ln -s "${_server_root}/logs" "${pkgdir}/var/log/${_game}"
# Give the group write permissions and set user or group ID on execution
chmod g+ws "${pkgdir}${_server_root}"
# Make plugins folder ready for drag and drop
- install -dm777 "${pkgdir}/${_server_root}/plugins"
+ install -dm2775 "${pkgdir}/${_server_root}/plugins"
}
diff --git a/README.md b/README.md
new file mode 100644
index 000000000000..e8639fddd80a
--- /dev/null
+++ b/README.md
@@ -0,0 +1,6 @@
+# Minecraft Server Management Script
+
+The management script to control this minecraft flavor was moved to a dedicated repository at [GitHub:Edenhofer/minecraft-server](https://github.com/Edenhofer/minecraft-server).
+The script works for various flavors of minecraft.
+It is very minimalist yet versatile and feature-rich.
+For more information on how to configure and install the script separately, visit the above linked repository.
diff --git a/spigot-backup.service b/spigot-backup.service
deleted file mode 100644
index 5c497785bdcb..000000000000
--- a/spigot-backup.service
+++ /dev/null
@@ -1,12 +0,0 @@
-[Unit]
-Description=Spigot World Backup
-After=local-fs.target
-
-[Service]
-Type=oneshot
-ExecStart=/usr/bin/spigot backup
-User=craftbukkit
-Group=craftbukkit
-
-[Install]
-WantedBy=multi-user.target
diff --git a/spigot-backup.timer b/spigot-backup.timer
deleted file mode 100644
index be4b690d86b2..000000000000
--- a/spigot-backup.timer
+++ /dev/null
@@ -1,10 +0,0 @@
-[Unit]
-Description=Daily Spigot Backup
-
-[Timer]
-OnCalendar=daily
-AccuracySec=5min
-Persistent=true
-
-[Install]
-WantedBy=multi-user.target
diff --git a/spigot.conf b/spigot.conf
deleted file mode 100644
index 9484bad47bb3..000000000000
--- a/spigot.conf
+++ /dev/null
@@ -1,27 +0,0 @@
-# THIS IS THE CONFIGURATION FILE FOR THE MANAGING SCRIPT NOT FOR THE ACTUAL SERVER
-# Variables are interpreted in bash. Simply using bash-syntax is sufficient.
-
-# General parameters
-SERVER_ROOT="/srv/craftbukkit"
-BACKUP_DEST="/srv/craftbukkit/backup"
-BACKUP_PATHS="world world_nether world_the_end" # World paths separated by spaces relative to SERVER_ROOT
-KEEP_BACKUPS="10"
-GAME_USER="craftbukkit"
-MAIN_EXECUTABLE="spigot.jar"
-SESSION_NAME="spigot"
-
-# System parameters for java
-# -Xms sets the intial heap size (must be a multiple of 1024 and greater than 2MB, no spaces!)
-# -Xmx sets the maximum heap size (must be a multiple of 1024 and greater than 2MB, no spaces!)
-SERVER_START_CMD="java -Xms512M -Xmx1024M -jar './${MAIN_EXECUTABLE}' nogui"
-
-# System parameters for the actual game server
-# Describes whether a daemon process which stops the server if it is not used by a player
-# within IDLE_IF_TIME seconds should be started. The GAME_PORT is not inhereted to the server!
-IDLE_SERVER=false # true or false
-# Ensure that if SESSION_NAME is passed through the command line and therefore set to read only by the script,
-# IDLE_SESSION_NAME gets altered according to the command line and not the configurtion file, hence invoke the variable
-IDLE_SESSION_NAME="idle_server_${SESSION_NAME}"
-GAME_PORT="25565" # used to listen for incoming connections when the server is down
-CHECK_PLAYER_TIME="30" # in seconds
-IDLE_IF_TIME="1200" # in seconds
diff --git a/spigot.service b/spigot.service
deleted file mode 100755
index 840ced4720c6..000000000000
--- a/spigot.service
+++ /dev/null
@@ -1,13 +0,0 @@
-[Unit]
-Description=Spigot
-After=local-fs.target network.target multi-user.target
-
-[Service]
-Type=forking
-ExecStart=/usr/bin/spigot start
-ExecStop=/usr/bin/spigot stop
-User=craftbukkit
-Group=craftbukkit
-
-[Install]
-WantedBy=multi-user.target
diff --git a/spigot.sh b/spigot.sh
deleted file mode 100755
index 4cd2d1a6d621..000000000000
--- a/spigot.sh
+++ /dev/null
@@ -1,549 +0,0 @@
-#!/bin/bash
-
-# The actual program name
-declare -r myname="spigot"
-declare -r game="spigot"
-
-# General rule for the variable-naming-schema:
-# Variables in capital letters may be passed through the command line others not.
-# Avoid altering any of those later in the code since they may be readonly (IDLE_SERVER is an exception!)
-
-# You may use this script for any game server of your choice, just alter the config file
-[[ -n "${SERVER_ROOT}" ]] && declare -r SERVER_ROOT=${SERVER_ROOT} || SERVER_ROOT="/srv/craftbukkit"
-[[ -n "${BACKUP_DEST}" ]] && declare -r BACKUP_DEST=${BACKUP_DEST} || BACKUP_DEST="/srv/craftbukkit/backup"
-[[ -n "${BACKUP_PATHS}" ]] && declare -r BACKUP_PATHS=${BACKUP_PATHS} || BACKUP_PATHS="world world_nether world_the_end"
-[[ -n "${BACKUP_FLAGS}" ]] && declare -r BACKUP_FLAGS=${BACKUP_FLAGS} || BACKUP_FLAGS="-z"
-[[ -n "${KEEP_BACKUPS}" ]] && declare -r KEEP_BACKUPS=${KEEP_BACKUPS} || KEEP_BACKUPS="10"
-[[ -n "${GAME_USER}" ]] && declare -r GAME_USER=${GAME_USER} || GAME_USER="craftbukkit"
-[[ -n "${MAIN_EXECUTABLE}" ]] && declare -r MAIN_EXECUTABLE=${MAIN_EXECUTABLE} || MAIN_EXECUTABLE="spigot.jar"
-[[ -n "${SESSION_NAME}" ]] && declare -r SESSION_NAME=${SESSION_NAME} || SESSION_NAME="${game}"
-
-# Command and parameter declaration with which to start the server
-[[ -n "${SERVER_START_CMD}" ]] && declare -r SERVER_START_CMD=${SERVER_START_CMD} || SERVER_START_CMD="java -Xms512M -Xmx1024M -jar './${MAIN_EXECUTABLE}' nogui"
-[[ -n "${SERVER_START_SUCCESS}" ]] && declare -r SERVER_START_SUCCESS=${SERVER_START_SUCCESS} || SERVER_START_SUCCESS="done"
-
-# System parameters for the control script
-[[ -n "${IDLE_SERVER}" ]] && tmp_IDLE_SERVER=${IDLE_SERVER} || IDLE_SERVER="false"
-[[ -n "${IDLE_SESSION_NAME}" ]] && declare -r IDLE_SESSION_NAME=${IDLE_SESSION_NAME} || IDLE_SESSION_NAME="idle_server_${SESSION_NAME}"
-[[ -n "${GAME_PORT}" ]] && declare -r GAME_PORT=${GAME_PORT} || GAME_PORT="25565"
-[[ -n "${CHECK_PLAYER_TIME}" ]] && declare -r CHECK_PLAYER_TIME=${CHECK_PLAYER_TIME} || CHECK_PLAYER_TIME="30"
-[[ -n "${IDLE_IF_TIME}" ]] && declare -r IDLE_IF_TIME=${IDLE_IF_TIME} || IDLE_IF_TIME="1200"
-
-# Additional configuration options which only few may need to alter
-[[ -n "${GAME_COMMAND_DUMP}" ]] && declare -r GAME_COMMAND_DUMP=${GAME_COMMAND_DUMP} || GAME_COMMAND_DUMP="/tmp/${myname}_${SESSION_NAME}_command_dump.txt"
-
-# Variables passed over the command line will always override the one from a config file
-source /etc/conf.d/"${game}" 2>/dev/null || >&2 echo "Could not source /etc/conf.d/${game}"
-
-# Preserve the content of IDLE_SERVER without making it readonly
-[[ -n ${tmp_IDLE_SERVER} ]] && IDLE_SERVER=${tmp_IDLE_SERVER}
-
-
-# Strictly disallow uninitialized Variables
-set -u
-# Exit if a single command breaks and its failure is not handled accordingly
-set -e
-
-MAX_SERVER_START_TIME=150
-
-# Check whether sudo is needed at all
-if [[ "$(whoami)" == "${GAME_USER}" ]]; then
- SUDO_CMD=""
-else
- SUDO_CMD="sudo -u ${GAME_USER}"
-fi
-
-# Choose which flavor of netcat is to be used
-if command -v netcat &> /dev/null; then
- NETCAT_CMD="netcat"
-elif command -v ncat &> /dev/null; then
- NETCAT_CMD="ncat"
-else
- NETCAT_CMD=""
-fi
-
-# Check for sudo rigths
-if [[ "$(${SUDO_CMD} whoami)" != "${GAME_USER}" ]]; then
- >&2 echo -e "You have \e[39;1mno permission\e[0m to run commands as $GAME_USER user."
- exit 21
-fi
-
-# Pipe any given argument to the game server console,
-# sleep for $sleep_time and return its output if $return_stdout is set
-game_command() {
- ${SUDO_CMD} tmux -L "${SESSION_NAME}" wait-for -L "command_lock"
- if [[ -z "${return_stdout:-}" ]]; then
- ${SUDO_CMD} tmux -L "${SESSION_NAME}" send-keys -t "${SESSION_NAME}":0.0 "$*" Enter
- else
- ${SUDO_CMD} tmux -L "${SESSION_NAME}" pipe-pane -t "${SESSION_NAME}":0.0 "cat > ${GAME_COMMAND_DUMP}"
- ${SUDO_CMD} tmux -L "${SESSION_NAME}" send-keys -t "${SESSION_NAME}":0.0 "$*" Enter
- sleep "${sleep_time:-0.3}"
- ${SUDO_CMD} tmux -L "${SESSION_NAME}" pipe-pane -t "${SESSION_NAME}":0.0
- ${SUDO_CMD} cat "${GAME_COMMAND_DUMP}"
- fi
- ${SUDO_CMD} tmux -L "${SESSION_NAME}" wait-for -U "command_lock"
-}
-
-# Check whether there are player on the server through list
-is_player_online() {
- response="$(sleep_time=0.6 return_stdout=true game_command list)"
- # Delete leading line and fancy characters from free response string
- response="$(echo "${response}" | sed -r -e 's/\x1B\[([0-9]{1,2}(;[0-9]{1,2})*)?[JKmsuG]//g')"
- # The list command prints a line containing the usernames after the last occurrence of ": "
- # and since playernames may not contain this string the clean player-list can easily be retrieved.
- # Otherwise check the first digit after the last occurrence of "There are". If it is 0 then there
- # are no players on the server. Should this test fail as well. Assume that a player is online.
- if [[ $(echo "${response}" | grep ":" | sed -e 's/.*\: //' | tr -d '\n' | wc -c) -le 1 ]]; then
- # No player is online
- return 0
- elif [[ "x$(echo "${response}" | grep "There are" | sed -r -e 's/.*\: //' -e 's/^([^.]+).*$/\1/; s/^[^0-9]*([0-9]+).*$/\1/' | tr -d '\n')" == "x0" ]]; then
- # No player is online
- return 0
- else
- # A player is online (or it could not be determined)
- return 1
- fi
-}
-
-# Check whether the server is visited by a player otherwise shut it down
-idle_server_daemon() {
- # This function is run within a tmux session of the GAME_USER therefore SUDO_CMD can be omitted
- if [[ "$(whoami)" != "${GAME_USER}" ]]; then
- >&2 echo "Somehow this hidden function was not executed by the ${GAME_USER} user."
- >&2 echo "This should not have happend. Are you messing around with this script? :P"
- exit 22
- fi
-
- # Time in seconds for which no player was on the server
- no_player=0
-
- while true; do
- printf "no_player: %10ss check_player_time: %10ss idle_if_time: %10ss\n" "${no_player}" "${CHECK_PLAYER_TIME}" "${IDLE_IF_TIME}"
- # Retry in ${CHECK_PLAYER_TIME} seconds
- sleep ${CHECK_PLAYER_TIME}
-
- if socket_has_session "${SESSION_NAME}"; then
- # Game server is up and running
- # Check for active player
- if [[ -n "$(tmux -L "${SESSION_NAME}" list-clients -t "${SESSION_NAME}":0.0 2> /dev/null)" ]]; then
- # An administrator is connected to the console, pause player checking
- echo "An admin is connected to the console. Pause player checking."
- elif SUDO_CMD="" is_player_online; then
- # No player was seen on the server through list
- no_player=$(( no_player + CHECK_PLAYER_TIME ))
- # Stop the game server if no player was active for at least ${IDLE_IF_TIME}
- if [[ "${no_player}" -ge "${IDLE_IF_TIME}" ]]; then
- IDLE_SERVER="false" ${myname} stop
- # Wait for game server to go down
- for i in {1..100}; do
- socket_has_session "${SESSION_NAME}" || break
- [[ $i -eq 100 ]] && echo -e "An \e[39;1merror\e[0m occurred while trying to reset the idle_server!"
- sleep 0.1
- done
- # Reset timer and give the player 300 seconds to connect after pinging
- no_player=$(( IDLE_IF_TIME - 300 ))
- # Game server is down, listen on port ${GAME_PORT} for incoming connections
- echo -n "Netcat: "
- ${NETCAT_CMD} -v -l -p ${GAME_PORT} 2>&1 | (grep -m1 -i "connect" && pkill -P $$ ${NETCAT_CMD}) || true
- echo "Netcat caught a connection. The server is coming up again..."
- IDLE_SERVER="false" ${myname} start
- fi
- else
- # Reset timer since there is an active player on the server
- no_player=0
- fi
- else
- # Reset timer and give the player 300 seconds to connect after pinging
- no_player=$(( IDLE_IF_TIME - 300 ))
- # Game server is down, listen on port ${GAME_PORT} for incoming connections
- echo -n "Netcat: "
- ${NETCAT_CMD} -v -l -p ${GAME_PORT} 2>&1 | (grep -m1 -i "connect" && pkill -P $$ ${NETCAT_CMD}) || true
- echo "Netcat caught a connection. The server is coming up again..."
- IDLE_SERVER="false" ${myname} start
- fi
- done
-}
-
-# Start the server if it is not already running
-server_start() {
- # Start the game server
- if socket_has_session "${SESSION_NAME}"; then
- echo "A tmux ${SESSION_NAME} session is already running. Please close it first."
- else
- echo -en "Starting server..."
- ${SUDO_CMD} rm -f "${GAME_COMMAND_DUMP}"
- # Use a plain file as command buffers for the server startup and switch to a FIFO pipe later
- ${SUDO_CMD} touch "${GAME_COMMAND_DUMP}"
- # Ensure pipe-pine is started before the server itself by splitting the session creation and server startup
- ${SUDO_CMD} tmux -L "${SESSION_NAME}" new-session -s "${SESSION_NAME}" -c "${SERVER_ROOT}" -d /bin/bash
- ${SUDO_CMD} tmux -L "${SESSION_NAME}" wait-for -L "command_lock"
- ${SUDO_CMD} tmux -L "${SESSION_NAME}" pipe-pane -t "${SESSION_NAME}":0.0 "cat > ${GAME_COMMAND_DUMP}"
- ${SUDO_CMD} tmux -L "${SESSION_NAME}" send-keys -t "${SESSION_NAME}":0.0 "exec ${SERVER_START_CMD}" Enter
- for ((i=1; i<=MAX_SERVER_START_TIME; i++)); do
- sleep "${sleep_time:-0.1}"
- if ! socket_session_is_alive "${SESSION_NAME}"; then
- echo -e "\e[39;1m failed\e[0m\n"
- >&2 ${SUDO_CMD} cat "${GAME_COMMAND_DUMP}"
- ${SUDO_CMD} rm -f "${GAME_COMMAND_DUMP}"
- # Session is dead but remain-on-exit left it open; close it for sure
- ${SUDO_CMD} tmux -L "${SESSION_NAME}" kill-session -t "${SESSION_NAME}"
- exit 1
- elif grep -q -i "${SERVER_START_SUCCESS}" "${GAME_COMMAND_DUMP}"; then
- echo -e "\e[39;1m done\e[0m"
- break
- elif [[ $i -eq ${MAX_SERVER_START_TIME} ]]; then
- echo -e "\e[39;1m skipping\e[0m"
- >&2 echo -e "Server startup has not finished yet; continuing anyways"
- fi
- done
- ${SUDO_CMD} tmux -L "${SESSION_NAME}" pipe-pane -t "${SESSION_NAME}":0.0
- # Let the command buffer be a FIFO pipe
- ${SUDO_CMD} rm -f "${GAME_COMMAND_DUMP}"
- ${SUDO_CMD} mkfifo "${GAME_COMMAND_DUMP}"
- ${SUDO_CMD} tmux -L "${SESSION_NAME}" wait-for -U "command_lock"
-
- # Mimic GNU screen and allow for both C-a and C-b as prefix
- ${SUDO_CMD} tmux -L "${SESSION_NAME}" set -g prefix2 C-a
- fi
-
- if [[ "${IDLE_SERVER,,}" == "true" ]]; then
- # Check for the availability of the netcat (nc) binaries
- if [[ -z "${NETCAT_CMD}" ]]; then
- >&2 echo "The netcat binaries are needed for suspending an idle server."
- exit 12
- fi
-
- # Start the idle server daemon
- if socket_has_session "${IDLE_SESSION_NAME}"; then
- ${SUDO_CMD} tmux -L "${SESSION_NAME}" kill-session -t "${IDLE_SESSION_NAME}"
- # Restart as soon as the idle_server_daemon has shut down completely
- for i in {1..100}; do
- sleep 0.1
- if ! socket_has_session "${IDLE_SESSION_NAME}"; then
- ${SUDO_CMD} tmux -L "${SESSION_NAME}" new-session -s "${IDLE_SESSION_NAME}" -d "${myname} idle_server_daemon"
- break
- fi
- [[ $i -eq 100 ]] && echo -e "An \e[39;1merror\e[0m occurred while trying to reset the idle_server!"
- done
- else
- echo -en "Starting idle server daemon..."
- ${SUDO_CMD} tmux -L "${SESSION_NAME}" new-session -s "${IDLE_SESSION_NAME}" -d "${myname} idle_server_daemon"
- echo -e "\e[39;1m done\e[0m"
- fi
- fi
-}
-
-# Stop the server gracefully by saving everything prior and warning the users
-server_stop() {
- # Quit the idle daemon
- if [[ "${IDLE_SERVER,,}" == "true" ]]; then
- # Check for the availability of the netcat (nc) binaries
- if [[ -z "${NETCAT_CMD}" ]]; then
- >&2 echo "The netcat binaries are needed for suspending an idle server."
- exit 12
- fi
-
- if socket_has_session "${IDLE_SESSION_NAME}"; then
- echo -en "Stopping idle server daemon..."
- ${SUDO_CMD} tmux -L "${SESSION_NAME}" kill-session -t "${IDLE_SESSION_NAME}"
- echo -e "\e[39;1m done\e[0m"
- else
- echo "The corresponding tmux session for ${IDLE_SESSION_NAME} was already dead."
- fi
- fi
-
- # Gracefully exit the game server
- if socket_has_session "${SESSION_NAME}"; then
- # Game server is up and running, gracefully stop the server when there are still active players
-
- # Check for active player
- if is_player_online; then
- # No player was seen on the server through list
- echo -en "Server is going down..."
- game_command stop
- else
- # Player(s) were seen on the server through list (or an error occurred)
- # Warning the users through the server console
- game_command say "Server is going down in 10 seconds! HURRY UP WITH WHATEVER YOU ARE DOING!"
- game_command save-all
- echo -en "Server is going down in..."
- for i in {1..10}; do
- game_command say "down in... $(( 10 - i ))"
- echo -n " $(( 10 - i ))"
- sleep 1
- done
- game_command stop
- fi
-
- # Finish as soon as the server has shut down completely
- for i in {1..100}; do
- if ! socket_has_session "${SESSION_NAME}"; then
- ${SUDO_CMD} rm -f "${GAME_COMMAND_DUMP}"
- echo -e "\e[39;1m done\e[0m"
- break
- fi
- [[ $i -eq 100 ]] && echo -e "\e[39;1m timed out\e[0m"
- sleep 0.1
- done
- else
- echo "The corresponding tmux session for ${SESSION_NAME} was already dead."
- fi
-}
-
-# Print whether the server is running and if so give some information about memory usage and threads
-server_status() {
- # Print status information about the idle daemon
- if [[ "${IDLE_SERVER,,}" == "true" ]]; then
- # Check for the availability of the netcat (nc) binaries
- if [[ -z "${NETCAT_CMD}" ]]; then
- >&2 echo "The netcat binaries are needed for suspending an idle server."
- exit 12
- fi
-
- if socket_has_session "${IDLE_SESSION_NAME}"; then
- echo -e "Idle server daemon status:\e[39;1m running\e[0m"
- else
- echo -e "Idle server daemon status:\e[39;1m stopped\e[0m"
- fi
- fi
-
- # Print status information for the game server
- if socket_has_session "${SESSION_NAME}"; then
- echo -e "Status:\e[39;1m running\e[0m"
-
- # Calculating memory usage
- for p in $(${SUDO_CMD} pgrep -f "${MAIN_EXECUTABLE}"); do
- ps -p"${p}" -O rss | tail -n 1;
- done | gawk '{ count ++; sum += $2 }; END {count --; print "Number of processes =", count, "(tmux +", count, "x server)"; print "Total memory usage =", sum/1024, "MB" ;};'
- else
- echo -e "Status:\e[39;1m stopped\e[0m"
- fi
-}
-
-# Restart the complete server by shutting it down and starting it again
-server_restart() {
- if socket_has_session "${SESSION_NAME}"; then
- server_stop
- server_start
- else
- server_start
- fi
-}
-
-# Backup the directories specified in BACKUP_PATHS
-backup_files() {
- # Check for the availability of the tar binaries
- if ! command -v tar &> /dev/null; then
- >&2 echo "The tar binaries are needed for a backup."
- exit 11
- fi
-
- echo "Starting backup..."
- fname="$(date +%Y_%m_%d_%H.%M.%S).tar.gz"
- ${SUDO_CMD} mkdir -p "${BACKUP_DEST}"
- if socket_has_session "${SESSION_NAME}"; then
- game_command save-off
- game_command save-all
- sleep "${sleep_time:-0.3}"
- sync && wait
- ${SUDO_CMD} tar -C "${SERVER_ROOT}" -cf "${BACKUP_DEST}/${fname}" ${BACKUP_PATHS} --totals ${BACKUP_FLAGS} 2>&1 | grep -v "tar: Removing leading "
- game_command save-on
- else
- ${SUDO_CMD} tar -C "${SERVER_ROOT}" -cf "${BACKUP_DEST}/${fname}" ${BACKUP_PATHS} --totals ${BACKUP_FLAGS} 2>&1 | grep -v "tar: Removing leading "
- fi
- echo -e "\e[39;1mbackup completed\e[0m\n"
-
- echo -n "Only keeping the last ${KEEP_BACKUPS} backups and removing the other ones..."
- backup_count=$(for f in "${BACKUP_DEST}"/[0-9_.]*; do echo "${f}"; done | wc -l)
- if [[ $(( backup_count - KEEP_BACKUPS )) -gt 0 ]]; then
- for old_backup in $(for f in "${BACKUP_DEST}"/[0-9_.]*; do echo "${f}"; done | head -n"$(( backup_count - KEEP_BACKUPS ))"); do
- ${SUDO_CMD} rm "${old_backup}";
- done
- echo -e "\e[39;1m done\e[0m ($(( backup_count - KEEP_BACKUPS)) backup(s) pruned)"
- else
- echo -e "\e[39;1m done\e[0m (no backups pruned)"
- fi
-}
-
-# Restore backup
-backup_restore() {
- # Check for the availability of the tar binaries
- if ! command -v tar &> /dev/null; then
- >&2 echo "The tar binaries are needed for a backup."
- exit 11
- fi
-
- # Only allow the user to restore a backup if the server is down
- if socket_has_session "${SESSION_NAME}"; then
- >&2 echo -e "The \e[39;1mserver should be down\e[0m in order to restore the world data."
- exit 3
- fi
-
- # Either let the user choose a backup or expect one as an argument
- if [[ $# -lt 1 ]]; then
- echo "Please enter the corresponding number for the backup to be restored: "
- i=1
- for f in "${BACKUP_DEST}"/[0-9_.]*; do
- echo -e " \e[39;1m$i)\e[0m\t$f"
- i=$(( i + 1 ))
- done
- echo -en "Restore backup number: "
-
- # Read in user input
- read -r user_choice
-
- # Interpeting the input
- if [[ $user_choice =~ ^-?[0-9]+$ ]]; then
- n=1
- for f in "${BACKUP_DEST}"/[0-9_.]*; do
- [[ ${n} -eq $user_choice ]] && fname="$f"
- n=$(( n + 1 ))
- done
- if [[ -z $fname ]]; then
- >&2 echo -e "\e[39;1mFailed\e[0m to interpret your input. Please enter the digit of the presented options."
- exit 5
- fi
- else
- >&2 echo -e "\e[39;1mFailed\e[0m to interpret your input. Please enter a valid digit for one of the presented options."
- exit 6
- fi
- elif [[ $# -eq 1 ]]; then
- # Check for the existance of the specified file
- if [[ -f "$1" ]]; then
- fname="$1"
- else
- if [[ -f "${BACKUP_DEST}"/"$1" ]]; then
- fname="${BACKUP_DEST}"/"$1"
- else
- >&2 echo -e "Sorry, but '$1', is \e[39;1mnot a valid file\e[0m, neither in your current directory nor in the backup folder."
- exit 4
- fi
- fi
- elif [[ $# -gt 1 ]]; then
- >&2 echo -e "\e[39;1mToo many arguments.\e[0m Please pass only the filename for the world data as an argument."
- >&2 echo "Or alternatively, no arguments at all to choose from a list of available backups."
- exit 7
- fi
-
- echo "Restoring backup..."
- if ${SUDO_CMD} tar -xf "${fname}" -C "${SERVER_ROOT}" 2>&1; then
- echo -e "\e[39;1mRestoration completed\e[0m"
- else
- echo -e "\e[39;1mFailed to restore backup.\e[0m"
- fi
-}
-
-# Run the given command at the game server console
-server_command() {
- if [[ $# -lt 1 ]]; then
- >&2 echo "No server command specified. Try 'help' for a list of commands."
- exit 1
- fi
-
- if socket_has_session "${SESSION_NAME}"; then
- return_stdout=true game_command "$@"
- else
- echo "There is no ${SESSION_NAME} session to connect to."
- fi
-}
-
-# Enter the tmux game session
-server_console() {
- if socket_has_session "${SESSION_NAME}"; then
- ${SUDO_CMD} tmux -L "${SESSION_NAME}" attach -t "${SESSION_NAME}":0.0
- else
- echo "There is no ${SESSION_NAME} session to connect to."
- fi
-}
-
-# Check if there is a session available
-socket_has_session() {
- if [[ "$(whoami)" != "${GAME_USER}" ]]; then
- ${SUDO_CMD} tmux -L "${SESSION_NAME}" has-session -t "${1}":0.0 2> /dev/null
- return $?
- fi
- tmux -L "${SESSION_NAME}" has-session -t "${1}":0.0 2> /dev/null
- return $?
-}
-
-socket_session_is_alive() {
- if socket_has_session "${1}"; then
- if [[ "$(whoami)" != "${GAME_USER}" ]]; then
- return $(${SUDO_CMD} tmux -L "${SESSION_NAME}" list-panes -t "${1}":0.0 -F '#{pane_dead}' 2> /dev/null)
- fi
- return $(tmux -L "${SESSION_NAME}" list-panes -t "${1}":0.0 -F '#{pane_dead}' 2> /dev/null)
- else
- return 1
- fi
-}
-
-# Help function, no arguments required
-help() {
- cat <<-EOF
- This script was designed to easily control any ${game} server. Almost any parameter for a given
- ${game} server derivative can be changed by editing the variables in the configuration file.
-
- Usage: ${myname} {start|stop|restart|status|backup|restore|command <command>|console}
- start Start the ${game} server
- stop Stop the ${game} server
- restart Restart the ${game} server
- status Print some status information
- backup Backup the world data
- restore [filename] Restore the world data from a backup
- command <command> Run the given command at the ${game} server console
- console Enter the server console through a tmux session
-
- Copyright (c) Gordian Edenhofer <gordian.edenhofer@gmail.com>
- EOF
-}
-
-case "${1:-}" in
- start)
- server_start
- ;;
-
- stop)
- server_stop
- ;;
-
- status)
- server_status
- ;;
-
- restart)
- server_restart
- ;;
-
- console)
- server_console
- ;;
-
- command)
- server_command "${@:2}"
- ;;
-
- backup)
- backup_files
- ;;
-
- restore)
- backup_restore "${@:2}"
- ;;
-
- idle_server_daemon)
- # This shall be a hidden function which should only be invoked internally
- idle_server_daemon
- ;;
-
- -h|--help)
- help
- exit 0
- ;;
-
- *)
- help
- exit 1
- ;;
-esac
-
-exit 0
diff --git a/spigot.sysusers b/spigot.sysusers
deleted file mode 100644
index a59d11834384..000000000000
--- a/spigot.sysusers
+++ /dev/null
@@ -1 +0,0 @@
-u craftbukkit - "Spigot Server" /srv/craftbukkit /bin/bash
diff --git a/spigot.tmpfiles b/spigot.tmpfiles
deleted file mode 100644
index 3534d45818c4..000000000000
--- a/spigot.tmpfiles
+++ /dev/null
@@ -1,5 +0,0 @@
-z /srv/craftbukkit 2775 craftbukkit craftbukkit - -
-d /srv/craftbukkit/logs 2755 craftbukkit craftbukkit -
-z /srv/craftbukkit/logs - craftbukkit craftbukkit - -
-d /srv/craftbukkit/plugins 2755 craftbukkit craftbukkit -
-z /srv/craftbukkit/plugins - craftbukkit craftbukkit - -