How To Run A Modded Minecraft Server on AWS

Andrew Brown 🇨🇦 on April 20, 2019

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 ... [Read Full]
markdown guide
 

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!

 

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.

 

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.

 

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.

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.

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.

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.

 

Alright, I did everthing exactly as you described, but after the minecraft.service file runs, nothing happens. I checked the status logs and it continues to say that I need to change the EULA to true. I even used nano to check if it had been changed to true and it is in fact set to true. What I think is happening is the server.jar is being ran in another folder somewhere on the instance where I can't find and creating a new eula.txt. Do you have some insight?

 

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.

 

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

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.

 

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.

 

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.

 

It would be helpful if you also shared the user_data.sh

 

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
 
code of conduct - report abuse