mirror of
https://github.com/timvisee/lazymc.git
synced 2025-05-19 04:40:22 -07:00
Add documentation for using bash script as server command
This commit is contained in:
parent
a7a182fbcb
commit
115d100aee
41
docs/command_bash.md
Normal file
41
docs/command_bash.md
Normal file
@ -0,0 +1,41 @@
|
||||
# Use bash script to start server
|
||||
|
||||
You may use a `bash` script to start your server, rather than invoking `java`
|
||||
directly. This requires some changes though, to ensure your server properly
|
||||
shuts down.
|
||||
|
||||
When `lazymc` wants to stop your server, it sends a [`SIGTERM`][sigterm] signal
|
||||
to the server command to gracefully shut it down. `bash` ignores this signal by
|
||||
default and keeps the server running.
|
||||
|
||||
You must configure `bash` to [forward][forward-signal] the signal to properly
|
||||
shutdown the Minecraft server as well.
|
||||
|
||||
[sigterm]: https://en.wikipedia.org/wiki/Signal_(IPC)#SIGTERM
|
||||
[forward-signal]: https://unix.stackexchange.com/a/434269/61092
|
||||
|
||||
## Example
|
||||
|
||||
Here's a minimal example, trapping the signal and forwarding it to the server.
|
||||
Be sure to set the correct server JAR file and appropriate memory limits.
|
||||
|
||||
[`start-server`](../res/start-server):
|
||||
|
||||
```bash
|
||||
#!/bin/bash
|
||||
|
||||
# Server JAR file, set this to your own
|
||||
FILE=server.jar
|
||||
|
||||
# Trap SIGTERM, forward it to server process ID
|
||||
trap 'kill -TERM $PID' TERM INT
|
||||
|
||||
# Start server
|
||||
java -Xms1G -Xmx1G -jar $FILE --nogui &
|
||||
|
||||
# Remember server process ID, wait for it to quit, then reset the trap
|
||||
PID=$!
|
||||
wait $PID
|
||||
trap - TERM INT
|
||||
wait $PID
|
||||
```
|
@ -12,6 +12,8 @@ address = "0.0.0.0:25565"
|
||||
directory = "."
|
||||
|
||||
# Command to start the server.
|
||||
#
|
||||
# Warning: if using a bash script, see: https://github.com/timvisee/lazymc/blob/master/docs/command_bash.md
|
||||
command = "java -Xmx1G -Xms1G -jar server.jar --nogui"
|
||||
|
||||
# Ingress address.
|
||||
@ -40,5 +42,5 @@ motd_starting = "§2☻ Server is starting...\n§7⌛ Please wait..."
|
||||
login_starting = "Server is starting... §c♥§r\n\nThis may take some time.\n\nPlease try to reconnect in a minute."
|
||||
|
||||
[advanced]
|
||||
# Automatically set internal IP and port in Minecraft server.properties file.
|
||||
# Automatically set IP and port in Minecraft server.properties file.
|
||||
rewrite_server_properties = true
|
||||
|
@ -1,19 +1,15 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Server file
|
||||
# Server JAR file, set this to your own
|
||||
FILE=server.jar
|
||||
|
||||
# Switch to script directory
|
||||
DIR="$(dirname "$(realpath "$0")")"
|
||||
cd $DIR
|
||||
|
||||
# Catch SIGTERM to gracefully stop server
|
||||
# Trap SIGTERM, forward it to server process ID
|
||||
trap 'kill -TERM $PID' TERM INT
|
||||
|
||||
# Start server
|
||||
java -Xms1G -Xmx1G -jar $FILE --nogui &
|
||||
|
||||
# Clean up stopped server
|
||||
# Remember server process ID, wait for it to quit, then reset the trap
|
||||
PID=$!
|
||||
wait $PID
|
||||
trap - TERM INT
|
||||
|
Loading…
x
Reference in New Issue
Block a user