aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Runge <dave@sleepmap.de>2016-01-11 15:00:17 +0100
committerDavid Runge <dave@sleepmap.de>2016-01-11 15:00:17 +0100
commita5521552416b29ce81e820c00ffd0f80e9397c81 (patch)
tree70dc7b4263297070c303c25148e857cc5f55018e
parentb4fc2d2e268a79e57c5613edfe8e3e281681c58a (diff)
downloaddotfiles-a5521552416b29ce81e820c00ffd0f80e9397c81.tar.gz
dotfiles-a5521552416b29ce81e820c00ffd0f80e9397c81.tar.bz2
dotfiles-a5521552416b29ce81e820c00ffd0f80e9397c81.tar.xz
dotfiles-a5521552416b29ce81e820c00ffd0f80e9397c81.zip
bin/switch_wfs_os: Adding feature to switch the OS on the nodes. This requires for the hostnames to resolve and the user wfs being able to sudo without password.
-rwxr-xr-xbin/switch_wfs_os20
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