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 the Elastic Compute Cloud (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, and you are not ready to sign-up for one of our pay editions, you can create an AWS account and set up a Free Developer account. See Upgrade Your Account to learn how to sign-up for AWS and add your credentials into the Dashboard.
NOTE: 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 ServerTemplate
Step 2: Create and add a RightScript to the ServerTemplate
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 ServerTemplate and adding some scripts to it. A ServerTemplate defines the composition and configuration of your EC2 instance. When an instance is launched from a ServerTemplate, it uses a base OS image and a series of scripts to install and configure the server as it boots. ServerTemplates help you get up and running quickly, while also giving you the flexibility to clone and customize these ServerTemplates so that you can reuse and leverage all the pre-existing assets.
Go to Design -> ServerTemplates and click the New button to create a new ServerTemplate.
NOTE: For multi-cloud support, your buttons may be labeled slightly different, including the cloud name. For example, "New EC2" or "New Flexiscale," etc. For this example, select the "New" or "New EC2" button.

Next you will provide some basic information about your new ServerTemplate.

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

Now you have a blank ServerTemplate that you can use to build your Apache web server.
The next step is to add some extra functionality to the ServerTemplate 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. There are three types of RightScripts that are attached to ServerTemplates
Go to Design -> RightScripts.
As you create custom RightScripts of your own, they will be listed alphabetically under your Private tab. If you clone a RightScript from one of the other tabs, it will also appear under your Private tab. Once a RightScript is defined, it can be used by any ServerTemplate in an account.

Click the New button to create a new RightScript. 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" ServerTemplate.
Go to Design -> ServerTemplates, and click on apache webserver ServerTemplate.

Click on the Scripts tab.
RightScripts can be added to ServerTemplates as either a boot, operational, or decomission script. Since this RightScript is installing apache, you want it to automatically run when the server boots. Add the "apache install" RightScript as a boot script.

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

The Dashboard header displays "RightScript was successfully added" and the "apache install" RightScript is now listed under Boot Scripts. This RightScript is configured to run at boot time whenever the “apache webserver” ServerTemplate 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@my.rightscale.com. It may be in your bulk/spam folder. When you click the email validation link your account should be activated. Refresh and launch the server again. If you are still experience problems, please contact support@rightscale.com.
You may notice that the ServerTemplate has a [HEAD] label. Since you can commit and create revisions of ServerTemplates and RightScripts, you can only make changes to the curent [HEAD] version.

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

Click Launch.
The RightScale Dashboard header displays "Launched server apache" as the “apache webserver” 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. One of the main advantages of using ServerTemplates is that they ensure that new servers are launched exactly how you configured it, everytime! Depending how often you view the status window, after a couple of minutes you should see the instance's status progress from "pending" to "booting" and finally to "operational." The elapsed time (Age) of each event is also displayed.

Once your server is operational, go back to the Dashboard’s main window (Home -> Dashboard, or you can click on the RightScale logo as a shortcut) 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.

Two windows should be launched for you. The first is an ssh status and control window. The other is the ssh console itself.
A couple Warning-Security screens may appear. Click Yes when you see the SSH confirmation window.


Troubleshooting
Occassionally the very first attempt at ssh will fail. If this happens, simply close out the launched windows and attempt again by pressing the "SSH Console" button.
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.” Type: 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, you'll create a new RightScript that will accomplish the same task achieved in the previous step of this tutorial. Except this time, you will also create a variable that will allow you 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. The RightScale Dashboard header status message displays "RightScript was successfully added."
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” ServerTemplate. 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 once a server is operational.
Go to Design -> Server Templates. Select the apache webserver ServerTemplate.
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.
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. (You may observe a brief transition from "queued" to "completed".) Once the task is 100% completed, take another look at the server's homepage in a browser 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!." This was accomplished by simple variable substitution using RightScript inputs.
Congratulations! You now you have a RightScript that will display any text message that you define.
NOTE: The bonus section can only be completed with a Developer or pay edition of RightScale. You cannot complete the bonus section with a Free Trial account.
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 ServerTemplate. 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 ServerTemplate. Simply append each file with $ATTACH_DIR/ in front of the filename.
The next step is to attach the "deploy webapp" RightScript to the ServerTemplate.
Go to the Dashboard homepage and click on "apache webserver" ServerTemplate (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 ServerTemplate).

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.
When 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 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