Skip to content

Instantly share code, notes, and snippets.

@jyotty
Created July 14, 2015 00:25
Show Gist options
  • Save jyotty/254afa8f8a0421db7af6 to your computer and use it in GitHub Desktop.
Save jyotty/254afa8f8a0421db7af6 to your computer and use it in GitHub Desktop.
pacemaker cluster status in $PS1
# Pick a resource that runs only on the master (clone/ms won't work)
# then, in your /root/.bash_profile:
# . path/to/crm.sh
# export CRM_PS1_RESOURCE=xxx
# export PS1='[\u@\h \W](crm: $(__crm_ps1))\$ '
function __crm_ps1() {
local nodename="$(uname -n)"
crm_resource --list -Q >/dev/null 2>&1 || { echo "dead"; return 1; }
local standby="$(crm_attribute --node "$nodename" --name standby --query -l forever --quiet)"
[ "$standby" = "on" ] && { echo "standby"; return 0; }
local resource_location="$(crm_resource --resource "$CRM_PS1_RESOURCE" --locate -Q)"
[ "$resource_location" = "$nodename" ] && echo master || echo slave
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment