I've created a custom Amazon AMI (Fedora) runs a few scripts and then shuts down.
The problem with AMI's is that if my code changes there has to be a way for the AMI instance to get the latest scripts before it executes them.
I wrote a shell script & put it in /etc/init.d/nt_startup
To keep the code up to date, I execute a git pull
shell script in my code repository and then execute the script.
The problem is, the git pull
doesn't seem to run when an instance boots up, but the python script runs just fine. Not sure what I'm missing... here's the startup script:
#!/bin/bash
#
# ec2 Startup script for EC2 machines
#
# chkconfig: 345 99 02
# description: Script used to issue startup and shutdown commands.
#
if [ "$1" = "start" ]; then
/usr/scripts/code/git_latest
python /usr/scripts/code/process.py
exit
fi
if [ "$1" = "stop" ]; then
#nothing
exit
fi
The /usr/scripts/code/git_latest
shell script looks like this:
#pulls in the latest code from the repository
cd /usr/scripts/code
sudo git pull
It should be pulling down the latest process.py
script.
The strange thing is that if I ssh into my instance and execute the startup script manually (/etc/init.d/nt_startup "start"
), the git script works just fine.
Am I missing something?
OK, I finally figured it out. After scouring the EC2 output I found this line:
"Starting ntstartup: sudo: sorry, you must have a tty to run sudo"
Apparently Fedora locks out non tty sudo commands.
A quick search led to the solution:
Hope this is helpful for anyone else who runs into this issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With