#!/bin/sh #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~# # remotehost-sync-setup # - Set variables for PORT/DELAY/DIR # - create directory for state_messages # - run web server used for sharing/checking state_messages #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~# function remotehost-sync-setup() { echo "$FUNCNAME $@" local RETURNCODE=0 export IPA_SYNC_PORT=8907 export IPA_SYNC_DELAY=30 export IPA_SYNC_DIR=/tmp/ipasync mkdir -p $IPA_SYNC_DIR pushd $IPA_SYNC_DIR if [ $(python --version 2>&1|awk '{print $2}'|cut -f1 -d.) -eq 2 ]; then IPA_SYNC_WEBMOD=SimpleHTTPServer; else IPA_SYNC_WEBMOD=http.server; fi ps -ef|grep "Simple[H]TTPServer.*${IPA_SYNC_PORT}" if [ $? -eq 1 ]; then echo "remotehost-sync web server not running on $IPA_SYNC_PORT. starting" python -m $IPA_SYNC_WEBMOD $IPA_SYNC_PORT > /var/log/python_web_server.log 2>&1 & else echo "remotehost-sync web server running on $IPA_SYNC_PORT. Using that one." fi if [ $? -eq 0 ]; then export IPA_SYNC_PID=$(ps -ef|grep "py[t]hon.*$IPA_SYNC_PORT"|awk '{print $2}') else echo "[ FAIL ] :: WEB SERVER FAILED TO START!!!!!!!!!!!!!!!" export IPA_SYNC_PID="SERVERFAILED" RETURNCODE=1 fi popd return $RETURNCODE } #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~# # remotehost-sync-block -s [ ...] # - block actions on server where it is run until sets # expected #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~# function remotehost-sync-block() { echo "$FUNCNAME $@" export IPA_SYNC_PORT=8907 export IPA_SYNC_DELAY=30 export IPA_SYNC_DIR=/tmp/ipasync local DASH_S=$1 local MESSAGE=$2 local HOSTS="$3 $4 $5 $6 $7 $8 $9" local HOST="" ps -ef|grep "${IPA_SYNC_PID}.*Simple[H]TTPServer.*${IPA_SYNC_PORT}" if [ $? -eq 1 ]; then echo "ipa-sync web server not running on $IPA_SYNC_PORT. starting" remotehost-sync-setup fi while true; do for HOST in $HOSTS; do #echo "wget -O/dev/null http://$HOST:$IPA_SYNC_PORT/$MESSAGE" wget -qO/dev/null http://$HOST:$IPA_SYNC_PORT/$MESSAGE if [ $? -eq 0 ]; then HOSTS="$(echo $HOSTS|sed s/$HOST//|sed 's/ / /g')" fi done if [ -n "$HOSTS" ]; then sleep $IPA_SYNC_DELAY else break fi done } #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~# # remotehost-sync-set -s [-m ] # - set on localhost (even if ) # - unblocks servers using remotehost-sync-block waiting on #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~# function remotehost-sync-set() { echo "$FUNCNAME $@" export IPA_SYNC_PORT=8907 export IPA_SYNC_DELAY=30 export IPA_SYNC_DIR=/tmp/ipasync local DASH_S=$1 local MESSAGE=$2 ps -ef|grep "${IPA_SYNC_PID}.*Simple[H]TTPServer.*${IPA_SYNC_PORT}" if [ $? -eq 1 ]; then echo "ipa-sync web server not running on $IPA_SYNC_PORT. starting" remotehost-sync-setup fi touch "$IPA_SYNC_DIR/$MESSAGE" }