1

I am trying to run a command on the startup of the server. I tried to add the command to the User Data section:

#!/bin/bash
cd /home/ec2-user 
java -Xms1G -Xmx1G -XX:+UseConcMarkSweepGC -jar spigot-1.14.4.jar 

However that still didn't work, so I then in addition to the userdata, I added that same command to the rc.local file in /etc/:

touch /var/lock/subsys/local
cd /home/ec2-user
java -Xms1G -Xmx1G -XX:+UseConcMarkSweepGC -jar spigot-1.14.4.jar

However, that too doesn't work. Is there anything I am missing.

Also, the command I am running is meant to stay running until the server ends.

1

UserData is only executed the first time the instance boots after it's created. Not upon subsequent reboots or shutdowns/starts.

Best to create a systemd unit file for your app and enable it. It can do some smarts like restarting the app if it fails, etc.

Have a look here for example: Creating and modifying systemd unit files

Hope that helps :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.