Note: Please go to docs.rightscale.com to access the current RightScale documentation set. Also, feel free to Chat with us!
Home > Guides > RightLink 6 > RightLink Legacy Versions > RightLink 5.9 > Using RightLink > Command Line Utilities - v5.9

Command Line Utilities - v5.9

Overview

The following command line utilities are useful for setting and getting information between RightLink enabled images and the RightScale platform.

Availability

The following command line utilities are available for use on instances with RightLink v5.8 and above. For example, if you are using a RightImage (e.g. RightImage_CentOS_5.6_x64_v5.8) or a custom RightScale-enabled image that includes RightLink v5 and above. If you are using older RightImages, some RightLink utilities might not be supported.

Note: The 2012-06-29 ServerTemplate release features RightScale templates that use v5.8 RightImages and RepoPaths that feature the consolidated cookbook repository (rightscale/rightscale_cookbooks). The older ServerTemplates use the v5.7 RightImages and RepoPaths that reference the older RightScale repository (rightscale/cookbooks_public). If you are using older ServerTemplates that use v5.7 RightImages, the RightScale Cookbooks are located under rs_utils (rightscale/cookbooks_public/cookbooks/rs_utils). If you are using v5.8 RightImages, RightScale Cookbooks are located under rightscale (rightscale_cookbooks/cookbooks/rightscale).

Warning!

Customized images are not fully supported by RightScale. We encourage you to use our ServerTemplates and RightImages. However, if you do create custom images and would like to RightLink-enable them, please see Creating RightScale-enabled Images with RightLink.

 

Table of Contents (abbreviated)

General Information

RightScale's command line utilities are found in /usr/bin on Linux systems*.  To see all installed "rs" utilities:

ls /usr/bin/rs_*

From within a running instance you can issue a "--help" or "-h" command line flag to see synopsis, example and usage information. For example:

rs_log_level -h
rs_run_recipe --help

Below is documentation for the more commonly used RightScale command line utilities for Chef.


Note: The following utility also exists in the /usr/bin directory.

  • rs_reenroll and rs_thunk - Not designed to be used by RightScale customers or partners.  (This is an Internal tool used by RightScale.)

Windows Support

Although the example screenshots below are from a Linux system, these command line utilities are part of RightLink on Windows systems as well.

  • Usage is the same as Linux systems
  • /usr/bin is part of the PATH environment variable in Linux and is added to the Windows PATH as well.

RightLink Utilities

rs_connect

Designed for RightScale internal use only. Not intended for use by end users.

Usage
rs_connect [options]

Options

--attach, -a Attach this machine to a server
--force, -f Force attachment even if server appears already connected
--cloud, -c Name of cloud in which instance is running or 'none' to indicate instance is not running in any cloud. If a cloud has already been selected during installation of RightLink then this option will override that choice. If no choice has been made then the default is 'none'.
--help: Display help
--version: Display version information

 


rs_log_level

Synopsis

RightScale Log Level Manager (rs_log_level)
Log Level Manager allows setting and retrieving the RightLink agent log level.

Usage
rs_log_level [--log-level, -l debug|info|warn|error|fatal]
root@good:~# rs_log_level --help

 

Options

--log-level, -l LVL Set log level of RightLink agent
--verbose, -v Display debug information
--help: Display help
--version: Display version information

 

 

No options prints the current RightLink agent log level.

Examples

Retrieve log level:

rs_log_level

Set log level to debug*:

rs_log_level --log-level debug
rs_log_level -l debug

*Note: You have to be logged in as root to set the log level of the RightLink agent.


rs_ohai

Synopsis

RightScale Ohai (rs_ohai) is an implementation of Ohai by RightScale
rs_ohai is a utility that inspects a running instance and discovers relevant system-specific data.

Usage

Options

-d,  --directory DIRECTORY A directory to add to the Ohai search path
-f,  --file FILE A file to run Ohai against
-l,  --log_level LEVEL Set the log level (debug, info, warn, error, fatal)
-L,  --logfile LOGLOCATION Set the log file location, defaults to STDOUT - recommended for daemonizing
-v,  --version Show chef version
-h,  --help Show this message

 

