Aws Ec2 run script program at startup

痞子三分冷 提交于 2019-12-10 11:24:56

问题


There is a method to setup an EC2 machine to execute Kafka starting script on startup? I use also java Aws SDK, so I accept both solution for a program java that run command on EC2 instance and solutions for a bash script mode that run kafka script at startup.


回答1:


A script can be passed in the User Data property.

If you are using the Amazon Linux AMI, and the first line of the script begins with #!, then the script will be executed the first time that the instance is started.

For details, see: Running Commands on Your Linux Instance at Launch




回答2:


What is the OS of EC2 instance?

  1. You could use userdata script at instance launch time. Remember this is just 1time activity

  2. If your requirement is to start the script everytime you reboot EC2 instance then you could make use of rc.local file on Linux instances which is loaded at OS boot time.




回答3:


If you are running a windows EC2 you'll want to read: https://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/ec2-windows-user-data.html

Example:

<script>
echo Current date and time >> %SystemRoot%\Temp\test.log
echo %DATE% %TIME% >> %SystemRoot%\Temp\test.log
</script>


来源:https://stackoverflow.com/questions/49594391/aws-ec2-run-script-program-at-startup

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!