DEV Community

Play Button Pause Button
Andrew Brown πŸ‡¨πŸ‡¦ for ExamPro

Posted on

How To Run A Modded Minecraft Server on AWS

At ExamPro if you can justify it with AWS you can do it. We run our own modded minecraft for the team to play in and thought we'd show you how you could do the same.

Talk Resources

Download Twitch Desktop App
https://www.twitch.tv/downloads

Download Minecraft Forge Server
https://files.minecraftforge.net

Top comments (18)

Collapse
 
hsimah profile image
hsimah • Edited

I'm getting a lot of permission denied errors with this one. If I ssh in and execute the /usr/bin/java -jar /minecraft/forge...jar myself my server runs fine. But when the system service is started it complains of permission issues:

[05:03:27] [main/WARN] [minecraft/ServerEula]: Failed to save eula.txt
 java.io.FileNotFoundException: eula.txt (Permission denied)

Any thoughts would be helpful!

Collapse
 
andrewbrown profile image
Andrew Brown πŸ‡¨πŸ‡¦

This is going to come down to permissions.

It's either the eula file is set root:root or you aren't running the server as sudo user.

Collapse
 
hsimah profile image
hsimah

So I added WorkDirectory=/minecraft and all my woes went away.

In summary:

  • no need for sudo in the ExecStart
  • ensure eula.txt is owned by ec2-user:ec2-user
  • add WorkingDirectory=/minecraft to minecraft.service

Seems to be working for me. Thanks for the prompt support Andrew - looking forward to playing Minecraft in the cloud.

Collapse
 
hsimah profile image
hsimah

Do you mean setting the ExecStart with /usr/bin/sudo prepended? I do get further if I run it that way. Just not sure if it is a good idea or not for security.

Thread Thread
 
andrewbrown profile image
Andrew Brown πŸ‡¨πŸ‡¦

Most servers need to run via sudo to access specific libraries so this is normal.
It could be the case thats where you need to place sudio.

If I didn't have it you don't need it.

You can also just attempt changing the ownership of the eula.txt file because maybe it was created as root user by mistake.

If you are using Amazon Linux then you just need to do chown: ec2-user:ec2-user eula.txt and this may resolve your issue.

Thread Thread
 
hsimah profile image
hsimah

I'm at work at the moment so I can't do more testing.

A few things I can note:

  • Running /usr/bin/java ... on its own (no sudo) works fine and I can play on my Minecraft server when it starts up, mods and all.
  • Having the same command execute via system service fails due to permissions.
  • Having the system service run via sudo works, but does not create/read the eula.txt

Permissions on the directory are ec2-user:ec2-user and that user can create, update and delete the eula.txt. I might go through the whole set up and make sure everything is configured correctly on the AWS side, but it seems odd that I can run the server myself, but when I try and set it as a service it fails. Having done Windows services for many years I do know it's usually some sort of permission that is the issue.

On another note - how do you persist your game world? My thought would be to create a cron job to store the world in my S3 periodically.

Thread Thread
 
andrewbrown profile image
Andrew Brown πŸ‡¨πŸ‡¦

Your EC2 instance has an EBS volume which is your virtual hard drive. You can take snapshots which are then stored on AWS managed S3. When you take additional snapshots it only backs up the difference in changes like a git repository.

They don't recommend to take EBS snapshots while the server is running but you certainly can and this is what I do and I've had no ill adverse effects (data loss or reduced server speed).

You could also sync just the files you want to s3 but this I think is less desirable now that I've done both methods.

You can automate EBS snapshots on schedule via CloudWatch events. CloudWatch events are basically serverless cron jobs, and much better than configuring your instance.

Collapse
 
andrewbrown profile image
Andrew Brown πŸ‡¨πŸ‡¦ • Edited

medium.com/exampro/2018-modded-min...

#!/usr/bin/env bash
sudo yum -y install java-1.8.0
sudo mkdir /minecraft
sudo chown -R ec2-user:ec2-user /minecraft
cd /minecraft
aws s3 cp s3://minecraft-server00/setup/forge-1.12.2-14.23.4.2756-installer.jar /minecraft/forge-1.12.2-14.23.4.2756-installer.jar
java -jar forge-1.12.2-14.23.4.2756-installer.jar --installServer
echo '#By changing the setting below to TRUE you are indicating your agreement to our EULA (https://account.mojang.com/documents/minecraft_eula).
#Mon Aug 06 18:11:14 UTC 2018
eula=true' > eula.txt
aws s3 cp s3://minecraft-server00/setup/mods.zip /minecraft/mods.zip
unzip mods.zip
sudo aws s3 cp s3://minecraft-server00/setup/minecraft.service /etc/systemd/system/minecraft.service
sudo systemctl daemon-reload
sudo service minecraft start
Collapse
 
daltjm profile image
DaltJM

Hi I've run into an issue. I can login via SSH and I can ping the EC2 but when I try and connect from the Twitch Minecraft launcher I get a "Failed to connect to the server" "io.netty.channel.AbstractChannel$AnnotatedConnectException:Connection refused: no further information:"

I don't think it even gets to the part where it installs or tries to run anything. Any help would be great.

Collapse
 
jmoore53 profile image
Jack Moore

Nice Post. This got me back into Minecraft. I'll have to check out the spot pricing from AWS, I've really just been using the On-demand pricing and it's starting to get expensive.

Collapse
 
hsimah profile image
hsimah

Hey! I came across the same issue. What I did:

  • ssh into your ec2
  • remove eula.txt
  • run minecraft server (not forge) using a command similar to this: java -Xmx1G -Xms1G -jar minecraft_server.1.12.2.jar nogui
  • this will close but will have generated you a new eula.txt
  • alter eula.txt to be true
  • start the forge server

Disclaimer - not sure how I am going to combine this command into the user data script, but at least it gets the server up and running. I'll try again tomorrow after work and see what I can find as to why this is necessary.

Collapse
 
andrewbrown profile image
Andrew Brown πŸ‡¨πŸ‡¦

I should really just shoot end-to-end videos on this stuff.

Thread Thread
 
hsimah profile image
hsimah

I thought it was a great video. I've mostly used Azure for cloud services so it was a great help navigating through the AWS stuff.

Collapse
 
aldoalvaradof profile image
AldoAlvaradof • Edited

I've been into games in Minecraft for a long time now, and I like that everyone can choose a server that interests them. You can run a modified Minecraft server on AWS or choose absolutely any other server to your liking. Maybe answers.microsoft.com/en-us/xbox/f... will be useful for you. Regardless of which one you choose, each of these servers will provide you with a brilliant experience. These are all good quality server options regardless of whether you are a newbie or already an experienced player. I wish you the best of luck in the game!

Collapse
 
est320 profile image
EST

sudo systemctl daemon-reload
sudo: systemctl: command not found

how to fix it?