Examples

Retrieve system data:

rs_ohai

Set the log level to debug*:

rs_ohai --log_level debug
rs_ohai -l debug

*Note: most commands invoked by Ohai/Chef are logged with the debug severity for easier debugging of troublesome providers or recipes. 


rs_reenroll

Designed for reestablish communication with the RightScale brokers.


rs_run_recipe

Synopsis

RightScale Bundle Runner (rs_run_right_script/rs_run_recipe) rs_run_right_script and rs_run_recipe are command line tools that allow running RightScripts and recipes respectively from within an instance.

Usage 
root@localhost:~# rs_run_recipe --help 
rs_run_recipe --identity, -i ID [--json, -j JSON_FILE] [--verbose, -v]
rs_run_recipe --name, -n NAME [--json, -j JSON_FILE] [--verbose, -v]

* Can appear multiple times

Options

--identity, -i ID RightScript or ServerTemplateChefRecipe id.   For example, 
https://my.rightscale.com/acct/1/right_scripts/12345, 12345 is the ID
--name, -n NAME RightScript or Chef recipe name (overriden by id)
--json, -j JSON_FILE JSON file name for JSON to be merged into attributes before running recipe
--parameter, -p NAME=type:VALUE   Define or override RightScript input  Note: Only applies to run_right_script
--thread, -t THREAD Schedule the operation on a specific thread name -t THREAD for concurrent execution. Thread names must begin with a letter and can consist only of lower-case alphabetic characters, digits, and the underscore character.
--policy, -P POLICY Audits for the executable to be run will be grouped under the given policy name. All detail will be logged on the instance, but limited detail will be audited.
--audit_period -a PERIOD_IN_SECONDS Specifies the period of time that should pass between audits
--recipient_tags, r TAG_LIST Tag for selecting which instances the script will be run on. The tag must not contain any spaces. Available with RightLink 5.7 and above.
--scope, -s SCOPE Scope for selecting tagged recipients: single or all (default all)
--cfg-dir, -c DIR Set directory containing configuration for all agents
--verbose, -v Display progress information
--help: Display help
--version: Display version information
Examples

Run recipe with id 12 and verbose output:

rs_run_recipe -i 12 -v
rs_run_recipe --identity 12 --verbose

Run the recipe, web_apache::do_restart on all servers with the tag, foo

rs_run_recipe --name "web_apache::do_restart" -r "foo" --verbose

Run the recipe, web_apache::do_restart on all servers with the tag, sport:basketball=lakers

rs_run_recipe --name "web_apache::do_restart" -r "sport:basketball=lakers" --verbose

Run the recipe, rightscale::setup_hostname with a created node.json override file:

# ensure root can only read the json file if on a shared system
touch /root/node.json && chmod -v 770 /root/node.json

# simple bash heredoc for creating the node.json
cat <<EOF> /root/node.json
{
  "rightscale" : {
     "timezone":"Australia/Sydney"
  }
}
EOF

# run rs_run_recipe with the node.json created
rs_run_recipe -v --name="rightscale::setup_timezone" --json /root/node.json

rs_run_right_script

Note: If you use rs_run_right_script with the -p option, you must pass a COMPLETE set of input values in which case the input values that are defined on the server are not merged. If you omit any inputs, e.g. do not use -p, then the values defined on the server are used. However we do not provide a way to mix and match.

Synopsis

RightScale Bundle Runner (rs_run_right_script/rs_run_recipe)
rs_run_right_script and rs_run_recipe are command line tools that allow running RightScripts and recipes respectively from within an instance. With RightLink 5.7 and above, you can also execute RightScripts on other instances within the deployment.

Like any tag used with the RightScale platform, these tags can be plain tags ("foo") or machine tags ("foo:bar=baz") Their values are arbitrary and user-defined; users may apply tags through UI or API, or RightScripts/recipes included in ServerTemplates may cause servers to tag themselves.

