In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "what are the convenient functions of OCF". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what are the convenient functions of OCF"?
7 convenient functions
7.1Log: ocf_log
The resource agent should use the ocf_log function for logging. The calling method is as follows:
The following log levels are supported:
Debug-debugging message. Most logging configurations do not use this level by default.
Info-information about the behavior and status of resource agents
Warn-warning. Some unexpected behavior, but not an irrecoverable error
Err-error. These logs appear before the resource agent exit with a certain error code
Crit-critical error. Thought there was an err level. The crit level is rarely used, and the departure resource agent exits with a certain error code.
7.2 check binaries: have_binary and check_binary
Resource agents may need to test the availability of specific executables. You can use the have_binary function:
one
two
three
If! Have_binary frobnicate; then
Ocf_log warn "Missing frobnicate binary, frobnication disabled!"
Fi
If missing binaries is a fatal error, the check_binary function should be called in advance:
one
Check_binary frobnicate
Using check_binary is a convenient way to check that the file exists (and executable), and exit with $OCF_ERR_INSTALLED if it is not found or cannot be executed.
Note: have_binary and check_binary will look for the specified binaries in the directory defined by $PATH. It is recommended to do full-path checking. In a distributed environment, changes in user policies will change the file path.
7.3 execute the command and collect the output: ocf_run
Whenever you need to execute a command and get its output, you can use the ocf_run function, as in the following example:
one
Ocf_run "frobnicate-- spam=eggs" | | exit $OCF_ERR_GENERIC
With the above command, the resource agent calls frobnicate-- spam=eggs and captures its output and exit code. If the exit code is non-zero (representing an error), ocf_run logs the output to the log at the err level, and the resource agent then exits. If the exit code is 0 (indicating success), the output is logged at the info level.
If the resource agent wants to ignore the output that was successfully executed, you can use the-Q parameter. In the following example, ocf_run will only import the execution output with a non-zero exit code into the log.
one
Ocf_run-Q "frobnicate-- spam=eggs" | | exit $OCF_ERR_GENERIC
Finally, if the resource agent wants to record execution results with non-zero return codes at different log levels (non-err), you can use the-info or-warn parameter:
one
Ocf_run-warn "frobnicate-- spam=eggs"
7.4 Lock: ocf_take_lock and ocf_release_lock_on_exit
Occasionally, different resources of the same type cannot run in parallel according to the cluster configuration. Resource agents need to ensure that they are not parallel on the same machine:
one
two
three
four
five
six
seven
eight
LOCKFILE=$ {HA_RSCTMP} / foobar
Ocf_release_lock_on_exit $LOCKFILE
Foobar_start () {
...
Ocf_take_lock $LOCKFILE
...
}
Ocf_take_lock attempts to get the specified $LOCKFILE. When it is not available, it sleep a random time between 0 and 1 second and try again. Ocf_release_lock_on_exit releases the lock file when the resource agent exits.
7.5 numerical detection
For parameter detection, this function can be used to detect whether a value is a number. Examples are as follows:
one
two
three
four
five
six
seven
eight
nine
ten
LOCKFILE=$ {HA_RSCTMP} / foobar
Ocf_release_lock_on_exit $LOCKFILE
Foobar_validate_all () {
If! Ocf_is_decimal $OCF_RESKEY_eggs; then
Ocf_log err "eggs is not numeric!"
Exit $OCF_ERR_CONFIGURED
Fi
...
}
7.6 boolean value detection
When the resource agent defines a parameter of type boolean, the user will specify the parameter as 0max 1, true/false, or on/off. In the resource agent, it is troublesome to detect these values, so it is convenient to use the ocf_is_true function:
one
two
three
If ocf_is_true $OCF_RESKEY_superfrobnicate; then
Ocf_run "frobnicate-super"
Fi
Note: ocf_is_true cannot be used with empty or non-existent variables. It always returns the exit code 1, which is equivalent to false.
7.7 pseudo resources: ha_pseudo_resource
Pseudo resources are resource agents that do not actually start and stop as runnable processes do. They simply execute a single behavior and somehow track whether the behavior is executed or not. The portblock resource agent is an example of this.
The resource agent of a pseudo resource can use ha_pseudo_resource, which opens the label to save the state of the resource with Shi Yonghong tracking file (tracking file). If foobar is a resource proxy for a resource, its start should behave like this:
one
two
three
four
five
six
seven
eight
nine
ten
eleven
twelve
thirteen
fourteen
fifteen
sixteen
seventeen
eighteen
nineteen
twenty
twenty-one
twenty-two
twenty-three
twenty-four
twenty-five
twenty-six
Foobar_start () {
# exit immediately if configuration is not valid
Foobar_validate_all | | exit $?
# if resource is already running, bail out early
If foobar_monitor; then
Ocf_log info "Resource is already running"
Return $OCF_SUCCESS
Fi
# start the pseudo resource
Ha_pseudo_resource ${OCF_RESOURCE_INSTANCE} start
# After the resource has been started, check whether it started up
# correctly. If the resource starts asynchronously, the agent may
# spin on the monitor function here-if the resource does not
# start up within the defined timeout, the cluster manager will
# consider the start action failed
While! Foobar_monitor; do
Ocf_log debug "Resource has not started yet, waiting"
Sleep 1
Done
# only return $OCF_SUCCESS if _ everything_ succeeded as expected
Return $OCF_SUCCESS
}
Thank you for your reading, these are the contents of "what are the convenient functions of OCF". After the study of this article, I believe you have a deeper understanding of what the convenient functions of OCF have, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.