summaryrefslogtreecommitdiffstats
path: root/tools/crm_standby.in
blob: 0911b9daec9336d348cd3d0206448373cfe0124a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#!@BASH_PATH@
#
# Copyright 2009-2018 the Pacemaker project contributors
#
# The version control history for this file may have further details.
#
# This source code is licensed under the GNU General Public License version 2
# or later (GPLv2+) WITHOUT ANY WARRANTY.
#

USAGE_TEXT="Usage: crm_standby <command> [options]

Common options:
 --help                 Display this text, then exit
 --version              Display version information, then exit
 -V, --verbose          Specify multiple times to increase debug output
 -q, --quiet            Print only the standby status (if querying)

Commands:
 -G, --query            Query the current value of standby mode (on/off)
 -v, --update=VALUE     Update the value of standby mode (on/off)
 -D, --delete           Let standby mode use default value

Additional Options:
 -N, --node=NODE        Operate on the named node instead of the current one
 -l, --lifetime=VALUE   Until when should the setting take effect
                        (valid values: reboot, forever)
 -i, --id=VALUE         (Advanced) XML ID used to identify standby attribute"

HELP_TEXT="crm_standby - Query, enable, or disable standby mode for a node

Nodes in standby mode may not host cluster resources.

$USAGE_TEXT
"

exit_usage() {
    if [ $# -gt 0 ]; then
        echo "error:" "$@" >&2
    fi
    echo
    echo "$USAGE_TEXT"
    exit 1
}

op=""
options=""
lifetime=0
target=""

SHORTOPTS_DEPRECATED="U:Q"
LONGOPTS_DEPRECATED="uname:,get-value,delete-attr,attr-value:,attr-id:"
SHORTOPTS="VqGv:DN:l:i:"
LONGOPTS="help,version,verbose,quiet,query,update:,delete,node:,lifetime:,id:"

TEMP=$(@GETOPT_PATH@ -o ${SHORTOPTS}${SHORTOPTS_DEPRECATED} \
    --long ${LONGOPTS},${LONGOPTS_DEPRECATED} \
    -n crm_standby -- "$@")
if [ $? -ne 0 ]; then
    exit_usage
fi

eval set -- "$TEMP" # Quotes around $TEMP are essential

while true ; do
    case "$1" in
        --help)
            echo "$HELP_TEXT"
            exit 0
            ;;
        --version)
            crm_attribute --version
            exit 0
            ;;
        -q|--quiet|-V|--verbose|-Q)
            options="$options $1"
            shift
            ;;
        -N|--node|-U|--uname)
            target="$2"
            shift
            shift
            ;;
        -G|--query|--get-value)
            options="$options --query"
            op=g
            shift
            ;;
        -v|--update|--attr-value)
            options="$options --update $2"
            op=u
            shift
            shift
            ;;
        -D|--delete|--delete-attr)
            options="$options --delete"
            op=d
            shift
            ;;
        -l|--lifetime)
            options="$options --lifetime $2"
            lifetime=1
            shift
            shift
            ;;
        -i|--id|--attr-id)
            options="$options --id $2"
            shift
            shift
            ;;
        --)
            shift
            break
            ;;
        *)
            exit_usage "unknown option '$1'"
            ;;
    esac
done

# It's important to call cluster commands only after arguments are processed,
# so --version and --help work without problems even if those commands don't.
if [ "$target" = "" ]; then
    target=$(crm_node -n)
fi

options="-N $target -n standby $options"
if [ x$op = x ]; then
    options="$options -G"; op=g
fi

# If the user didn't explicitly specify a lifetime ...
if [ $lifetime -eq 0 ]; then
    case $op in
        g)
            # For query, report the forever entry if one exists, otherwise
            # report the reboot entry if one exists, otherwise report off.
            crm_attribute $options -l forever >/dev/null 2>&1
            if [ $? -eq 0 ]; then
                options="$options -l forever"
            else
                options="$options -l reboot -d off"
            fi
            ;;
        u)
            # For update, default to updating the forever entry.
            options="$options -l forever"
            ;;
        d)
            # For delete, default to deleting both forever and reboot entries.
            crm_attribute $options -l forever
            crm_attribute $options -l reboot
            exit 0
            ;;
    esac
fi

crm_attribute $options