lazymc/docs/command_bash.md

1.2 KiB

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 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 the signal to properly shutdown the Minecraft server as well.

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:

#!/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