Created
December 16, 2013 14:39
-
-
Save vholer/7987969 to your computer and use it in GitHub Desktop.
On RHCS cluster migrate all local services to another node, update operating system and reboot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# On RHCS cluster migrate all local services to another | |
# node, update operating system and reboot | |
# | |
NODES=`cman_tool nodes -F type,name | awk '$1 == "M" { print $2 }'` | |
if [ `echo "${NODES}" | wc -w` -le 1 ]; then | |
echo "Not enough nodes ($NODES), at least 2 active needed" | |
exit 1 | |
fi | |
LOCAL_NODE=`cman_tool status | awk -F': ' '$1 ~ /^Node name/ { print $2 }'` | |
if [ "x${LOCAL_NODE}" == 'x' ]; then | |
echo "Unknown local node cluster name" | |
exit 1 | |
fi | |
OTHER_NODE=`echo "$NODES" | grep -v "${LOCAL_NODE}"` | |
if [ "x${OTHER_NODE}" == 'x' ]; then | |
echo "Failed to filter other node name" | |
exit 1 | |
fi | |
LOCAL_SERVICES=`clustat | awk "\\$2 ~ /$LOCAL_NODE/ { print \\$1 }"` | |
if [ "x${LOCAL_SERVICES}" == 'x' ]; then | |
echo "No local services to migrate" | |
exit 1 | |
fi | |
# summary | |
echo "Cluster nodes: "${NODES} | |
echo "Local node: "${LOCAL_NODE} | |
echo "Candidate node: "${OTHER_NODE} | |
echo "Services: "${LOCAL_SERVICES} | |
echo | |
# migrate all local services to first other node | |
# 1. try live migration | |
# 2. try cold migration (stop/start) | |
# if no migration succeeds, fail! | |
for S in $LOCAL_SERVICES; do | |
clusvcadm -M "${S}" -m "${OTHER_NODE}" || \ | |
clusvcadm -r "${S}" -m "${OTHER_NODE}" || \ | |
exit | |
done | |
echo "... done" | |
if yum update; then | |
shutdown -r +5 "System update done, rebooting machine" | |
( | |
for S in rgmanager sanlock gfs2 clvmd; do | |
service ${S} stop | |
done | |
service cman stop remove | |
) & | |
else | |
echo 'Update failed!' | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment