summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Klishin <michael@novemberain.com>2015-11-09 21:02:54 +0300
committerMichael Klishin <michael@novemberain.com>2015-11-09 21:02:54 +0300
commit1d0606968856bb512f7ff065fb0c003d45607991 (patch)
tree298ac16198e5771335cbac772750e514ceee3ba2
parent19905b328e5f0f67949ba6cafcdaf074eaa54cb5 (diff)
parente0f90d8f4ab908c49f058de7123a28ad3590e770 (diff)
downloadrabbitmq-server-git-1d0606968856bb512f7ff065fb0c003d45607991.tar.gz
Merge pull request #411 from binarin/rabbitmq-server-ocf-idempotent-cookie
Don't update cookie on every run of HA OCF script
-rwxr-xr-xscripts/rabbitmq-server-ha.ocf17
1 files changed, 15 insertions, 2 deletions
diff --git a/scripts/rabbitmq-server-ha.ocf b/scripts/rabbitmq-server-ha.ocf
index 632c354a43..42e5332367 100755
--- a/scripts/rabbitmq-server-ha.ocf
+++ b/scripts/rabbitmq-server-ha.ocf
@@ -573,9 +573,22 @@ check_need_join_to() {
# Update erlang cookie, if it has been specified
update_cookie() {
+ local cookie_file_content
if [ "${OCF_RESKEY_erlang_cookie}" != 'false' ] ; then
- echo "${OCF_RESKEY_erlang_cookie}" > "${OCF_RESKEY_erlang_cookie_file}" && \
- chown ${OCF_RESKEY_username}:${OCF_RESKEY_groupname} "${OCF_RESKEY_erlang_cookie_file}" && \
+ if [ -f "${OCF_RESKEY_erlang_cookie_file}" ]; then
+ # First line of cookie file without newline
+ cookie_file_content=$(head -n1 "${OCF_RESKEY_erlang_cookie_file}" | perl -pe chomp)
+ fi
+ # As there is a brief period of time when the file is empty
+ # (shell redirection has already opened and truncated file,
+ # and echo hasn't finished its job), we are doing this write
+ # only when cookie has changed.
+ if [ "${OCF_RESKEY_erlang_cookie}" != "${cookie_file_content}" ]; then
+ echo "${OCF_RESKEY_erlang_cookie}" > "${OCF_RESKEY_erlang_cookie_file}"
+ fi
+ # And this are idempotent operations, so we don't have to
+ # check any preconditions for running them.
+ chown ${OCF_RESKEY_username}:${OCF_RESKEY_groupname} "${OCF_RESKEY_erlang_cookie_file}"
chmod 600 "${OCF_RESKEY_erlang_cookie_file}"
fi
return $OCF_SUCCESS