Modded Java

cylinder chest
FORGE SERVER
​
Running a modded server is gonna require some decent horsepower. It varies a lot depending on modpack and server population, but in general a full modpack is gonna need a lot of RAM and a good CPU - especially on worldgen.
​
My server uses an Intel 8600k and 16GB RAM - I don't have any issues with 3-5 people on any modpacks.
​
Let's get started.
​
A lot of modpacks these days come with server files premade. You can set them up easily. Go on Twitch and download it. Scroll down a little bit if you don't have a server pack available.
​

Inside you'll find the Forge installer, forge-1.12.2-14.23.5.2838-installer.jar, or whichever version is appropriate for your modpack,we need to run this and let the Forge files install.
​
Rename the server folder to something quick and easy to type then copy the folder to your Minecraft server instance folder /opt/minecraft. Either cd to the Downloads folder,or use Tools>Open Current Folder in Terminal) - wherever you extracted the modpack server folder
​
cd ~/Downloads
​
sudo cp -r skyfactory /opt/minecraft

To run it we open a terminal at this folder (Tools>Open Current Folder in Terminal) or cd into it and issue this command:
​
sudo java -jar forge-installer.jar --installServer
​
Where forge-installer.jar is the name of the installer (in the screenshot it's forge-1.12.2-14.23.5.2838-installer.jar)
​
It'll open the installer. Select "Install server" and point it to /opt/minecraft/modpack
​
Where /modpack is the name of your modpack.


If your modpack DOESN'T come with a server file pack, it's really easy to create one. Download the appropriate version of Forge installer from the official website and follow the above guide.
Open CurseForge, go to the modpack, hit the cog in the upper right corner and open the folder (edit - right click on the modpack and you'll see this option). Just copy the contents of the modpack folder from your computer to your server folder /opt/minecraft/modpack and install Forge inside, same as above.


Creating a service with systemd
​
Ubuntu uses a system called systemd and screen to manage services. We can use it to manage multiple Minecraft servers easily.
​
​
Open LeafPad (Start>Accessories>LeafPad) and paste this in (between the underscores):
​
_______________
​
[Unit]
Description=ForgeMC %i
After=network.target
​
[Service]
WorkingDirectory=/opt/minecraft/%i
User=minecraft
Group=minecraft
Restart=always
KillMode=none
​
ExecStart=/usr/bin/screen -DmS forge-%i /usr/bin/java -Xmx10G -Xms10G -XX:+UseG1GC -XX:+ParallelRefProcEnabled -XX:MaxGCPauseMillis=200 -XX:+UnlockExperimentalVMOptions -XX:+DisableExplicitGC -XX:+AlwaysPreTouch -XX:G1NewSizePercent=30 -XX:G1MaxNewSizePercent=40 -XX:G1HeapRegionSize=8M -XX:G1ReservePercent=20 -XX:G1HeapWastePercent=5 -XX:G1MixedGCCountTarget=4 -XX:InitiatingHeapOccupancyPercent=15 -XX:G1MixedGCLiveThresholdPercent=90 -XX:G1RSetUpdatingPauseTimePercent=5 -XX:SurvivorRatio=32 -XX:+PerfDisableSharedMem -XX:MaxTenuringThreshold=1 -jar forge.jar nogui
​
[Install]
WantedBy=multi-user.target
_______________
​
​
This is our service named "Forge Server: (name of modpack folder)". It's operating out of /opt/minecraft/modpack with the user/group "minecraft". Screen (to monitor the server from terminal) will be named "mc-(name of modpack folder)". Restarts when closed, unless stopped by systemd itself.
​
Change forge.jar as needed.
​
If you've followed this guide to the letter you can leave it all the same.

Save this as minecraft@.service somewhere (~/Documents is alright)
​
All we need to do to use this as a service is copy to /etc/systemd/system and allow it to be executed. Navigate to wherever you saved minecraft@.service and issue these:
sudo chmod u+x minecraft@.service
sudo cp minecraft@.service /etc/systemd/system
​
​
We've just created a service we can use for multiple modpacks. It works out of whatever folder you specify (minecraft@modpack)
​
Before we can run it, we need to rename the Forge server application to just forge.jar. We have to in order to use just 1 service script.
​
Navigate (cd) to /opt/minecraft/modpack and open a terminal session.
​
sudo mv sudo mv forge-1.12-14.21.1.2443-universal.jar forge.jar
​
​
This renames the file forge-1.12-14.21.1.2443-universal.jar to just forge.jar.
​
​

JVM Arguments and server.properties
​
Java needs to be told how to run to get the best performance, it makes a lot of garbage. Inside your paper.service you'll find this line:
​
... -Xmx2G -Xms2G -XX:+UseG1GC -Dsun.rmi.dgc.server.gcInterval=2147483646 -XX:+UnlockExperimentalVMOptions -XX:G1NewSizePercent=20 -XX:G1ReservePercent=20 -XX:MaxGCPauseMillis=50 -XX:G1HeapRegionSize=32M -XX:ParallelGCThreads=2 -jar forge.jar nogui
​
​
The "base" command looks like this (if you ran it from the terminal, or edited it in the Minecraft launcher):
​
java -Xmx1G -Xms1G -jar paper.jar nogui
​
​
These are called JVM (Java virtual machine) arguments. We can edit a few things to optimize the server based on your hardware. The rest are ones I've found to work well, and that were recommended by people on Reddit.
​
You can change the amount of RAM with this:
-Xmx2G -Xms2G
​
Number of threads (for garbage collecting - set it to the number of cores your CPU has):
-XX:ParallelGCThreads=2
​
You can find more info on JVM arguments here
Your server.properties can affect performance as well. You'll need to edit it with nano, as you did the eula.txt. cd or open Tools>Open Terminal over to the server folder /opt/minecraft/modpack and use this:
​
cd /opt/minecraft/modpack
​
sudo nano server.properties
​
See more on the server.properties here
​
Read up on your mods, some may need changes in this. Biomes O' Plenty is a good example.
​
​

Run the server!!!
​
Start and stop the service minecraft@.service with systemd. The syntax will be minecraft@(your modpack's folder name)
​
To enable it on boot, run the "enable" command for your modpack:
​
sudo systemctl start minecraft@sevtech
sudo systemctl stop minecraft@rlcraft
sudo systemctl status minecraft@allthemods3
sudo systemctl enable minecraft@skyfactory4
sudo systemctl disable minecraft@projectozone
​
View the output of the server with Screen:
​
sudo -u minecraft screen -R mc-sevtech
sudo -u minecraft screen -R mc-skyfactory4
​
As long as your port forwarding is correct, you can connect and play! It'll take a moment to start the server, based on your computer's performance and mods/plugins.
​


NOTE: If you plan on making your server open to the public, you'll need to take necessary precautions before opening up and giving out a path to your home network. Several STRONG recommendations include: SSH hardening, general OS hardening, logging, automatic OS updates, firewalls, intrusion detection/prevention.
​
All of the security-related guides linked are guidelines - a strong mindset of security is required to host public servers. Take it seriously so your home network isn't compromised.