EC2上的启动脚本

发布于 2024-07-13 19:34:59 字数 976 浏览 4 评论 0原文

我创建了一个自定义 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

风铃鹿 2024-07-20 19:34:59

好吧,我终于想通了。 在搜索 EC2 输出后,我发现了这一行:

“Starting ntstartup: sudo: 抱歉,你必须有一个 tty 才能运行 sudo”

显然 Fedora 锁定了非 tty sudo 命令。

快速搜索找到了解决方案:

  1. 以 root 身份运行“visudo”。
  2. 找到包含“Default requiretty”的行并将其注释掉(#Default requiretty)

希望这对遇到此问题的其他人有所帮助。

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.

满身野味 2024-07-20 19:34:59

您必须将启动链接放入 /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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文