Usage
root@good:~# rs_run_right_script --help
rs_run_right_script --identity, -i ID [--parameter, -p NAME=type:VALUE]* [--verbose, -v] [--recipient_tags, -r TAG_LIST]

rs_run_right_script --name, -n NAME [--parameter, -p "NAME=type:VALUE" -p "FOO=text:bar" -p "PING=text:pong"]* [--verbose, -v] [--recipient_tags, -r TAG_LIST]

* Can appear multiple times

Options

--identity, -i ID RightScript or ServerTemplateChefRecipe id.  For example, 
https://my.rightscale.com/acct/1/right_scripts/12345, where '12345' is the ID
--name, -n NAME RightScript or Chef recipe name (overriden by id)
--json, -j JSON_FILE JSON file name for JSON to be merged into attributes before running recipe
--parameter, -p NAME=type:VALUE Define or override RightScript input.  
Note: Only applies to run_right_script
--thread, -t THREAD Schedule the operation on a specific thread name for the concurrent execution. Thread names must begin with a letter and can consist only of lower-case alphabetic characters, digits, and the underscore character.
--policy, -p POLICY Audits for the executable to be run will be grouped under the given policy name. All detail will be logged on the instance, but limited detail will be audited. Available with RightLink 5.8 and above.
--audit_period, -a PERIOD_IN_SECONDS Specifies the period of time that should pass between audits. Available with RightLink 5.8 and above.
--recipient_tags, -r TAG_LIST Tag for selecting which instances the script will be run on. The tag must not contain any spaces. Available with RightLink 5.7 and above.
--scope, -s SCOPE Scope for selecting tagged recipients: single or all (Default: all)
--cfg-dir, -c DIR Set directory containing configuration for all agents
--verbose, -v Display progress information
--help: Display help
--version: Display version information
Examples

Run RightScript with an ID of 34 and verbose output:

rs_run_right_script -i 34 -v
rs_run_right_script --identity 34 --verbose

Run RightScript with name, 'Install Nginx' and verbose output:

rs_run_right_script -n "Install Nginx" -v
rs_run_right_script --name "Install Nginx" --verbose

Run RightScript with and ID of 14 and override the input value for 'APPLICATION' with 'Mephisto':

rs_run_right_script -i 14 -p "APPLICATION=text:Mephisto"
rs_run_right_script --identity 14 --parameter "APPLICATION=text:Mephisto"

Run RightScript, 'Hello World!' with credential, 'HelloWorldText' for input, HW_TEXT:

rs_run_right_script --n "Hello World!" --p "HW_TEXT=cred:HelloWorldText"
rs_run_right_script --name "Hello World!" --parameter "HW_TEXT=cred:HelloWorldText"
Run the "register app server" RightScript on the server that is tagged as being a load balancer. This option takes a space-separated list of one or more tags, which will be used to select one or more target servers on which to run the script or recipe.
rs_run_right_script -n "APP register app server" -r "app:role=load_balancer"
Run the MySQL backup recipe on servers that are tagged as being a database machine and also a master.
rs_run_recipe -n "mysql::backup" -r "app:role=database database:master=true"

rs_shutdown

Usage
rs_shutdown [options]

Options

--reboot, -r Request reboot
--stop, -s Request stop (boot volume is preserved)
--terminate, -t Request termination (boot volume is discarded)
--immediately, -i       Request immediate shutdown (reboot, stop or terminate) by passing any pending scripts and preserving instance state
--deferred, -d Request deferred shutdown (reboot, stop or terminate) pending finishing of any remaining scripts (default)
--verbose, -v Display progress information
--help: Display help
--version: Display version information

rs_tag

Synopsis

RightScale Tagger (rs_tag)

Tagger allows listing, adding and removing tags on the current instance and querying for all instances with a given set of tags.

Note: Spaces in tags are not supported in RightLink v5.7 and earlier.

Usage
root@good%  rs_tag --help
 rs_tag (--list, -l | --add, -a TAG | --remove, -r TAG | --query, -q TAG_LIST)

Options

