Ec2 Run Scripts Every Boot
Solution 1:
So the current solution appears to be a method I wrote off in my initial question post as I may have not performed the setup exactly as outline in the link below...
This link --> How do I make cloud-init startup scripts run every time my EC2 instance boots?
The link shows how to modify the /etc/cloud/cloud.cfg file to update scripts-user to [scripts-user, always]
Also that link says to add your *.sh file to /var/lib/cloud/scripts/per-boot directory.
Once you reboot your system your script should have executed and you can verify this in: sudo cat /var/log/cloud-init.log
if your script still fails to execute try to erase the instance state of your server with the following command: sudo rm -rf /var/lib/cloud/instance/*
--NOTE:-- It appears print commands from a python script do not pipe (>>) as expected but echo commands pipe easily
Fails to pipesudo python test.py >> log.txt
Pipes successfullyecho "HI" >> log.txt
Solution 2:
Is this something along the lines that you want?
It copies the script to the instance, connects to the instance, and runs the script right away.
ec2 scp ~/path_to_script.py : instance_name -y && ec2 ssh instance_name -yc "python script_name.py" 1>/dev/null
Solution 3:
I read that the use of rc.local is getting deprecated. One thing to try is a line in /etc/crontab like this:
@reboot full-path-of-script
If there's a specific user you want to run the script as, you can list it after @reboot.
Post a Comment for "Ec2 Run Scripts Every Boot"