This repository has been archived by the owner on Mar 23, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 72
/
deploy
executable file
·87 lines (72 loc) · 2.53 KB
/
deploy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/bin/bash
#
# File: deploy
# Description: This script boots guest machines sequentially but provisions them in parallel.
#
# This script is derived from https://github.com/joemiller/sensu-tests/blob/master/para-vagrant.sh.
# (See our NOTICE file.)
#
MY_DIR=`echo $(cd $(dirname $0); pwd)`
. $MY_DIR/sh/common.sh
EFFECTIVE_LOG_DIR=$MY_DIR/$LOG_DIR
### CONFIGURATION: BEGIN
# Any valid 'parallel' argument will work here, such as "-P 3".
PARALLEL_OPTS="--no-notice -P 10"
### CONFIGURATION: END
check_requirements() {
which parallel &>/dev/null
if [ $? -ne 0 ]; then
error "ERROR: 'parallel' not found."
case $OS in
$OS_MAC)
puts "Install via 'brew install parallel'"
;;
$OS_LINUX)
puts "=> 1) Install via 'sudo yum install parallel' (RHEL/CentOS/Fedora)"
puts " or 'sudo apt-get install parallel' (Debian/Ubuntu)"
puts " 2) Edit /etc/parallel/config and change '--tollef' to '--gnu'"
;;
$OS_UNKNOWN)
warn "Could not detect your OS, so I can't tell you what the command is to install 'parallel'."
;;
esac
exit 1
fi
which vagrant &>/dev/null
if [ $? -ne 0 ]; then
error "ERROR: 'vagrant' not found. Install according to http://www.vagrantup.com/"
exit 1
fi
}
prepare_local_environment() {
mkdir -p $EFFECTIVE_LOG_DIR &> /dev/null
rm -f $EFFECTIVE_LOG_DIR/*.log
}
parallel_provision() {
while read box; do
echo $box
done | parallel $PARALLEL_OPTS -I"NODE" "$MY_DIR/sh/provision-node.sh NODE"
}
print_provisioning_results() {
failures=$(egrep -h '^FAILURE' $EFFECTIVE_LOG_DIR/*.log | sed -e 's/^/ /')
successes=$(egrep -h '^SUCCESS' $EFFECTIVE_LOG_DIR/*.log | sed -e 's/^/ /')
echo
error "Failures:"
echo '------------------'
error "$failures"
echo
success "Successes:"
echo '------------------'
echo "$successes"
}
### Main
check_requirements
prepare_local_environment
# Start boxes sequentially to avoid vbox explosions
puts '[Wirbelsturm] Calling 'vagrant up' to boot the boxes ...'
vagrant up --no-provision $@ || exit 2
# But run provision tasks in parallel
config_file=${WIRBELSTURM_CONFIG_FILE:-wirbelsturm.yaml}
puts "[Wirbelsturm] Beginning parallel 'vagrant provision' processes ... (it may take some time until you see further output)"
ruby -rjson -I $MY_DIR/lib -r wirbelsturm -e "include Wirbelsturm; puts nodes = JSON.parse(compile_node_catalog('$config_file'), :symbolize_names => true).keys.map{ |h| h.to_s }" | parallel_provision
print_provisioning_results