Note: Please go to docs.rightscale.com to access the current RightScale documentation set. Also, feel free to Chat with us!
Home > Guides > Dashboard Users Guide > Design > RightScripts > Actions > Create Reboot-safe RightScripts

Create Reboot-safe RightScripts

 

In the RightScale Dashboard, you can manually reboot an active server by selecting Reboot from the More actions drop-down (ServerName > More actions > Reboot). In order for your servers to reboot properly, you need to make sure that your scripts are configured correctly.  We are working hard to make sure that all of our RightScripts are reboot-safe.  However, you are responsible for ensuring that your own custom scripts are reboot-safe.  Follow the instructions below to make sure that your own RightScripts reboot-safe. 

Things to Consider

  • You cannot "patch" a program twice; it may not work if it's patched on reboot.
  • Most scripts that use mkdir to create a directory will fail the second time if you forget the -p option.
  • Updates on REBOOT are up to you and your application because you may want to skip updates when you reboot a server.
  • Database restores are not needed if the information was on /mnt because this data is automatically remounted on REBOOT.

As you can see, there are several details associated with performing a successful reboot.

To help you make sure that your RightScripts are reboot-safe, we've provided a template below that you can follow as an example.

Example: Reboot-safe RightScript

#!/bin/bash
#
# Description:
#
# Simple BASH RightScript that skips a portion of the code on REBOOT
#

#
# This code runs each time the server Boots or REBOOTS
#
set   # Display all of the Environment Variables to the Audit file

#
# Test for a reboot,  if this is a reboot just skip this script.
#
if test "$RS_REBOOT" = "true" ; then
  echo "Skip Example script on reboot."
  logger -t ExampleScript "Skip Example script on reboot."
  exit 0 # Leave with a smile ...
fi

#
#  This portion of the RightScript runs only on first Launch boot.
#
date
echo "This server just launched for the first time"
logger -t ExampleScript "This server just launched for the first time"

exit 0 # Leave with a smile...

 

Example Breakdown 

Now we'll explain all of the features of this script above:

#/bin/bash
  • Informs the shell that is is a BASH script

 

set
  • Displays all of the Environment Variables to the Audit FIle in the RightScale Dashboard and on the server in the /var/log/install file.  This is a nice way to see which variables you need to work with in your scripts.  WARNING! Remember that any code you "yum" install may add or delete variables later.  For example, when java is installed, it adds several variables to the environment.

 

if test "$RS_REBOOT" = "true" ; then
  echo "Skip Example script on reboot."
  logger -t ExampleScript "Skip Example script on reboot."
  exit 0 # Leave with a smile ...
fi
  • This short bash code example will exit the script at this point in the code when it's run for the second time on REBOOT.  You could also place code inside the "if" for scripts that ONLY run on reboot.

 

logger -t Example "your text here"
  • The "logger" program adds lines of text to the /var/log/messages file and sends them to the RightScale Dashboard.  The "-t"  token helps you "grep" for these lines.  Be sure to make it unique.

 

exit 0 # Leave with a smile...
  • Never leave the exit code to chance.  This last line in every script sets the value to "good" or "operational."  Some Linux commands leave behind a value in "$?" that can give you problems.  The "Leave with a smile..." line is just for fun.

 

Ruby Example

In your ruby scripts, the following example will provide a way to skip code that should not be done on reboot.

if  ENV['RS_REBOOT'] == 'true'
  system("logger -t ExampleScript Skipping Yada yada yada.")
  exit(0) # Leave with a smile ...
end
Viewing 2 of 2 comments: view all
I'm going through the list of "Actions." I'm checking for changes in the dashboard so I didn't do anything here. If it's changed, it needs a review.
Posted 06:36, 13 Aug 2013
The one thing is that the doc mentions a "Reboot" button. I don't remember seeing one but perhaps that's now "Relaunch?"
Posted 07:20, 14 Aug 2013
Viewing 2 of 2 comments: view all
You must to post a comment.
Last modified
08:54, 14 Aug 2013

Tags

Classifications

This page has no classifications.

Announcements

None


© 2006-2014 RightScale, Inc. All rights reserved.
RightScale is a registered trademark of RightScale, Inc. All other products and services may be trademarks or servicemarks of their respective owners.