I run into the following issue when I try running a minecraft server on an ec2 instance:
java[7261]: No X11 DISPLAY variable was set, but this program performed an operation which requires it.
java[7261]: at java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:204)
java[7261]: at java.awt.Window.<init>(Window.java:536)
java[7261]: at java.awt.Frame.<init>(Frame.java:420)
java[7261]: at java.awt.Frame.<init>(Frame.java:385)
java[7261]: at javax.swing.SwingUtilities$SharedOwnerFrame.<init>(SwingUtilities.java:1763)
java[7261]: at javax.swing.SwingUtilities.getSharedOwnerFrame(SwingUtilities.java:1838)
java[7261]: at javax.swing.JOptionPane.getRootFrame(JOptionPane.java:1696)
java[7261]: at javax.swing.JOptionPane.showOptionDialog(JOptionPane.java:863)
java[7261]: at javax.swing.JOptionPane.showMessageDialog(JOptionPane.java:666)
java[7261]: at javax.swing.JOptionPane.showMessageDialog(JOptionPane.java:637)
java[7261]: at net.minecraftforge.installer.SimpleInstaller.launchGui(SimpleInstaller.java:177)
java[7261]: at net.minecraftforge.installer.SimpleInstaller.main(SimpleInstaller.java:147)
systemd[1]: minecraft.service: main process exited, code=exited, status=1/FAILURE
systemd[1]: Unit minecraft.service entered failed state.
systemd[1]: minecraft.service failed.
my user data script looks like this (run every time an instance is started):
#!/usr/bin/env bash
sudo yum -y install java-1.8.0
sudo mkdir /minecraft
sudo chown -R 777 /minecraft
cd /minecraft
aws s3 cp s3://minecraft-server-v3/setup/forge-1.12.2-14.23.5.2860-installer.jar /minecraft/forge-1.12.2-14.23.5.2860-installer.jar
export DISPLAY=:0.0
java -jar forge-1.12.2-14.23.5.2860-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-server-v3/setup/mods.zip /minecraft/mods.zip
unzip mods.zip
sudo aws s3 cp s3://minecraft-server-v3/setup/minecraft.service /etc/systemd/system/minecraft.service
sudo chmod 777 /etc/systemd/system/minecraft.service
sudo systemctl daemon-reload
sudo service minecraft start
and my minecraft.service
file looks like this:
[Unit]
Description=Minecraft Service
After=default.target
[Service]
Type=simple
User=ec2-user
WorkingDirectory=/minecraft
ExecStart=/usr/bin/java -Xmx8G -Xms8G -jar /minecraft/forge-1.12.2-14.23.5.2860-installer.jar nogui
Any idea what could be going on? Which operation requires a display? I'm very confused. Would appreciate any help.
From my understanding the issue is with your minecraft.service
file.
When you are starting the service you are running the installer for the forge server.
The installer requires X unless run with the --installServer
flag as you have done above in your user data script.
This is why you are experiencing the error.
I would imagine that you want to run the actual server .jar
For the version of the installer you are using I'm pretty sure that the name for the jar is:
minecraftforge-universal-1.12.2-14.23.5.2860.jar
Using this as an example you want to replace your current command with this:
/usr/bin/java -Xmx8G -Xms8G -jar minecraftforge-universal-1.12.2-14.23.5.2860.jar nogui