0

I have followed ec2 run scripts every boot and tried the same approach for per-instance but my script still doesn't get executed.

I also followed Execute User Data After the Initial Launch of Your EC2 Instance and yet the script doesn't get executed. Content of the script:

nohup /home/ubuntu/anaconda3/envs/tensorflow_p36/bin/python3 -u medi_app.py &> nohup_medi &

Why is it proving so hard to run a script every time an instance restarts? Can someone please help out here?

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
Vikram Murthy
  • 293
  • 6
  • 17
  • Have you considered native OS features, such as an [@reboot cron task](https://www.cyberciti.biz/faq/linux-execute-cron-job-after-system-reboot/)? – jarmod Sep 22 '20 at 21:30

1 Answers1

3

If you are using an Amazon EC2 Linux instance to run a batch job on startup, simply install the script in this directory:

/var/lib/cloud/scripts/per-boot/

This will work on any system that has cloud-init installed, which also runs User Data scripts.

For more details, see: Auto-Stop EC2 instances when they finish a task - DEV Community

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470