views:

1274

answers:

2

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?

A: 

You have to put a startup link in /etc/rc?.d. You can use chkconfig(8) or ntsysv(8) to help you administer these directories.

kmkaplan
The process.py script is being executed at start up... so I don't think that's the problem. It's just that the "git pull" is not being executed.
Mark
BTW, I did the above suggestions (# chkconfig: 345 99 02) and still no luck... I'll can think is that the git call is failing because the network hasn't been initialized or something?
Mark
+1  A: 

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:

  1. As root run "visudo."
  2. Find the line with "Default requiretty" and comment it out (#Default requiretty)

Hope this is helpful for anyone else who runs into this issue.

Mark
Why are you using sudo? Startup scripts run as root anyway.
tylerl