Search code examples
linuxamazon-web-servicesamazon-ec2terminalminecraft

Amazon EC2 Minecraft Server - Cannot run mc commands, only runs bash commands


Normally, manually using SSH to connect to my EC2 server and then running this command will start the Minecraft server and allow me to enter in Minecraft commands

java -Xmx7G -Xms7G -jar vanilla-1.18.2.jar nogui

However, I have created a batch file on my computer to automate both launching the EC2 server (using AWSCLI) and the Minecraft server.

aws ec2 start-instances --instance-ids <INSTANCE ID>
ssh -i "Minecraft SMP.pem" ec2-user@DNS "cd MC/Server ; bash | java -Xmx7G -Xms7G -jar vanilla-1.18.2.jar nogui"

Line 1 launches the EC2 server using AWS's Command Line Interface. Line 2 connects to it from my pc, changes the directory to the MC server, and then runs it.

However, once the server is started, I can only enter in bash commands into the terminal-- not Minecraft commands.

Is there any way to "change the focus" onto the Minecraft server?

This is what happens when I run the batch file.

G:\Games\MC\My SMP>aws ec2 start-instances --instance-ids <INSTANCE ID>
{
    "StartingInstances": [
        {
            "CurrentState": {
                "Code": 16,
                "Name": "running"
            },
            "InstanceId": "<INSTANCE ID>",
            "PreviousState": {
                "Code": 16,
                "Name": "running"
            }
        }
    ]
}


G:\Games\MC\My SMP>ssh -i "Minecraft SMP.pem" ec2-user@DNS "cd MC/Server ; bash | java -Xmx7G -Xms7G -jar vanilla-1.18.2.jar nogui"
Starting net.minecraft.server.Main
[16:53:33] [ServerMain/INFO]: Environment: authHost='https://authserver.mojang.com', accountsHost='https://api.mojang.com', sessionHost='https://sessionserver.mojang.com', servicesHost='https://api.minecraftservices.com', name='PROD'
[16:53:36] [ServerMain/WARN]: Ambiguity between arguments [teleport, location] and [teleport, destination] with inputs: [0.1 -0.5 .9, 0 0 0]
[16:53:36] [ServerMain/WARN]: Ambiguity between arguments [teleport, location] and [teleport, targets] with inputs: [0.1 -0.5 .9, 0 0 0]
[16:53:36] [ServerMain/WARN]: Ambiguity between arguments [teleport, destination] and [teleport, targets] with inputs: [Player, 0123, @e, dd12be42-52a9-4a91-a8a1-11c01849e498]
[16:53:36] [ServerMain/WARN]: Ambiguity between arguments [teleport, targets] and [teleport, destination] with inputs: [Player, 0123, dd12be42-52a9-4a91-a8a1-11c01849e498]
[16:53:36] [ServerMain/WARN]: Ambiguity between arguments [teleport, targets, location] and [teleport, targets, destination] with inputs: [0.1 -0.5 .9, 0 0 0]
[16:53:37] [Worker-Main-2/INFO]: Loaded 7 recipes
[16:53:38] [Worker-Main-2/INFO]: Loaded 1141 advancements
[16:53:40] [Server thread/INFO]: Starting minecraft server version 1.18.2
[16:53:41] [Server thread/INFO]: Loading properties
[16:53:41] [Server thread/INFO]: Default game type: SURVIVAL
[16:53:41] [Server thread/INFO]: Generating keypair
[16:53:41] [Server thread/INFO]: Starting Minecraft server on 0.0.0.0:25565
[16:53:41] [Server thread/INFO]: Using epoll channel type
[16:53:41] [Server thread/INFO]: Preparing level "goldenSMP"
[16:53:47] [Server thread/INFO]: Preparing start region for dimension minecraft:overworld
[16:53:49] [Worker-Main-2/INFO]: Preparing spawn area: 0%
[16:53:49] [Worker-Main-2/INFO]: Preparing spawn area: 0%
[16:53:49] [Worker-Main-2/INFO]: Preparing spawn area: 0%
[16:53:49] [Worker-Main-2/INFO]: Preparing spawn area: 0%
[16:53:49] [Worker-Main-2/INFO]: Preparing spawn area: 0%
[16:53:50] [Worker-Main-2/INFO]: Preparing spawn area: 0%
[16:53:50] [Worker-Main-2/INFO]: Preparing spawn area: 0%
[16:53:51] [Worker-Main-2/INFO]: Preparing spawn area: 0%
[16:53:51] [Worker-Main-2/INFO]: Preparing spawn area: 0%
[16:53:52] [Worker-Main-2/INFO]: Preparing spawn area: 1%
[16:53:52] [Worker-Main-2/INFO]: Preparing spawn area: 4%
[16:53:53] [Worker-Main-2/INFO]: Preparing spawn area: 4%
[16:53:53] [Worker-Main-2/INFO]: Preparing spawn area: 7%
[16:53:54] [Worker-Main-2/INFO]: Preparing spawn area: 9%
[16:53:54] [Worker-Main-2/INFO]: Preparing spawn area: 13%
[16:53:55] [Worker-Main-2/INFO]: Preparing spawn area: 21%
[16:53:55] [Worker-Main-2/INFO]: Preparing spawn area: 31%
[16:53:56] [Worker-Main-2/INFO]: Preparing spawn area: 50%
[16:53:56] [Worker-Main-2/INFO]: Preparing spawn area: 62%
[16:53:57] [Worker-Main-2/INFO]: Preparing spawn area: 83%
[16:53:58] [Server thread/INFO]: Time elapsed: 10591 ms
[16:53:58] [Server thread/INFO]: Done (16.919s)! For help, type "help"
say hi
bash: line 1: say: command not found

(normally, typing in say hi in the linux console will print [Server] hi in the Minecraft chat like so:

(image of what SHOULD happen: server saying hi in the minecraft text chat)


Solution

  • From what I understand; You're logging into server as ec2-user which by default uses /bin/bash server. (I am assuming it is one of the following - Amazon Linux, RHEL, SUSE, Ubuntu as they offer the user-name ec2-user by default)

    So, you do not really need to run the command "bash |" after the semi-colon symbol.

    ssh -i "Minecraft SMP.pem" ec2-user@DNS "cd MC/Server ; java -Xmx7G -Xms7G -jar vanilla-1.18.2.jar nogui"
    

    I believe it should give you the Java based MineCraft chat server you're looking for.