--list, -l List current instance tags
--add, -a TAG NAME Add tag NAME. 
--remove, -r TAG NAME Remove tag NAME
--query, -q TAG_LIST Query tag information about instances in your deployment
--die, -e Exit with error if query/list fails
--format, -f FMT Output format: json, yaml, text
--verbose, -v Display debug information
--help: Display help
--version: Display version information
--timeout, -t Custom timeout parameter (Default = 120 seconds)
Examples

Retrieve all tags:

rs_tag --list
rs_tag -l

 

Add tag 'opinions:tags=awesome' to instance:

rs_tag --add 'opinions:tags=awesome'
rs_tag -a 'opinions:tags=awesome'

 

Remove tag 'opinions:tags=awesome' from instance:

rs_tag --remove 'opinions:tags=awesome'
rs_tag -r 'opinions:tags=awesome'

 

Get and print last tag value for 'opinions:tags':

tag=$(rs_tag --list | grep 'opinions:tags' | head -n 1) && tag_value=${tag##*=}
echo 'Opinion on tags: '"$tag_value"

 

Remove all tags:

for i in `rs_tag --list | grep - | awk '{print $2}'`; do $(rs_tag --remove $i) ; done

 

In a RightScript, manage a unique tag 'on itself' using an Input value:


#!/bin/bash -e

# RightScript: Set node DNS hostname tag

# NODE_HOSTNAME can be set to any type text, environment variable, credential etc.
# e.g. EC2_PUBLIC_HOSTNAME

# remove any existing rs_node:dns_hostname tags
tags_remove=$(rs_tag --list | grep 'rs_node:dns_hostname' | awk '{ print $2 }')

# remove existing tags
for tag in `echo $tags_remove`
do
	echo Removing "$tag"
	rs_tag --remove "$tag"
done

# Add rs_node dns hostname tag
rs_tag --add 'rs_node:dns_hostname='"$NODE_DNS_HOSTNAME"

# get and print 1st/last set rs node dns hostname
tag=$(rs_tag --list | grep 'rs_node:dns_hostname' | head -n 1) && node_dns_hostname=${tag##*=}
echo 'Current/latest node dns hostname: '"$node_dns_hostname"

echo 'Done.'

 

Querying for tags:

Use rs_tag with the --query, -q TAG_LIST to query tag information about instances in your deployment only. A query will not return instances that are in a different deployment. TAG_LIST is a space-delimited list of machine tags. You can use some wildcard functions in the TAG_LIST by substituting an asterisk (*) for the value part of the machine tag -- for example, rs_tag -q "loadbalancer:app=*". 

 

Note: This is not a fully supported wildcard function. Semi-wildcard functions will not work, such as rs_tag -q "loadbalancer:app=prod*"

 

This returns a JSON object to stdout with the following syntax:

{ <agentA_id> : { "tags": [ <tag_n> ] } }

# rs_tag --query "rs_logging:state=*"
{
  "rs-instance-05c03c0150c3b55b83a63b4eb8c0f2af5156d8ea-5013179": {
    "tags": [
      "rs_launch:type=auto",
      "rs_logging:state=active",
      "rs_login:state=active",
      "rs_monitoring:state=active"
    ]
  },
  "rs-instance-00f2710adb07e72bbabf42092c93c675098a9ef0-5013178": {
    "tags": [
      "rs_launch:type=auto",
      "rs_logging:state=active",
      "rs_login:state=active",
      "rs_monitoring:state=active"
    ]
  },
  "rs-instance-71334da6925feee899ee1e5d58cc8c8b2423a59a-5325028": {
    "tags": [
      "rs_logging:state=active",
      "rs_login:state=active",
      "rs_monitoring:state=active"
    ]
  }
}
 
Please note that this is not a full wildcard function. You will receive an error if you attempt to enter the following: 
# rs_tag --query "rs_logging:sta*"
# rs_tag --query "rs_logging:*"
# rs_tag --query "rs_logg*"
Any of these will instead produce an error about an invalid wildcard statement.

rs_thunk

Designed for RightScale internal use only. Not intended for use by end users.


See also

You must to post a comment.
Last modified
13:36, 3 Sep 2014

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.