DEV Community

Discussion on: How To Run A Modded Minecraft Server on AWS

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.