Saturday, February 17, 2018

Run shell script on Your Linux Instance at Launch

Run shell script on Your Linux Instance at Launch

When you launch an instance in Amazon EC2, you have the option of passing user data to the instance that can be used to perform common automated configuration tasks and even run scripts after the instance starts. You can pass two types of user data to Amazon EC2: shell scripts and cloud-init directives. You can also pass this data into the launch wizard as plain text, as a file (this is useful for launching instances using the command line tools), or as base64-encoded text (for API calls).
If you are interested in more complex automation scenarios, consider using AWS CloudFormation and AWS OpsWorks. For more information, see the AWS CloudFormation User Guide and the AWS OpsWorks User Guide.
For information about running commands on your Windows instance at launch, see Running Commands on Your Windows Instance at Launch and Managing Windows Instance Configuration in the Amazon EC2 User Guide for Windows Instances.
In the following examples, the commands from the Installing a LAMP Web Server tutorial are converted to a shell script and a set of cloud-init directives that executes when the instance launches. In each example, the following tasks are executed by the user data:

  • The distribution software packages are updated.
  • The necessary web server, php, and mysql packages are installed.
  • The httpd service is started and turned on via chkconfig.
  • The www group is added, and ec2-user is added to that group.
  • The appropriate ownership and file permissions are set for the web directory and the files contained within it.
  • A simple web page is created to test the web server and PHP engine.
By default, user data and cloud-init directives only run during the first boot cycle when you launch an instance. However, AWS Marketplace vendors and owners of third-party AMIs may have made their own customizations for how and when scripts run.

The following is example output.
#!/bin/bash yum update -y service httpd start chkconfig httpd on contect reference https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/user-data.html#user-data-shell-scripts

6 comments:

  1. thanks for sharing your expertise and also the time it took to post!!

    DevOps Training in Hyderabad

    ReplyDelete
  2. I like your post. Everyone should do read this blog. Because this blog is important for all now I will share this post. Thank you so much for share with us.


    Data Science Training in Hyderabad

    ReplyDelete
  3. amazon account manager is the most cost-effective and hassle free way to optimize and scale your Amazon business to its full operational capacity.

    ReplyDelete

Ethical Hacking Techniques: Cracking WPA/WPA2 Wi-Fi Using WPS and Capturing Handshakes

In the realm of cyber security, ethical hacking plays a crucial role in identifying and addressing vulnerabilities. One of the areas where e...