This site best when viewed with a modern standards-compliant browser. We recommend Firefox Get Firefox!.

Linux-HA project logo
Providing Open Source High-Availability Software for Linux and other OSes since 1999.

USA Flag UK Flag

Japanese Flag

Homepage

About Us

Contact Us

Legal Info

How To Contribute

Security Issues

21 December 2007 Heartbeat release 2.1.3 is now out Download it and install it!

11 October 2007 NEW educational HA/DR Blog hosted by Alan Robertson

9 April 2007 Check out the Cool Heartbeat Screencasts: Installation, Intro to the GUI Part of the Heartbeat Education project

Last site update:
2008-07-25 12:26:20

crm_resource is a good alternative to the GUI (see GuiGuide), and is definitely your friend for scripting jobs and the like, except it has no man page so far (as of 2.0.7), so here are some tips.

crm_resource
usage: crm_resource [-?VS] -(L|Q|W|D|C|P|p) [options]
        --help (-?)     : this help message
        --verbose (-V)  : turn on debug info. additional instances increase verbosity
        --quiet (-Q)    : Print only the value on stdout (for use with -W)

Commands
        --list (-L)     : List all resources
        --query-xml (-x)        : Query a resource
                          Requires: -r
        --locate (-W)   : Locate a resource
                          Requires: -r
        --migrate (-M)  : Migrate a resource from it current location.  Use -H to specify a destination
                If -H is not specified, we will force the resource to move by creating a rule for the current location and a score of -INFINITY
                NOTE: This will prevent the resource from running on this node until the constraint is removed with -U
                          Requires: -r, Optional: -H, -f
        --un-migrate (-U)       : Remove all constraints created by -M
                          Requires: -r
        --delete (-D)   : Delete a resource from the CIB
                          Requires: -r, -t
        --cleanup (-C)  : Delete a resource from the LRM
                          Requires: -r.  Optional: -H
        --reprobe (-P)  : Recheck for resources started outside of the CRM
                          Optional: -H
        --refresh (-R)  : Refresh the CIB from the LRM
                          Optional: -H
        --set-parameter (-p) <string>   : Set the named parameter for a resource
                          Requires: -r, -v.  Optional: -i, -s
        --get-parameter (-g) <string>   : Get the named parameter for a resource
                          Requires: -r.  Optional: -i, -s
        --delete-parameter (-d) <string>: Delete the named parameter for a resource
                          Requires: -r.  Optional: -i
        --get-property (-G) <string>    : Get the named property (eg. class, type, is_managed) a resource
                          Requires: -r
        --set-property (-S) <string>    : Set the named property (not parameter) for a resource
                          Requires: -r, -t, -v
Options
        --resource (-r) <string>        : Resource ID
        --resource-type (-t) <string>   : Resource type (primitive, clone, group, ...)
        --property-value (-v) <string>  : Property value
        --host-uname (-H) <string>      : Host name
        --force-relocation (-f) : Force the resource to move by creating a rule for the current location and a score of -INFINITY
                This should be used if the resource's stickiness and constraint scores total more than INFINITY (Currently 10,000)
                NOTE: This will prevent the resource from running on this node until the constraint is removed with -U
        -s <string>     : (Advanced Use Only) ID of the instance_attributes object to change
        -i <string>     : (Advanced Use Only) ID of the nvpair object to change/delete

Examples

  1. Listing all resources

    •   crm_resource -L
  2. Checking where a resource is running (and if it does)

    •   crm_resource -W -r my_first_ip
        resource my_first_ip is running on: server1
      
        crm_resource -W -r my_first_ip
        resource my_first_ip is NOT running
  3. Start/stop a resource

    •   crm_resource -r my_first_ip -p target_role -v started
        crm_resource -r my_first_ip -p target_role -v stopped
  4. Query the definition of a resource

    •   crm_resource -x -r my_first_ip
  5. Migrating a resource away from its current location

    •   crm_resource -M -r my_first_ip
  6. Migrating a resource to a specific location

    •   crm_resource -M -r my_first_ip -H c001n02
  7. Allow a resource to return to its normal location

    •   crm_resource -U -r my_first_ip

      NOTE: the values of resource_stickiness and default_resource_stickiness may mean that it doesnt move back. In such cases, you should use -M to move it back and then run this command.
  8. Deleting a resource from the CRM

    •   crm_resource -D -r my_first_ip -t primitive
  9. Deleting a resource group from the CRM

    •   crm_resource -D -r my_first_group -t group
  10. Disabling a resource management for a resource in the CRM

    •   crm_resource -p is_managed -r my_first_ip -t primitive -v off
  11. Enabling a resource management for a resource in the CRM

    •   crm_resource -p is_managed -r my_first_ip -t primitive -v on
  12. Resetting a failed resource after having been manually cleaned up

    •   crm_resource -C -H c001n02 -r my_first_ip
  13. Rechecking all nodes for resources started outside of the CRM

    •   crm_resource -P
  14. Rechecking one node for resources started outside of the CRM

    •   crm_resource -P -H c001n02
  15. Querying a parameter of a resource. Say the resource is the following:
    • <primitive id="example_mail" class="ocf" type="MailTo" provider="heartbeat">
        <instance_attributes id="example_mail_inst">
          <attributes>
            <nvpair id="example_mail_inst_attr0" name="email" value="root"/>
            <nvpair id="example_mail_inst_attr1" name="subject" value="Example Failover"/>
          </attributes>
        </instance_attributes>
      </primitive>
      You could query the email address using the following:
        crm_resource -r example_mail -g email
  16. Setting a parameter of a resource. Following the same example above:
    •   crm_resource -r example_mail -p email -v "myemailaddress@somedomain.com"