EC2上的启动脚本
我创建了一个自定义 Amazon AMI (Fedora),它运行一些脚本,然后关闭。
AMI 的问题是,如果我的代码发生更改,则 AMI 实例必须有一种方法可以在执行脚本之前获取最新的脚本。
我写了一个shell脚本& 将其放入 /etc/init.d/nt_startup
为了使代码保持最新,我在代码存储库中执行 git pull
shell 脚本,然后执行该脚本。
问题是,实例启动时 git pull 似乎没有运行,但 python 脚本运行得很好。 不知道我错过了什么......这是启动脚本:
#!/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
/usr/scripts/code/git_latest shell 脚本如下所示:
#pulls in the latest code from the repository
cd /usr/scripts/code
sudo git pull
它应该拉下最新的 process.py脚本。
奇怪的是,如果我 ssh 进入我的实例并手动执行启动脚本(/etc/init.d/nt_startup "start"
),git 脚本就可以正常工作。
我错过了什么吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,我终于想通了。 在搜索 EC2 输出后,我发现了这一行:
“Starting ntstartup: sudo: 抱歉,你必须有一个 tty 才能运行 sudo”
显然 Fedora 锁定了非 tty sudo 命令。
快速搜索找到了解决方案:
希望这对遇到此问题的其他人有所帮助。
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.
您必须将启动链接放入 /etc/rc?.d 中。 您可以使用 chkconfig(8) 或 ntsysv(8) 来帮助您管理这些目录。
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.