Running script on EC2

I created a custom AMA (Fedora) Amazon that runs several scripts and then shuts down.

The problem with AMI is that if my code changes, there must be a way for the AMI instance to get the latest scripts before it executes them.

I wrote a shell script and put it in /etc/init.d/nt_startup

To update the code, I run git pull shell script in my code repository and then execute the script.

The problem is that git pull does not start when the instance loads, but the python script works just fine. Not sure what I am missing ... here's the script run:

 #!/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 shell /usr/scripts/code/git_latest script looks like this:

 #pulls in the latest code from the repository cd /usr/scripts/code sudo git pull 

It should flush the last process.py script.

It is strange that if I ssh in my instance and start the script launch manually ( /etc/init.d/nt_startup "start" ), the git script works just fine.

Did I miss something?

+6
git shell amazon-ec2 fedora
source share
2 answers

OK, I finally figured it out. After clearing the EC2 output, I found this line:

"Running ntstartup: sudo: sorry, you must have tty to run sudo"

Fedora seems to block tty sudo commands.

A quick search led to a solution:

  • How to root run "visudo".
  • Find the line with "Default requiretty" and comment on it (#Default requiretty)

I hope that this will be useful for everyone who is faced with this problem.

+3
source share

You should put the start link in /etc/rc?.d. You can use chkconfig (8) or ntsysv (8) to help you manage these directories.

0
source share

All Articles