The purpose of the Basic Example tutorial is to introduce you to some of the basic RightScale concepts and demonstrate how easy it is to set up and launch a web server on EC2 using the RightScale Dashboard by using our various ServerTemplates and RightScripts. Learn how to create custom RightScripts and connect to your EC2 instance using an SSH console. Upload a simple web page and web application to the web server and then preview it in a browser window.
The Basic Example can be completed with any type of account (Free Trial, Developer, Premium).
If you do not have a RightScale account, sign up for a Free Trial account at http://www.rightscale.com. If you are running a trial account and your EC2 time has expired, you will need to create an AWS account and Sign up for AWS (AWS Credentials) and Add AWS credentials to RightScale.
If you are using a free trial account, you must activate your trial account by clicking on the link that was emailed to you from notifier@my.rightscale.com.
Step 1: Create an Apache server template
Step 2: Create and add a RightScript to the server template
Step 3: Launch the web server on EC2
Step 4: Connect to the instance using the SSH Console
Step 5: Upload files to the web server
Bonus: Upload a web application to the web server
Let's begin by creating a new server template and adding some scripts to it. A server template defines the composition and configuration of your EC2 instance. When an instance is launched from a server template, it uses a base OS image and a series of scripts to install and configure the server as it boots. Server templates help you get up and running quickly, while also giving you the flexibility to clone and customize these server templates so that you can reuse and leverage all the pre-existing assets.
Click on the Design tab. Go to Servers -> ServerTemplates.
Click the New button to create a new server template.

Next you will provide some basic information about your new server template.

Click Save and a confirmation screen will appear with information about the new server that you just created.

Now we have a blank server template that we can use to build our Apache web server.
The next step is to add some extra functionality to the server template by inserting a RightScript.
A RightScript is any script that you define within the RightScale Dashboard. It may be a shell script, a perl script, a ruby script, etc. RightScripts are attached to Server Templates as either boot scripts that run at boot time, operational scripts that can be run once a server is running, or as decommission scripts that run before a server is terminated.
Go to Design -> Servers -> RightScripts.
As you create custom RightScripts of your own, they will be listed alphabetically. Once a RightScript is defined, it can be used by any server template in an account.

Click the New button to create a new RightScript. Let's create a new RightScript that installs Apache on the web server.

Click Save.
Now that you've created the new RightScript, you need to add it to the "apache webserver" server template.
Go to Design -> Server Templates, and click on apache webserver server template.

Click on the Scripts tab.
RightScripts can be added to server templates as either a boot, operational, or decomission script. Let's configure the RightScript to automatically run when the server boots.

Select the apache install script from the pulldown list of private RightScripts.
Select boot script from the dropdown box.
Click Add.

The "apache install" RightScript is now listed under Boot Scripts and is configured to run at boot time whenever the “apache webserver” server template is used to create a new server.
The template is now ready to be launched. Click the Launch button.

Troubleshooting
If you receive an error message saying that your account has insufficient funding to perform this action, you need to verify your email address. Go to your email account and check for an email confirmation from notifier@rightscale.com. It may be in your bulk/spam folder. Click on the email link and your account should be activated. Refresh and launch the server again. If you are still experience problems, please contact support@rightscale.com.

Verify your settings and click Launch.
Since inputs were not specified in the server template, zero inputs are listed.

Click Launch.
The “apache webserver” that you just configured in the Dashboard is now being launched on EC2.
Under Recent Events, you can track the status of the server's boot process.

The "apache webserver" template that you just launched is now pending. The server will take a couple of minutes to complete the boot process. Server templates ensure that new servers are launched exactly how you configured it. After a couple of minutes you should see the instance's status change from "pending" to "operational," and show the elapsed time (Age) of each event.

Once your server is operational, go back to the Dashboard’s main window (Home -> Dashboard, or you can click on the RightScale logo) to see all of your running instances.

Under Nickname, click apache webserver and you will be taken to a general information page for your running instance.

