使用 EC2 cloud-init 启动脚本启动 long-运行 任务
Use EC2 cloud-init startup script to launch a long-running task
当我的 EC2 实例开始安装包、提取代码然后启动一个长 运行ning 任务时,我使用我的 cloud-init 启动脚本,这可能 运行 几天:
su - username -c 'python /path/script.py'
如果脚本在该行停留数天,这是否是 cloud-init 的问题?
如果是这样,在允许 cloud-init 脚本结束的同时让脚本 运行 的最佳方法是什么?
what is the best way to let the script run while permitting the cloud-init script to end?
我会使用 'at' 命令,例如
echo "python /path/script.py"|at now +3 minutes
脚本将在该命令后的 3 分钟内变为 运行,并且 cloud-init 脚本将继续 运行 而无需等待 script.py。
su
可能有问题,所以从根目录运行脚本会更简单,当然如果可以的话。
事实证明,使用 cloud-init 脚本 运行 几个小时不是问题。 AWS 似乎没有适当的机制来杀死几个小时后仍未终止的 cloud-init 脚本。
当我的 EC2 实例开始安装包、提取代码然后启动一个长 运行ning 任务时,我使用我的 cloud-init 启动脚本,这可能 运行 几天:
su - username -c 'python /path/script.py'
如果脚本在该行停留数天,这是否是 cloud-init 的问题? 如果是这样,在允许 cloud-init 脚本结束的同时让脚本 运行 的最佳方法是什么?
what is the best way to let the script run while permitting the cloud-init script to end?
我会使用 'at' 命令,例如
echo "python /path/script.py"|at now +3 minutes
脚本将在该命令后的 3 分钟内变为 运行,并且 cloud-init 脚本将继续 运行 而无需等待 script.py。
su
可能有问题,所以从根目录运行脚本会更简单,当然如果可以的话。
事实证明,使用 cloud-init 脚本 运行 几个小时不是问题。 AWS 似乎没有适当的机制来杀死几个小时后仍未终止的 cloud-init 脚本。