Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Startup script on EC2

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?

like image 439
Mark Avatar asked Feb 13 '09 18:02

Mark


1 Answers

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.

like image 51
Mark Avatar answered Sep 20 '22 05:09

Mark