Click on the Public DNS name link to view your running EC2 instance in a new browser window. We will reference this link again during the tutorial, so it will be helpful to keep this window open as a quick reference.
You should now see the Apache 2 Test Page in your web browser. You should also receive an email from notifier@rightscale.com informing you that the 'apache webserver' instance is now operational.
Congratulations! You just launched a live web server on EC2! Anyone in the world can type in your Public DNS name (ex: http://ec2-67-202-46-87.compute-1.amazon.aws.com) and see the Apache 2 Test Page.
By default, the web server that you just launched is currently pointing to an Apache homepage. Let’s create our own custom landing page using the SSH console.
Go back to your instance's homepage and click on the SSH Console button to “SSH” into the machine.

You can also open an SSH window by clicking the SSH button next to the instance's DNS.

A couple Warning-Security screens may appear. Click Run. Click Yes.
NOTE: If you don't have Java configured correctly, you will need to ssh in manually by following the client setup in this guide. See FAQ: How do I ssh into my machines?

You are now logged into the instance. From this command prompt, create a file called, /var/www/html/index.html and paste the following code.
<html>
<head>
<title>Tutorial: Apache Server</title>
</head>
<body>
<h1>Welcome to RightScale!</h1>
</body>
</html>
Reload your “apache webserver” by typing service httpd restart from the SSH command prompt. Click Enter. Now refresh the preview in the browser window that is displaying the instance's public DNS link. Or you can go back to the Dashboard and click on the public DNS name to load the new homepage.

Congratulations! You just logged into your EC2 instance using the SSH console and manually created a custom homepage for your Apache webserver. But, wouldn't it be great if we could somehow automate this manual process?
Next, we’ll create a new RightScript that will accomplish the same task. Except this time, we will also create a variable that will allow us to display different messages.
Go to Design -> RightScripts. Click New.
#!/bin/bash
cat <<EOF> /var/www/html/index.html
<html>
<head>
<title>Tutorial: Apache Server</title>
</head>
<body>
<h1>$WELCOME_MESSAGE</h1>
</body>
</html>
EOF
service httpd restart

Click Save.
Click the Script tab and look at the list of Inputs. Notice that the RightScale Dashboard automatically recognizes the WELCOME_MESSAGE parameter! Instead of hard-coding a message, we will use the WELCOME_MESSAGE variable, so that we can use the same script to display different messages.

Now add the new “configure homepage” RightScript to the “apache webserver” server template. But this time, add it as an operational script. Operational scripts behave similar to boot scripts, but they are not run when the instance boots. Operational scripts are run on-command.
Go to Design -> Server Templates. Select the apache webserver template.
Click the Scripts tab and select the configure homepage RightScript and define it as an operational script by clicking Add.

After we've added this new operational script, we can execute this script from the running instance page. But, before you run the instance again, specify a new value for the WELCOME_MESSAGE parameter. (Manage -> Active Servers; select “apache webserver.”)
Go back to the Dashboard’s main window (Home -> Dashboard, or you can click on the RightScale logo) and click on "apache webserver."

Now click on the Script Inputs tab. Click Edit.

To define the welcome message parameter, select Text and type RightScripts Rock! and click Save.

To run this new operational script, go to the Scripts tab and click the Run button on the right.

The “configure homepage” operational script now appears in the Recent Events list. Once the task is 100% completed, take another look at the server's homepage in a browswer window. (Refresh your DNS browser window.) The message should have changed to "RightScripts Rock!"
If you accidentally closed the preview browser window, go to the Dashboard (click on the RightScale logo) and click on the public DNS link for the “apache webserver.” You should now see the following page in a browser window.

In the example above, you defined the page’s <H1> tag to display the text “RightScripts Rock.” Congratulations! You now you have a RightScript that will display any text message that you define.
Instead of creating a RightScript that loads a simple html page, we will upload a web application and create a RightScript that deploys an entire web application.
Download the following sample web application: webapp.tgz
Create a new RightScript called, deploy webapp.
Paste the following code into the Script field.
tar xzf $ATTACH_DIR/webapp.tgz -C /var/www/html/ service httpd restart

Click Save.
Since we are launching a web application, we need to attach the webapp file to the server template. Click on the Attachments tab. Browse and upload the webapp.tz file.

Click on the Script tab and take a look at what this script does.

Notice the $ATTACH_DIR in the script.
RightScripts allow you to attach as many files as you want to a server template. Simply append each file with $ATTACH_DIR/ in front of the filename.
The next step is to attach the "deploy webapp" RightScript to the server template.
Go to the Dashboard homepage and click on "apache webserver" server template (not the nickname).

Click on the Scripts tab. Add the "deploy webapp" as an operational script.

Go to Home -> Dashboard and click on "apache webserver" nickname (not the server template).

Click on the Scripts tab.

To run the "deploy webapp" RightScript, click on the Run button.
After refreshing the preview window, you should see the new homepage of your EC2 instance, which is running the webapp.tz web application. (In this example, the web application is a simple html page.)

To turn this example into a reusable server configuration for launching a generic website, simply change the “deploy webapp” RightScript from an operational script to a boot script.
And once you are done testing the web application, don't forget to terminate your instance to ensure that completing this tutorial will only cost $0.10. Go to Manage -> Servers -> Active Servers and click on the Stop button.

----------------------
Did you find this document helpful? Please feel free to leave us a comment below. We're always looking for ways to improve our documentation. Thanks!
| File | Size | Date | Attached by | |||
|---|---|---|---|---|---|---|
| webapp.tgz webapp.tz | 215 bytes | 18:38, 3 Apr 2008 | deano | Actions | ||
The part at the end regarding uploading the webapp was especially promising as I would like to deploy our application server this way, but ideally I'd be able to upload the file as part of a one-step build/deploy process.
There's a small error error in the 'configure webserver' script, as curt noticed above. The commands after the final EOF are written to the file (and shown on the web front page) instead of executed.
The reason is that the scrip contains two spaces that mess up the EOF marker. One between << and EOF and another after the final EOF. Just remove these two spaces, and it works as expected.
I will add you suggestion Curt, and Emil, thanks for pointing that out, it has been fixed.
Martin
You are right, if you want security, jail apache and run it as a non-root user.
Our templates are not designed as an all-inclusive solution for every user. Rather, they are starting point to get you setup quickly and easily, and meant to be customized to fit your particular needs. So, indeed you will find plenty of situations where you would like a specific setup that is not provided. That is why we make it easy to clone and customize scripts and templates.
In this case, we chose to use the default CentOS installation. If we had made the default installation run as a different user and in a chroot environment, it would increase the complexity, and therefore the learning curve, of *all* users, and this is something that we want to minimize. Savvy users, like yourself, who know what they are doing usually want to make all sorts of tweaks and customizations anyways, and that is fine because they are very capable of implementing them. In this case, jailing apache and running it as a different user is trivial for an experienced sysadmin.
Thanks for your post,
Martin
Great tutorial, though! I can't believe how easy this is to work with. edited 22:56, 28 Apr 2008
I like to write this as:
cat > zap.txt <<EOF
Example here document.
All of this ends up in the file zap.txt in the current directory.
EOF