简体   繁体   English

EC2上的启动脚本

[英]Startup script on EC2

I've created a custom Amazon AMI (Fedora) runs a few scripts and then shuts down. 我创建了一个自定义Amazon AMI(Fedora)运行一些脚本然后关闭。

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. AMI的问题在于,如果我的代码发生了变化,那么AMI实例必须有一种方法可以在执行它们之前获取最新的脚本。

I wrote a shell script & put it in /etc/init.d/nt_startup 我写了一个shell脚本并将其放在/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. 为了使代码保持最新,我在代码库中执行git pull shell脚本,然后执行脚本。

The problem is, the git pull doesn't seem to run when an instance boots up, but the python script runs just fine. 问题是,当实例启动时, git pull似乎没有运行,但是python脚本运行得很好。 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: /usr/scripts/code/git_latest shell脚本如下所示:

#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. 它应该是下拉最新的process.py脚本。

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. 奇怪的是,如果我ssh到我的实例并手动执行启动脚本( /etc/init.d/nt_startup "start"脚本就可以了。

Am I missing something? 我错过了什么吗?

OK, I finally figured it out. 好的,我终于明白了。 After scouring the EC2 output I found this line: 在搜索EC2输出后,我找到了这一行:

"Starting ntstartup: sudo: sorry, you must have a tty to run sudo" “从ntstartup开始:sudo:抱歉,你必须有一个tty来运行sudo”

Apparently Fedora locks out non tty sudo commands. 显然Fedora锁定了非tty sudo命令。

A quick search led to the solution: 快速搜索导致了解决方案:

  1. As root run "visudo." 根本运行“visudo”。
  2. Find the line with "Default requiretty" and comment it out (#Default requiretty) 找到“Default requiretty”行并将其注释掉(#Default requiretty)

Hope this is helpful for anyone else who runs into this issue. 希望这对遇到此问题的任何其他人都有帮助。

You have to put a startup link in /etc/rc?.d. 你必须在/etc/rc?.d中放置一个启动链接。 You can use chkconfig(8) or ntsysv(8) to help you administer these directories. 您可以使用chkconfig(8)或ntsysv(8)来帮助您管理这些目录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM