如何让云初始化启动脚本运行,每次我的EC2实例的靴子? [英] How do I make cloud-init startup scripts run every time my EC2 instance boots?

查看:999
本文介绍了如何让云初始化启动脚本运行,每次我的EC2实例的靴子?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有运行的AMI基于亚马逊的Linux AMI一个EC2实例。像所有的这样的AMI,它支持云初始化系统运行的基础上传递到每个实例的用户数据启动脚本。在这种特殊情况下,我的用户数据输入恰好是一个包含文件的源其他几个启动脚本:

 的#include
http://s3.amazonaws.com/path/to/script/1
http://s3.amazonaws.com/path/to/script/2
 

我第一次启动我的情况下,云初始化启动脚本正常运行。但是,如果我做了实例的软重启(通过运行须藤执行shutdown -r现在,例如),实例恢复时的没有的跑来跑去的启动脚本的第二次。如果我去到系统日志,我可以看到:

 运行云初始化用户脚本
用户脚本已经运行一次的每个实例
[  好  ]
 

这是不是我想要的 - 我可以看到有只有每个实例的生命周期运行一次启动脚本的效用,但对我来说这些都应该运行每次实例启动,像正常的启动脚本。

我认识到,一个可能的解决方案是手动有我的脚本运行后的第一时间把自己摆成的rc.local 。然而,这似乎是沉重的负担,因为云init和rc.d的环境是微妙的不同,我现在将不得不在第一次启动调试脚本和所有后续推出独立。

有谁知道我可以告诉云初始化始终运行我的脚本?这当然听起来象是云初始化的设计师会考虑。

解决方案

在11.10,12.04和更高版本,可以通过使'脚本用户'跑'永远'实现这一目标。 在/etc/cloud/cloud.cfg,你会看到类似这样的:

  cloud_final_modules:
  -  rightscale_userdata
  - 脚本每一次
  - 脚本每次开机
  - 脚本,每个实例
  - 脚本用户
  - 钥匙到控制台
  - 电话入户
  - 最后的消息
 

这可以开机后进行修改,或云配置数据重写此节可以通过用户数据被插入。也就是说,在用户数据可以提供:

 #云配置
cloud_final_modules:
  -  rightscale_userdata
  - 脚本每一次
  - 脚本每次开机
  - 脚本,每个实例
  -  [脚本用户,总是]
  - 钥匙到控制台
  - 电话入户
  - 最后的消息
 

这也可以被包含(#include)当你在你的描述做了。 不幸的是,现在,你不能修改cloud_final_modules,但只覆盖它。我希望补充修改配置部分在某一时刻的能力。

在灯架上有云的配置文档时提供更多的信息 <一href="http://bazaar.launchpad.net/~cloud-init-dev/cloud-init/trunk/view/head:/doc/examples/cloud-config.txt">http://bazaar.launchpad.net/~cloud-init-dev/cloud-init/trunk/view/head:/doc/examples/cloud-config.txt

另外,你可以通过'脚本每启动路径把文件在/ var / lib中/云/脚本/每引导,他们会运行。

I have an EC2 instance running an AMI based on the Amazon Linux AMI. Like all such AMIs, it supports the cloud-init system for running startup scripts based on the User Data passed into every instance. In this particular case, my User Data input happens to be an Include file that sources several other startup scripts:

#include
http://s3.amazonaws.com/path/to/script/1
http://s3.amazonaws.com/path/to/script/2

The first time I boot my instance, the cloud-init startup script runs correctly. However, if I do a soft reboot of the instance (by running sudo shutdown -r now, for instance), the instance comes back up without running the startup script the second time around. If I go into the system logs, I can see:

Running cloud-init user-scripts
user-scripts already ran once-per-instance
[  OK  ]

This is not what I want -- I can see the utility of having startup scripts that only run once per instance lifetime, but in my case these should run every time the instance starts up, like normal startup scripts.

I realize that one possible solution is to manually have my scripts insert themselves into rc.local after running the first time. This seems burdensome, however, since the cloud-init and rc.d environments are subtly different and I would now have to debug scripts on first launch and all subsequent launches separately.

Does anyone know how I can tell cloud-init to always run my scripts? This certainly sounds like something the designers of cloud-init would have considered.

解决方案

In 11.10, 12.04 and later, you can achieve this by making the 'scripts-user' run 'always'. In /etc/cloud/cloud.cfg you'll see something like:

cloud_final_modules:
 - rightscale_userdata
 - scripts-per-once
 - scripts-per-boot
 - scripts-per-instance
 - scripts-user
 - keys-to-console
 - phone-home
 - final-message

This can be modified after boot, or cloud-config data overriding this stanza can be inserted via user-data. Ie, in user-data you can provide:

#cloud-config
cloud_final_modules:
 - rightscale_userdata
 - scripts-per-once
 - scripts-per-boot
 - scripts-per-instance
 - [scripts-user, always]
 - keys-to-console
 - phone-home
 - final-message

That can also be '#included' as you've done in your description. Unfortunately, right now, you cannot modify the 'cloud_final_modules', but only override it. I hope to add the ability to modify config sections at some point.

There is a bit more information on this in the cloud-config doc at http://bazaar.launchpad.net/~cloud-init-dev/cloud-init/trunk/view/head:/doc/examples/cloud-config.txt

Alternatively, you can put files in /var/lib/cloud/scripts/per-boot , and they'll be run by the 'scripts-per-boot' path.

这篇关于如何让云初始化启动脚本运行,每次我的EC2实例的靴子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