forked from riptano/ComboAMI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ds1_launcher.py
executable file
·171 lines (137 loc) · 5.75 KB
/
ds1_launcher.py
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#!/usr/bin/env python
### Script provided by DataStax.
import os
import subprocess
import shlex
import time
import urllib2
import logger
import conf
# Temporary fix until next rebake
def fix_profile():
# Setup a link to the motd script that is provided in the git repository
file_to_open = '/home/ubuntu/.profile'
logger.exe('sudo chmod 777 ' + file_to_open)
with open(file_to_open, 'r+') as f:
profile = f.read()
f.seek(0)
f.write(profile.replace('jdk1.6.0_31', 'jdk1.6.0_38'))
logger.exe('sudo chmod 644 ' + file_to_open)
def initial_configurations():
# Begin configuration this is only run once in Public Packages
if conf.get_config("AMI", "CurrentStatus") != "Complete!":
# Configure DataStax variables
try:
import ds2_configure
ds2_configure.run()
except:
conf.set_config("AMI", "Error", "Exception seen in %s. Please check ~/datastax_ami/ami.log for more info." % 'ds1_launcher.py')
logger.exception('ds1_launcher.py')
# Set ulimit hard limits
logger.pipe('echo "* soft nofile 32768"', 'sudo tee -a /etc/security/limits.conf')
logger.pipe('echo "* hard nofile 32768"', 'sudo tee -a /etc/security/limits.conf')
logger.pipe('echo "root soft nofile 32768"', 'sudo tee -a /etc/security/limits.conf')
logger.pipe('echo "root hard nofile 32768"', 'sudo tee -a /etc/security/limits.conf')
# Change permission back to being ubuntu's and cassandra's
logger.exe('sudo chown -hR ubuntu:ubuntu /home/ubuntu')
logger.exe('sudo chown -hR cassandra:cassandra /raid0/cassandra', False)
logger.exe('sudo chown -hR cassandra:cassandra /mnt/cassandra', False)
else:
logger.info('Skipping initial configurations.')
def write_bin_tools():
with open('/usr/bin/datastax_support', 'w') as f:
f.write("""#!/usr/bin/env python\nprint '''DataStax Support Links:
Cassandra Cluster Launcher:
https://github.com/joaquincasares/cassandralauncher
Documentation:
http://www.datastax.com/docs
AMI:
http://www.datastax.com/ami
Cassandra client libraries:
http://www.datastax.com/download/clientdrivers
Support Forums:
http://www.datastax.com/support-forums
For quick support, visit:
IRC: #cassandra channel on irc.freenode.net
'''
""")
with open('/usr/bin/datastax_demos', 'w') as f:
f.write("""#!/usr/bin/env python\nprint '''DataStax Demo Links:
Portfolio (Hive) Demo:
http://www.datastax.com/demos/portfolio
Pig Demo:
http://www.datastax.com/demos/pig
Wikipedia (Solr) Demo:
http://www.datastax.com/demos/wikipedia
Logging (Solr) Demo:
http://www.datastax.com/demos/logging
Sqoop Demo:
http://www.datastax.com/demos/sqoop
'''
""")
with open('/usr/bin/datastax_tools', 'w') as f:
f.write("""#!/usr/bin/env python\nprint '''Installed DSE/C Tools:
Nodetool:
nodetool --help
DSEtool:
dsetool --help
Cli:
cassandra-cli -h `hostname`
CQL Shell:
cqlsh
Hive:
dse hive (on Analytic nodes)
Pig:
dse pig (on Analytic nodes)
'''
""")
os.chmod('/usr/bin/datastax_support', 0755)
os.chmod('/usr/bin/datastax_demos', 0755)
os.chmod('/usr/bin/datastax_tools', 0755)
def restart_tasks():
logger.info("AMI Type: " + str(conf.get_config("AMI", "Type")))
# Create /raid0
logger.exe('sudo mount -a')
# Disable swap
logger.exe('sudo swapoff --all')
# Ensure the correct blockdev readahead since this sometimes resets after restarts
if conf.get_config('AMI', 'raid_readahead'):
logger.exe('sudo blockdev --setra %s /dev/md0' % (conf.get_config('AMI', 'raid_readahead')), expectError=True)
def wait_for_seed():
# Wait for the seed node to come online
req = urllib2.Request('http://instance-data/latest/meta-data/local-ipv4')
internalip = urllib2.urlopen(req).read()
if internalip != conf.get_config("AMI", "LeadingSeed"):
logger.info("Waiting for seed node to come online...")
nodetoolStatement = "nodetool -h " + conf.get_config("AMI", "LeadingSeed") + " ring"
logger.info(nodetoolStatement)
while True:
nodetool_out = subprocess.Popen(shlex.split(nodetoolStatement), stderr=subprocess.PIPE, stdout=subprocess.PIPE).stdout.read()
if (nodetool_out.lower().find("error") == -1 and nodetool_out.lower().find("up") and len(nodetool_out) > 0):
logger.info("Seed node now online!")
time.sleep(5)
break
time.sleep(5)
logger.info("Retrying seed node...")
def launch_opscenter():
logger.info('Starting a background process to start OpsCenter after a given delay...')
subprocess.Popen(shlex.split('sudo -u ubuntu python /home/ubuntu/datastax_ami/ds3_after_init.py &'))
def start_services():
# Wait for system setup changes to settle
time.sleep(5)
# Actually start the application
if conf.get_config("AMI", "Type") == "Community" or conf.get_config("AMI", "Type") == "False":
logger.info('Starting DataStax Community...')
logger.exe('sudo service cassandra restart')
elif conf.get_config("AMI", "Type") == "Enterprise":
logger.info('Starting DataStax Enterprise...')
logger.exe('sudo service dse restart')
def run():
fix_profile()
initial_configurations()
write_bin_tools()
restart_tasks()
if conf.get_config("AMI", "LeadingSeed"):
wait_for_seed()
launch_opscenter()
start_services()