2022-05-20 21:22:18 +02:00
|
|
|
---
|
2022-12-23 08:44:17 +01:00
|
|
|
title: "Minecraft Server"
|
2022-11-19 15:25:20 +01:00
|
|
|
visible: true
|
2022-05-20 21:22:18 +02:00
|
|
|
---
|
|
|
|
|
2022-06-06 18:37:33 +02:00
|
|
|
[toc]
|
2022-12-23 08:44:17 +01:00
|
|
|
|
|
|
|
Make sure to allow port `25565/tcp` to your server
|
2022-05-20 21:22:18 +02:00
|
|
|
|
|
|
|
## Vanilla
|
|
|
|
|
|
|
|
## PaperMC
|
|
|
|
|
|
|
|
## Forge Server
|
2022-12-23 08:44:17 +01:00
|
|
|
|
2022-05-20 21:22:18 +02:00
|
|
|
Download the forge installer from their website and install the server to a directory of your choosing.
|
2022-12-23 08:44:17 +01:00
|
|
|
Copy that folder to your server
|
2022-05-20 21:22:18 +02:00
|
|
|
|
|
|
|
On the server, create a directory for the server.
|
|
|
|
`# mkdir /etc/minecraft`
|
2022-12-23 08:44:17 +01:00
|
|
|
Put your folder here
|
2022-05-20 21:22:18 +02:00
|
|
|
|
|
|
|
Install java
|
2022-12-23 08:44:17 +01:00
|
|
|
`# apt install openjdk-17-jre`
|
2022-05-20 21:22:18 +02:00
|
|
|
|
2023-02-23 14:48:51 +01:00
|
|
|
Add a `minecraft` user.
|
|
|
|
|
|
|
|
```sh
|
|
|
|
useradd minecraft
|
|
|
|
chown minecraft:minecraft -R /etc/minecraft/
|
|
|
|
```
|
2022-05-20 21:22:18 +02:00
|
|
|
|
|
|
|
Start the server a first time.
|
2022-12-23 08:44:17 +01:00
|
|
|
`sudo -u minecraft /etc/minecraft/forge-(version)/run.sh`
|
2022-05-20 21:22:18 +02:00
|
|
|
|
2022-12-23 08:44:17 +01:00
|
|
|
Accept the EULA by editing `/etc/minecraft/forge-(version)/eula.txt`
|
2022-05-20 21:22:18 +02:00
|
|
|
|
|
|
|
## Fabric Server
|
|
|
|
|
|
|
|
## Systemd Service
|
|
|
|
|
2022-12-23 08:44:17 +01:00
|
|
|
> Adapted from [this gist](https://gist.github.com/dotStart/ea0455714a0942474635)
|
|
|
|
|
|
|
|
`/etc/systemd/system/minecraft.service`
|
|
|
|
|
2023-02-23 14:48:51 +01:00
|
|
|
```systemd
|
2022-05-20 21:22:18 +02:00
|
|
|
[Unit]
|
|
|
|
Description=Minecraft Server
|
|
|
|
After=network.target
|
|
|
|
|
|
|
|
[Service]
|
|
|
|
User=minecraft
|
|
|
|
WorkingDirectory=/etc/minecraft/server
|
|
|
|
# You can customize the maximum amount of memory as well as the JVM flags here
|
|
|
|
#ExecStart=/usr/bin/java -XX:+UseG1GC -Xmx3G -jar server.jar --nojline --noconsole
|
|
|
|
ExecStart=/usr/bin/java @user_jvm_args.txt @libraries/net/minecraftforge/forge/1.18.1-39.0.5/unix_args.txt nogui "$@"
|
|
|
|
|
|
|
|
# Restart the server when it is stopped or crashed after 30 seconds
|
|
|
|
# Comment out RestartSec if you want to restart immediately
|
|
|
|
Restart=always
|
|
|
|
RestartSec=30
|
|
|
|
|
|
|
|
# Alternative: Restart the server only when it stops regularly
|
|
|
|
# Restart=on-success
|
|
|
|
|
|
|
|
# Do not remove this!
|
|
|
|
StandardInput=null
|
|
|
|
|
|
|
|
[Install]
|
|
|
|
WantedBy=multi-user.target
|
|
|
|
```
|
|
|
|
|
|
|
|
## Systemd Service with STDIN available
|
|
|
|
|
2022-12-23 08:44:17 +01:00
|
|
|
> Based on [this stackexchange answer](https://unix.stackexchange.com/questions/598221/how-to-control-systemd-service-using-screen/612118#612118)
|
|
|
|
|
|
|
|
`/etc/systemd/system/minecraft.socket`
|
|
|
|
|
2023-02-23 14:48:51 +01:00
|
|
|
```systemd
|
2022-05-20 21:22:18 +02:00
|
|
|
[Unit]
|
|
|
|
PartOf=minecraft.service
|
|
|
|
|
|
|
|
[Socket]
|
|
|
|
ListenFIFO=%t/minecraft.stdin
|
|
|
|
```
|
|
|
|
|
2022-12-23 08:44:17 +01:00
|
|
|
`/etc/systemd/system/minecraft.service`
|
|
|
|
|
2023-02-23 14:48:51 +01:00
|
|
|
```systemd
|
2022-05-20 21:22:18 +02:00
|
|
|
[Unit]
|
|
|
|
Description=Minecraft Server
|
|
|
|
After=network.target
|
|
|
|
|
|
|
|
[Service]
|
|
|
|
Type=simple
|
|
|
|
User=minecraft
|
|
|
|
WorkingDirectory=/etc/minecraft/server
|
|
|
|
# fabric
|
|
|
|
ExecStart=/usr/bin/java -XX:+UseG1GC -Xmx4G -jar /etc/minecraft/server/fabric-server-launch.jar
|
|
|
|
# forge
|
|
|
|
#ExecStart=/usr/bin/java @user_jvm_args.txt @libraries/net/minecraftforge/forge/1.18.1-39.0.5/unix_args.txt nogui "$@"
|
|
|
|
Restart=on-failure
|
|
|
|
# Socket used for STDIN
|
|
|
|
Sockets=minecraft.socket
|
|
|
|
StandardInput=socket
|
|
|
|
StandardOutput=journal
|
|
|
|
StandardError=journal
|
|
|
|
|
|
|
|
[Install]
|
|
|
|
WantedBy=multi-user.target
|
|
|
|
```
|
|
|
|
|
2022-12-23 08:44:03 +01:00
|
|
|
To run commands, redirect commands into your socket.
|
|
|
|
`echo "command" > /run/minecraft.stdin`
|
2022-05-20 21:22:18 +02:00
|
|
|
|
|
|
|
### Pipe commands script
|
2022-12-23 08:44:17 +01:00
|
|
|
|
|
|
|
**No safety at all!!**
|
|
|
|
|
2023-02-23 14:48:51 +01:00
|
|
|
```sh
|
2022-05-20 21:22:18 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
echo "$@" > /run/minecraft.stdin
|
2022-05-27 16:05:08 +02:00
|
|
|
```
|