Search code examples
javalinuxamazon-web-servicesamazon-ec2amazon-linux-2

AWS EC2 Amazon Linux 2 How To Run Java on Boot


I've been looking all over the internet for a solution for this one and I just can't seem to get it right.

I have a command that I would like to start when my AWS EC2 server boots.

java -Xmx1740M -Xms1740M -jar /home/ec2-user/server.jar nogui

I've tried the "Change User Data" setting and bash scripts but to no avail.


Solution

  • Turns out I was misreading what to paste into the user data

    Content-Type: multipart/mixed; boundary="//"
    MIME-Version: 1.0
    
    --//
    Content-Type: text/x-shellscript; charset="us-ascii"
    MIME-Version: 1.0
    Content-Transfer-Encoding: 7bit
    Content-Disposition: attachment; filename="userdata.txt"
    
    #!/bin/bash
    cd /home/ec2-user/
    java -Xmx1900M -Xms1900M -jar server.jar nogui
    --//