bash - Restart a bunch of servers, keeping only a few down during the restart -
consider following script:
for host in $(get-all-hosts) (restart-server $host; wait-for-server-to-come-up $host) & done as might guess, restart-server restarts server , command wait-for-server-to-come-up blocks until server (e.g., grep -m 1 'server up' <(tail -f /path/to/log)).
this script restarts servers simultaneously. i'm curious what's simplest way modify script stop after fixed number of servers, , wait 1 server come before proceeding next restart maximum of, say, 4 servers down @ given time. 1 way know of doing restart in chunks of 4 , wait on of pids in each chunk, i'm hoping it's not hard smarter.
some scratch work toward solution:
second try, using ideas dennis's link. ideal vanilla bash solution:
mkfifo mfifo exec 3<>mfifo echo >&3 echo >&3 echo >&3 host in $(get-all-hosts) read (restart-server $host; wait-for-server-to-come-up $host; echo >&3) & done <&3 my biggest remaining complaint solution assumes there isn't named queue called mfifo that's in use. other that, haven't seen problems, , works expected far can tell.
xargs has parallelism feature similar parallel:
echo $(get-all-hosts) | tr ' ' '\n' | xargs -p 4 -n 1 ./blocking-restart ..where blocking-restart expected take name of single server, restart , wait until it's finished. note tr puts each host on own line, xargs expects.
Comments
Post a Comment