-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuserdata.sh
More file actions
137 lines (118 loc) · 3.63 KB
/
userdata.sh
File metadata and controls
137 lines (118 loc) · 3.63 KB
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
127
128
129
130
131
132
133
134
135
136
137
#!/bin/bash -v
NAME=blah
MYIP=$(curl http://169.254.169.254/latest/meta-data/local-ipv4/)
ENVIRONMENT=blah
MANAGEMENT_CODE=001
NAT_CODE=002
JENKINS_CODE=004
MONITORING_CODE=005
GRAPHITE_CODE=006
COREDB_CODE=007
BASTION_CODE=007
CODEX_CODE=011
STREAMING_SERVER_CODE=012
AFP_CODE=013
VFP_CODE=014
REEF_CODE=015
CLIP_EXTRACTOR_CODE=016
ORCA_CODE=021
ORCADB_CODE=022
ORCACACHE_CODE=023
SOLR_CODE=024
ORCASTORAGE_CODE=025
ORCAUVC_CODE=026
sudo apt-get update
#Update hostname
sudo hostname $NAME
sudo echo $NAME > /tmp/hostname
sudo cp -rp /tmp/hostname /etc/hostname
#Install s3cmd and chef-client
sudo apt-get install -y s3cmd
sudo curl -L https://www.opscode.com/chef/install.sh | sudo bash
sudo mkdir -p /etc/chef/
# write first-boot.json
if [ "${ENVIRONMENT}" = "ni" ]; then
echo '{"run_list": [ "role[base]" ]}' > /etc/chef/first-boot.json
else
case $NAME in
????-*-${CODEX_CODE}-???)
echo '{"run_list": [ "role[base]", "role[codex]" ]}' > /etc/chef/first-boot.json
;;
????-*-${STREAMING_SERVER_CODE}-???)
echo '{"run_list": [ "role[base]", "role[streaming-server]" ]}' > /etc/chef/first-boot.json
;;
????-*-${ORCA_CODE}-???)
echo '{"run_list": [ "role[base]", "role[orca]" ]}' > /etc/chef/first-boot.json
;;
????-*-${ORCADB_CODE}-???)
echo '{"run_list": [ "role[base]", "role[orcadb]" ]}' > /etc/chef/first-boot.json
;;
????-*-${SOLR_CODE}-???)
echo '{"run_list": [ "role[base]", "role[solr]" ]}' > /etc/chef/first-boot.json
;;
????-*-${ORCASTORAGE_CODE}-???)
echo '{"run_list": [ "role[base]", "role[orcastorage]" ]}' > /etc/chef/first-boot.json
;;
????-*-${JENKINS_CODE}-???)
echo '{"run_list": [ "role[base]", "role[jenkins]" ]}' > /etc/chef/first-boot.json
;;
????-*-${MONITORING_CODE}-???)
echo '{"run_list": [ "role[base]", "role[monitoring]" ]}' > /etc/chef/first-boot.json
;;
????-*-${COREDB_CODE}-???)
echo '{"run_list": [ "role[base]", "role[coredb]" ]}' > /etc/chef/first-boot.json
;;
????-*-${GRAPHITE_CODE}-???)
echo '{"run_list": [ "role[base]", "role[graphite]" ]}' > /etc/chef/first-boot.json
;;
????-*-${BASTION_CODE}-???)
echo '{"run_list": [ "role[base]", "role[bastion]" ]}' > /etc/chef/first-boot.json
;;
*)
echo '{"run_list": [ "role[base]" ]}' > /etc/chef/first-boot.json
;;
esac
fi
# write .s3cfg
(
sudo cat << 'EOP'
[default]
access_key =
secret_key =
use_https = True
EOP
) > /home/ubuntu/.s3cfg
# get chef validation key from S3
sudo s3cmd -c /home/ubuntu/.s3cfg get s3://lmstaging-systems/validation-core.pem
sudo mv validation-core.pem /etc/chef/validation.pem
# write client.rb
(
sudo cat << 'EOP'
log_level :info
log_location STDOUT
chef_server_url 'https://chef.c.livemagic.internal'
validation_client_name 'chef-validator'
EOP
) > /etc/chef/client.rb
#Write Dynamic DNS keys
echo 'key "'"$ENVIRONMENT.livemagic.internal."'" {
algorithm hmac-md5;
secret "";
};' >/root/dns.key
#Add new DNS information to file
echo -e "server 10.100.100.121 \n
debug yes \n
zone $ENVIRONMENT.livemagic.internal \n" >/root/addme.dns
OLDIP=$(dig $NAME.$ENVIRONMENT.livemagic.internal. +short)
if [ ! "${OLDIP}.." = ".." ];then
echo -e "\n update delete $NAME.$ENVIRONMENT.livemagic.internal 60 A $OLDIP\n\n" >>/root/addme.dns
fi
echo -e "
update add $NAME.$ENVIRONMENT.livemagic.internal 60 A $MYIP \n
show \n
send" >> /root/addme.dns
echo "node_name \"$NAME\"" >> /etc/chef/client.rb
# Bootstrap chef
sudo nsupdate -k /root/dns.key -v /root/addme.dns
#rm -rf /root/dns.key /root/addme.dns /home/ubuntu/.s3cfg
sudo nohup /usr/bin/chef-client -j /etc/chef/first-boot.json &>/root/chef-first-run.log &