AutoServer
概览
AutoServer 是一款专为 Velocity Proxy 设计的 Minecraft 插件。该插件会在玩家尝试连接时自动启动离线状态的后台服务器。对于希望节省资源、仅在需要时才开启闲置服务器的服务器网络来说,它是理想之选。
功能
- 当玩家尝试连接时,自动启动后台服务器。
- 当没有玩家在线时,自动停止本地服务器。
- 使用命令手动启动和停止后台服务器。
- 支持配置文件热重载。
- 可自定义消息内容。
快速入门
本节将介绍如何安装并配置 AutoServer 的最小化设置。
-
下载 AutoServer
前往 Versions 部分获取最新版本的 AutoServer。下载完成后,将 JAR 文件放入 Velocity 代理的 plugins 目录中。
-
首次启动
将 AutoServer 放入 plugins 目录后,我们需要重启 Velocity 以加载该插件。在首次启动时,AutoServer 会在 plugins 目录中生成一个名为 autoserver/config.toml 的配置文件。
-
配置您的服务器
首先,请查看您的 velocity.toml 文件,找到 [servers] 部分。配置 AutoServer 时,服务器的命名必须与此处完全一致。
使用文本编辑器打开 autoserver/config.toml,并搜索 [servers] 部分。此部分指定了 AutoServer 将管理的服务器。为您希望 AutoServer 管理的每台服务器创建一个表(table)。例如,如果您有一台名为 lobby 的服务器,则需要创建一个名为 [servers.lobby] 的表。
配置服务器时有两种选择:远程服务器或本地服务器。如果您有远程服务器,请参阅 Remote Backend 部分以获取更多详细信息。为了便于说明,本节我们将处理一台拥有启动脚本的本地服务器。以下示例中的本地服务器名为 lobby,这是使用脚本启动服务器的最小化设置:
[servers]
[servers.lobby]
# 服务器运行的目录路径。
workingDirectory = "/home/user/minecraft/servers/lobby"
# 启动 "lobby" 服务器的命令。
start = "bash start.sh"
# 或者如果您使用的是 Windows 批处理脚本
# start = "start.bat"
-
为每台服务器重复操作
现在,请为希望由 AutoServer 管理的每台服务器重复步骤 3。本文档的 Command examples 部分提供了大量示例命令,以帮助您构建适用于您情况的命令。
安装
- 从 Versions 下载最新版本的
autoserver-velocity-1.x.x.jar。
- 将
AutoServer-velocity-x.x.x.jar 文件放入您的 Velocity plugins 文件夹中。
- 重启 Velocity Proxy 以加载该插件。
配置
首次启动后,插件将在 plugins/autoserver 目录中生成一个 config.toml 文件。修改此文件以适应您的设置。
全局设置
| Key |
Type |
Description |
checkForUpdates |
boolean |
AutoServer 在启动时是否检查更新? |
messages |
table |
发送给玩家的提示信息。 |
servers |
table |
每台服务器的配置信息。 |
消息设置
| Key |
Type |
Description |
prefix |
string |
显示给玩家的所有消息的前缀。 |
starting |
string |
当玩家尝试连接到当前处于离线状态的服务器时,显示给玩家的消息。 |
failed |
string |
如果服务器启动失败或无法连接,显示给玩家的消息。 |
notify |
string |
当服务器准备就绪时显示给玩家的消息,提示他们即将被连接。 |
服务器
| 键 |
类型 |
描述 |
startupDelay |
int |
在尝试连接玩家之前,等待启动服务器的秒数。 |
shutdownDelay |
int |
在验证服务器是否已成功关闭之前,等待的秒数。 |
start |
string |
用于在本地启动服务器的命令。 |
stop |
string |
用于在本地停止服务器的命令。 |
workingDirectory |
string |
服务器运行所在的目录路径。 |
remote |
boolean |
指定服务器是否为远程服务器(true)或本地服务器(false)。 |
port |
int |
远程服务器监听启动命令的端口号。 |
preserveQuotes |
boolean |
(可选)控制是否保留首尾引号;在非 Windows 系统上默认移除引号,除非显式设置为 true。 |
security |
boolean |
指定远程服务器是否应在消息上使用安全性(默认值:true) |
autoShutdownDelay |
int |
自动关闭服务器前等待的持续时间(以秒为单位);设置为 0 可禁用此功能。 |
命令示例
以下是一些命令示例,帮助您构建 start 和 stop 命令。
运行 Java 命令
使用 java 运行服务器:
start = "java -Xmx4G -Xms4G -jar server.jar nogui"
默认情况下,这将在后台运行进程。如果需要附加到进程,请考虑在新终端会话中启动它。在 Linux 上,您可以使用 x-terminal-emulator:
start = "x-terminal-emulator -e java -Xmx4G -Xms4G -jar server.jar nogui"
使用 Bash 或 sh 脚本
使用 Bash 或 sh 运行脚本:
start = "bash start.sh"
stop = "bash stop.sh"
使用 screen
在分离的 screen 会话中运行服务器:
start = "screen -DmS mc-example java -Xmx4G -Xms4G -jar server.jar nogui"
stop = "screen -p 0 -S mc-example -X stuff \"stop\r\""
使用 tmux
在新的 tmux 会话中运行服务器:
start = "tmux new -d -s mc-example 'java -Xmx4G -Xms4G -jar server.jar nogui'"
stop = "tmux send-keys -t mc-example 'stop' C-m"
使用 systemd
如果您有服务器的 systemd 服务,可以这样控制它:
start = "systemctl start myserver"
stop = "systemctl stop myserver"
注意:您可能会遇到权限问题。
使用 Docker
使用 Docker 启动和停止服务器:
start = "docker start mc-example"
stop = "docker stop mc-example"
Windows
使用 batch 脚本
请注意,这是在后台运行的。
start = "start.bat"
使用 start(Windows 命令提示符)
在新的命令提示符窗口中启动服务器:
start = "cmd /c start \"ExampleTitle\" cmd /c java -Xmx4G -Xms4G -jar server.jar nogui"
使用 PowerShell
在新的 PowerShell 窗口中启动服务器:
start = "powershell -Command Start-Process -FilePath 'java' -ArgumentList '-Xmx4G -Xms4G -jar server.jar nogui'"
在隐藏的 PowerShell 窗口中启动服务器:
start = "powershell -WindowStyle Hidden -Command Start-Process -NoNewWindow -FilePath 'java' -ArgumentList '-Xmx4G -Xms4G -jar server.jar nogui'"
使用 wt
在与新选项卡相同的 PowerShell 窗口中启动服务器,执行如下命令:
start = "wt -w 0 new-tab -d \"C:/path/to/directory\" \"C:/path/to/script/start.bat\""
workingDirectory 设置对此命令无效,因此工作目录是在命令中传递的。
使用任务计划程序
如果您有用于启动服务器的计划任务:
start = "schtasks /run /tn \"MinecraftExampleTask\""
stop = "schtasks /end /tn \"MinecraftExampleTask\""
如果要使用 stop 命令,请勿为此任务使用 batch 脚本。它将无法工作,因为它只会结束 batch 脚本而不会结束 java 进程。
workingDirectory 设置对此命令无效。要设置工作目录,请进入任务计划程序 GUI 并编辑任务。有一个名为 Start in 的工作目录文本框。
命令与权限
| 命令 |
描述 |
权限 |
| (无命令,基础权限) |
访问任何命令所需的基础权限 |
autoserver.base |
/autoserver reload |
重新加载插件配置。 |
autoserver.command.reload |
/autoserver help |
显示包含可用命令的帮助菜单 |
autoserver.command.help |
/autoserver status [<server>] |
检查指定服务器的状态;若未指定服务器,则检查所有服务器的状态 |
autoserver.command.status |
/autoserver start <server> |
运行服务器的启动流程 |
autoserver.command.start |
/autoserver stop <server> |
运行服务器的停止流程 |
autoserver.command.stop |
/autoserver info <server> |
显示指定服务器的详细信息 |
autoserver.command.info |
/autoserver version |
插件版本 |
autoserver.command.version |
远程后端
注意:随着开发的继续,远程服务器支持的功能可能会发生变化,请注意这一点。
远程后端支持适用于 PaperMC 和 FabricMC 服务器。仅当需要远程服务器启动功能时,才需要远程后端。
- 从版本页面下载:
- 将其放入
mods 或 plugins 文件夹中。
- 重启你的服务器以生成配置文件。
首次启动后,插件将在 JAR 文件所在的同一目录(即 mods 或 plugins)下生成一个 AutoServer/config.yml 文件。
在远程后端上有一些你需要配置的设置。首先,你需要设置 server.workingDirectory 和 server.startCommand,以便在远程机器上启动服务器。startCommand 设置遵循与 Velocity 插件中 start 相同的规则,请查看 命令示例 部分获取示例。
除非你有其他端口可用于后端监听器,否则无需更改 bootListener 部分。
后端服务器支持与 Velocity 插件之间的消息 HMAC 安全机制。要启用此功能,你必须从 Velocity 机器上的 forwarding.secret 文件中复制密钥。然后,将 security.enabled 设置为 true,并在 AutoServer 的 Velocity 配置中将该服务器的 security 设置为 true。
以下是一个名为 survival 的远程服务器的配置表示例。这应放在 Velocity 的 autoserver/config.toml 中:
[servers.survival]
# 指定这是一个远程服务器
remote = true
# 远程服务器监听启动命令的端口(默认值:8080)。
port = 8080
# 在尝试连接玩家之前等待的时间(秒)。
# 对于远程服务器,可能需要更长的延迟时间。
startupDelay = 120
# 启用与此后端服务器连接的加密安全性。
# 如果未提供,默认为 true。
security = true
然后是 survival 服务器的匹配配置示例。这应放在远程机器上的 AutoServer/config.yml 中:
bootListener:
# 此命令用于在服务器关闭时启动引导监听器。
# 仅在需要时更改此项。
runJarCommand: "java -jar %jarName"
enabled: true
port: 8080
server:
workingDirectory: "/home/user/servers/minecraft-server/survival"
startCommand: "screen -DmS mc-example java -Xmx4G -Xms4G -jar server.jar nogui"
## 安全设置
security:
# 启用后端与 Velocity 插件之间消息传输的 HMAC 安全机制。
# 如果省略此设置,则默认为 "true"。
enabled: true
# 用于 HMAC 身份验证的共享密钥。
# 这必须与 Velocity 代理配置文件中的 "forwarding.secret" 相同。
# 为确保正确的身份验证,请直接从 Velocity 的配置文件中复制该值。
# 替换为来自 Velocity forwarding.secret 的确切值
secret: "xxxxxxxxxxxx"
PaperMC 后端
PaperMC AutoServer 插件支持通过后端服务器上可用的 /autoserver reload 命令热重载配置文件。
引导监听器 (Boot Listener)
引导监听器是等待并监听来自 Velocity 插件以启动服务器的指令的软件组件——因此得名“引导监听器”。它还包含一个命令行界面 (CLI),因此你可以运行诸如 reload 之类的命令来热重载配置文件,而无需重新启动引导监听器。
由于支持 CLI,你可能希望在一个允许与其交互的终端中运行引导监听器,而不是在后台运行它。为此,请参考 命令示例 部分来帮助构建实现此功能的命令,然后更新 bootListener.runJarCommand 为你想要的值。
例如,如果你想使用 screen,可以这样做:
bootListener:
runJarCommand: "screen -DmS boot-listener java -jar %jarName%"
故障排除
- 服务器未启动? 确保
config.toml 中的 start 命令正确且可执行。在新终端中运行该命令以测试其输出会有所帮助。
AutoServer
Overview
AutoServer is a Minecraft plugin designed for the Velocity Proxy. This plugin automatically starts offline backend servers when a player attempts to connect to them. It's perfect for server networks looking to save resources by keeping idle servers offline until needed.
Features
- Automatically starts backend servers when a player attempts to connect.
- Automatically stops local servers when no players are online.
- Manually start and stop backend servers using commands.
- Supports configuration hot reloading.
- Customizable messages.
Getting Started
This section will cover how to install and configure a minimal setup of AutoServer.
-
Downloading AutoServer
Head over to Versions section to get the latest version of AutoServer. After downloading AutoServer, place the JAR file into the plugins directory of your Velocity proxy.
-
Launching for the first time
Once you have placed AutoServer into the plugins directory, we need to restart Velocity to load the plugin. On the first launch AutoServer will generate a configuration file autoserver/config.toml located in the plugins directory.
-
Configuring your servers
Start by taking note of your velocity.toml file looking for the [servers] section. How the servers are named needs to match exactly when configuring AutoServer.
Open the autoserver/config.toml in a text editor and search for the [servers] section. This section specifies the servers that AutoServer will manage. Create a table for each server you want AutoServer to manage. For example if you have a server named lobby you will create a table called [servers.lobby].
Two routes you can head with configuring a server either a remote server or a local server. If you have a remote server you need to configure check out the Remote Backend section for more details. For the sake of this section we will handle a local server that we have a script for. This example local server is called lobby here is a minimal settings to start the server using a script:
[servers]
[servers.lobby]
# Path to the directory where the server runs.
workingDirectory = "/home/user/minecraft/servers/lobby"
# Command to start the "lobby" server.
start = "bash start.sh"
# Or if you have a Windows Batch Script
# start = "start.bat"
-
Repeat for each server
Now repeat step 3 for each server you want to be managed by AutoServer. There is a lot of example commands in the Command examples section of this document. To help you build a command that works for your situation.
Installation
- Download the latest version of
autoserver-velocity-1.x.x.jar from Versions.
- Place the
AutoServer-velocity-x.x.x.jar file into your Velocity plugins folder.
- Restart your Velocity Proxy to load the plugin.
Configuration
After the first launch, the plugin will generate a config.toml file in the plugins/autoserver directory. Modify this file to suit your setup.
Global
| Key |
Type |
Description |
checkForUpdates |
boolean |
Should AutoServer check for updates on boot? |
messages |
table |
Messages that will get sent to players. |
servers |
table |
The configuration for each server. |
Messages
| Key |
Type |
Description |
prefix |
string |
Prefix added to all messages displayed to the player. |
starting |
string |
Message displayed to the player when they attempt to connect to a server that is currently offline. |
failed |
string |
Message displayed to the player if the server fails to start or cannot be connected to. |
notify |
string |
Message displayed to the player when the server is ready, indicating that they will be connected shortly. |
Servers
| Key |
Type |
Description |
startupDelay |
int |
Time in seconds to wait before attempting to connect a player after starting the server. |
shutdownDelay |
int |
Time in seconds to wait before verifying whether the server has successfully shut down. |
start |
string |
Command used to start the server locally. |
stop |
string |
Command used to stop the server locally. |
workingDirectory |
string |
Path to the directory where the server runs. |
remote |
boolean |
Specifies whether the server is remote (true) or local (false). |
port |
int |
Port number on which the remote server listens for the start command. |
preserveQuotes |
boolean |
(Optional) Controls whether leading and trailing quotes are preserved, with quotes being removed by default on non-Windows systems unless explicitly set to true. |
security |
boolean |
Specifies whether the remote server should use security on message (default: true) |
autoShutdownDelay |
int |
Duration (in seconds) to wait before automatically shutting down the server; set to 0 to disable this feature. |
Command examples
Here are some command examples to help construct your start and stop commands.
Running Java command
To run the server using java:
start = "java -Xmx4G -Xms4G -jar server.jar nogui"
By default, this will run the process in the background. If you need to attach to the process, consider launching it in a new terminal session. On Linux, you can use x-terminal-emulator:
start = "x-terminal-emulator -e java -Xmx4G -Xms4G -jar server.jar nogui"
Using a Bash or sh Script
To run a script using Bash or sh:
start = "bash start.sh"
stop = "bash stop.sh"
Using screen
To run the server in a detached screen session:
start = "screen -DmS mc-example java -Xmx4G -Xms4G -jar server.jar nogui"
stop = "screen -p 0 -S mc-example -X stuff \"stop\r\""
Using tmux
To run the server in a new tmux session:
start = "tmux new -d -s mc-example 'java -Xmx4G -Xms4G -jar server.jar nogui'"
stop = "tmux send-keys -t mc-example 'stop' C-m"
Using systemd
If you have systemd service for your server, you can control it like this:
start = "systemctl start myserver"
stop = "systemctl stop myserver"
Note: You might have privilege issues with this.
Using Docker
To start and stop a server using Docker:
start = "docker start mc-example"
stop = "docker stop mc-example"
Windows
Using batch script
Be aware this runs in the background.
start = "start.bat"
Using start (Windows Command Prompt)
To launch the server in a new Command Prompt window:
start = "cmd /c start \"ExampleTitle\" cmd /c java -Xmx4G -Xms4G -jar server.jar nogui"
Using PowerShell
To start the server in a new PowerShell window:
start = "powershell -Command Start-Process -FilePath 'java' -ArgumentList '-Xmx4G -Xms4G -jar server.jar nogui'"
To start the server in a hidden PowerShell window:
start = "powershell -WindowStyle Hidden -Command Start-Process -NoNewWindow -FilePath 'java' -ArgumentList '-Xmx4G -Xms4G -jar server.jar nogui'"
Using wt
To start the server in the same PowerShell window as a new tab do a command like this:
start = "wt -w 0 new-tab -d \"C:/path/to/directory\" \"C:/path/to/script/start.bat\""
The workingDirectory setting won't be effective for this command which is why working directory is passed in the command.
Using Task Scheduler
If you have a scheduled task to start your server:
start = "schtasks /run /tn \"MinecraftExampleTask\""
stop = "schtasks /end /tn \"MinecraftExampleTask\""
Do not use a batch script for this task if you want to use the stop command. It won't work because it will end the batch script but not the java process.
The workingDirectory setting won't be effective for this command. To set the working directory go into the Task Scheduler GUI and edit the task. There is a text box for the working directory called Start in.
Commands and Permissions
| Command |
Description |
Permission |
| (No command, base permission) |
Base permission required to access any command |
autoserver.base |
/autoserver reload |
Reloads the plugin configuration. |
autoserver.command.reload |
/autoserver help |
Displays the help menu with available commands |
autoserver.command.help |
/autoserver status [<server>] |
Checks the status of a specified server or all servers if none is specified |
autoserver.command.status |
/autoserver start <server> |
Run the start sequence for a server |
autoserver.command.start |
/autoserver stop <server> |
Run to stop sequence for a server |
autoserver.command.stop |
/autoserver info <server> |
Displays detailed information about a specified server |
autoserver.command.info |
/autoserver version |
Version of the plugin |
autoserver.command.version |
Remote Backend
NOTICE: the functionality of the remote server support is likely to change with continued development be aware of this.
Remote backend support is available for PaperMC and FabricMC servers. Remote backend is required only for remote server startup functionality.
- Download from the Versions page:
- Place into
mods or plugins folder.
- Restart your sever to generate the config file.
After the first launch, the plugin will generate a AutoServer/config.yml file in the same directory as the JAR file either mods or plugins.
There are a few settings available on the remote backend you will need to configure. First you'll want to set the server.workingDirectory and server.startCommand for starting your server on the remote machine. The startCommand setting follows the same rules as start for the Velocity plugin so check out Command examples for examples.
Don't need to change the bootListener section unless you have a different port available for the backend listener.
Backend servers support HMAC security for messages between the backend and the Velocity plugin. To enable this feature you must copy the key from the file forwarding.secret on your Velocity machine. Then set security.enabled to true and set security to true for that server in AutoServer's Velocity config.
Here is an example config table for a remote server that is named survival. This goes in Velocity autoserver/config.toml:
[servers.survival]
# Specify that is a remote server
remote = true
# Port the remote server listens for the start command (default: 8080).
port = 8080
# Time in seconds to wait before attempting to connect a player.
# For a remote server probably want a longer delay.
startupDelay = 120
# Enable security for the connection with this backend server.
# If not provided the default is true.
security = true
Then the matching example config for the survival server. This goes in AutoServer/config.yml on the remote machine:
bootListener:
# This command is used to launch boot listener when server is shutdown.
# Only change this if you need to.
runJarCommand: "java -jar %jarName"
enabled: true
port: 8080
server:
workingDirectory: "/home/user/servers/minecraft-server/survival"
startCommand: "screen -DmS mc-example java -Xmx4G -Xms4G -jar server.jar nogui"
## Security Settings
security:
# Enables HMAC security for message transmission between the backend and the Velocity plugin.
# If this setting is omitted, it defaults to "true".
enabled: true
# The shared secret key used for HMAC authentication.
# This must be the same as the "forwarding.secret" in your Velocity proxy's configuration file.
# To ensure proper authentication, copy the value directly from Velocity's config file.
# Replace this with the exact value from Velocity's forwarding.secret
secret: "xxxxxxxxxxxx"
PaperMC Backend
PaperMC AutoServer plugin supports hot reloading of the config file though the /autoserver reload command available on the backend server.
Boot Listener
The Boot Listener is the piece of software that will wait and listen for a command from the Velocity plugin to boot the server - hence the name "Boot Listener". It also includes a command-line interface(CLI) so you can run commands like reload to hot reload the config file without needing to restart the Boot Listener.
Because of the CLI support you might want to run the Boot Listener in a terminal that allows you to interact with it, rather than running it in the background. To do that reference the Command examples section to help build a command that will do this, then you will update the bootListener.runJarCommand to what you want.
For example if you want to use screen do something like this:
bootListener:
runJarCommand: "screen -DmS boot-listener java -jar %jarName%"
Troubleshooting
- Server not starting? Ensure the
start command in config.toml is correct and executable. It's helpful to run the command in a new terminal to test the commands output.
评论 0
登录后参与评分
还没有评论,来抢沙发吧