2

I have a program written in c# and want it to start when my instance start.

I already added "mono /home/ec2-user/program/program.exe" to /etc/rc.local but it does nothing. What do I have to do?

2 Answers 2

2

Consider using cloud-init (if you are using Ubuntu), or a user-data start script. These will allow you to start an instance, configure it how you like (with necessary packages like mono), download your own code, and have it run as soon as the instance starts.

This is a preferred way to re-using instances or repackaging instances since all the steps needed to transform a 'stock' image to your own customized one is automated.

Sign up to request clarification or add additional context in comments.

2 Comments

what i've read... is that cloud-init and user-data start script is for ec2-run-instance... i'm using ec2-start-instance right now... is it possible for start instance?
Generally not. ec2-run-instance boots up a fresh instance. ec2-start-instance resumes an existing (but stopped) instance at whatever point the instance was at when it was stopped. While there's lots of ways of getting instances to do things when they first boot, there aren't so many ways to get instances to do things when they are started. Consider writing your code as a daemon that always runs, then it will be stopped and started with the instance as you expect.
0

@vsekhar is correct, as far as I am aware, regarding what happens when the instance is restarted. In that case, a daemon is about the best that can be done.

However, as all information in RAM is lost, it is often okay to just reboot. You can start the instance and reboot, allowing for normal processing of startup scripts. For rebooting, you can use ec2-reboot-instances.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.