diff options
Diffstat (limited to 'bin/switch_wfs_os')
-rwxr-xr-x | bin/switch_wfs_os | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/bin/switch_wfs_os b/bin/switch_wfs_os index f03e91b..c941a4c 100755 --- a/bin/switch_wfs_os +++ b/bin/switch_wfs_os @@ -18,12 +18,15 @@ reboot_cmd="" hostnames_arch=( "wfs-master" "wfs-node1" "wfs-node2" ) hostnames_ubuntu=( "wfs" "n101" "n102" ) +host=$(hostname) if [ $UID -ne 0 ]; then echo "You need to be root or call this script with sudo to do this." exit 1 fi +echo "Host: $host." + if [ -f /etc/arch-release ]; then os_current=$os_new syslinux_location=$syslinux_location_arch @@ -44,9 +47,14 @@ else fi if [ "$os_set" == "${os_new}" ] && [ "$os_current" == "${os_new}" ]; then - if [[ " ${hostnames_arch[@]} " =~ " $(hostname) " ]]; then + if [[ " ${hostnames_arch[@]} " =~ " $host " ]]; then echo "Switching to: $os_old" sed -i 's/^DEFAULT .*/DEFAULT '${os_old}'/' $syslinux_location + echo "Calling script on nodes:" + if [[ "${hostnames_arch[0]}" == "$host" ]]; then + ssh -t wfs${hostnames_arch[1]} "/usr/bin/sudo bin/$(basename $0)" + ssh -t wfs${hostnames_arch[2]} "/usr/bin/sudo bin/$(basename $0)" + fi else echo "Error: Script is not supposed to be running on this host!" echo "$(hostname) is not one of the following: ${hostnames_arch[@]}" @@ -54,12 +62,17 @@ if [ "$os_set" == "${os_new}" ] && [ "$os_current" == "${os_new}" ]; then exit 1 fi elif [ "$os_set" == "${os_old}" ] && [ "$os_current" == "${os_old}" ]; then - if [[ " ${hostnames_ubuntu[@]} " =~ " $(hostname) " ]]; then + if [[ " ${hostnames_ubuntu[@]} " =~ " $host " ]]; then echo "Switching to: $os_new" sed -i 's/^DEFAULT .*/DEFAULT '${os_new}'/' $syslinux_location + echo "Calling script on nodes:" + if [[ "${hostnames_ubuntu[0]}" == "$host" ]]; then + ssh -t wfs${hostnames_ubuntu[1]} "/usr/bin/sudo /usr/local/bin/$(basename $0)" + ssh -t wfs${hostnames_ubuntu[2]} "/usr/bin/sudo /usr/local/bin/$(basename $0)" + fi else echo "Error: Script is not supposed to be running on this host!" - echo "$(hostname) is not one of the following: ${hostnames_ubuntu[@]}" + echo "$host is not one of the following: ${hostnames_ubuntu[@]}" echo "Exiting." exit 1 fi @@ -70,6 +83,7 @@ else exit 1 fi + echo "Rebooting." $reboot_cmd |