-1

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.

JLO64
  • 17
  • 5
  • Pretty sure this is a duplicate question to https://stackoverflow.com/questions/49594391/aws-ec2-run-script-program-at-startup – vi_ral Nov 19 '19 at 02:41

2 Answers2

1

By default, user data scripts and cloud-init directives run only during the first boot cycle when an instance is launched. But you can tweak this behavior to executer your user data as per your preferences as mentioned here

https://aws.amazon.com/premiumsupport/knowledge-center/execute-user-data-ec2/

Or the other way around is to create a linux service that runs at the machine restart as mentioned here:

https://www.digitalocean.com/community/tutorials/how-to-configure-a-linux-service-to-start-automatically-after-a-crash-or-reboot-part-1-practical-examples

Juned Ahsan
  • 67,789
  • 12
  • 98
  • 136
  • As it turns out it was a permissions error with the file I was trying to run. Thank your for your help though! – JLO64 Nov 19 '19 at 03:22
0

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
--//
JLO64
  • 17
  • 5