-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinitialize_instance
executable file
·126 lines (94 loc) · 3.72 KB
/
initialize_instance
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/usr/bin/env bash
# 2014, [email protected]
lockdir=/tmp/initialize_instance.lock
if mkdir "$lockdir"; then
#echo >&2 "successfully acquired lock"
# Remove lockdir when the script finishes, or when it receives a signal
trap 'rm -rf "$lockdir"' 0 # remove directory when script finishes
trap "exit 2" 1 2 3 15 # terminate script when receiving signal
# Optionally create temporary files in this directory, because
# they will be removed automatically:
tmpfile=$lockdir/filelist
else
echo >&2 "cannot acquire lock, giving up on $lockdir"
exit 0
fi
set -x
# Deprecation warnings for obsolete Heat parameters:
if [ -n "$additional_script" ]; then
set +x
echo "WARNING: You are using the deprecated additional_script parameter which is no longer effective. Place scripts in your project-config repository's bootstrap.d/ instead."
set -x
fi
# Set DEBIAN_FRONTEND appropriately to avoid garbled dkpg output in log file.
export DEBIAN_FRONTEND=noninteractive
# Use SSH wrapper for git to avoid being deadlocked by password prompts
export GIT_SSH=ssh-autostrap
# Repositories:
: ${config_repo:=https://github.com/autostrap/project-config.git}
export config_repo
: ${config_branch:=master}
export config_branch
: ${global_config_repo:=https://github.com/autostrap/global-config.git}
export global_config_repo
: ${global_config_branch:=master}
export global_config_branch
: ${repodeploy_repo:=https://github.com/autostrap/puppet-repodeploy.git}
export repodeploy_repo
: ${repodeploy_branch:=master}
export repodeploy_branch
: ${openstackfacts_repo:=https://github.com/autostrap/puppet-openstackfacts.git}
export openstackfacts_repo
: ${openstackfacts_branch:=master}
export openstackfacts_branch
# Directories:
: ${scripts_dir:=/opt/scripts/autostrap}
export scripts_dir
: ${config_dir:=/opt/config/project}
export config_dir
: ${global_config_dir:=/opt/config/autostrap}
export global_config_dir
: ${bootstrap_dir:=${scripts_dir}/bootstrap.d} # Bootstrapping scripts supplied by Autostrap
export bootstrap_dir
: ${additional_dir:=${config_dir}/bootstrap.d} # Bootstrapping scripts supplied by project.
export additional_dir
: ${stage_dir:=/opt/scripts/stages} # All Bootstrapping scripts are symlinked to this directory and executed in order.
export stage_dir
: ${repos_bootstrap:=/etc/puppet/hieradata/repos_params.yaml} # puppet-repodeploy configuration for repositories from environment.
export repos_bootstrap
# Additional configuration repositories:
: ${additional_config:=''}
export additional_config
# Extra Hiera hierarchy entries to append after override.yaml
: ${extra_overrides:=''}
export extra_overrides
export bootstrap_stage=stage1
name=$(hostname -s)
export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/sbin:/usr/local/bin:${scripts_dir}/bin
# We'll need this early on to store repodeploy configuration for repositories
# specified through Heat paramaters.
mkdir -p /etc/puppet/hieradata
echo 'repodeploy::repos:' >> "$repos_bootstrap"
for cmd in setup_repos setup_stage_dir
do
if ! launch_logged $cmd; then
exit 1
fi
done
bootstrap_stage=stage2
for cmd in ${stage_dir}/*
do
if ! launch_logged $cmd; then
exit 1
fi
done
# FIXME: resetting bootstrap_stage here is required to maintain compatibility
# with the scloud utility from syseleven.cloudutils since this uses a stage
# finished message for 'initialize_instance' as indicator of bootstrapping
# having run its course. Everywhere else we use 'stage1' and 'stage2' which is
# more closely aligned with the Autostrap documentation's Life of a Stack
# section. If scloud is patched to recognize the conclusion of 'stage2' as
# well, this should be removed.
bootstrap_stage=initialize_instance log_stage_finished
env -u deploy_key
echo "finished $0"