This repository has been archived by the owner on Oct 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 50
/
startIndex.py
executable file
·135 lines (107 loc) · 4.02 KB
/
startIndex.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
#!/usr/bin/python
import os
import sys
import subprocess
import simplejson as json
# prevent everyone from importing
if __name__ != "__main__":
print >> sys.stderr, 'this script is not meant to be imported. Exiting'
sys.exit(1)
# ok, good to go
# parse the environment
if os.path.exists('/data/env.name'):
env = open('/data/env.name').readline().rstrip("\n")
else:
env = 'PROD'
print >>sys.stderr, 'WARNING, the instance does not have a /data/env.name. USING PROD AS ENV'
# parse json
config_file = sys.argv[1]
config = json.load(open(config_file))
# setup logging files
log_dir = 'logs'
log_file = "%s/indextank.log" % log_dir
gc_log_file = "%s/gc.log" % log_dir
os.makedirs(log_dir)
pid_file = open('pid', 'w')
# setup index directory
index_dir = 'index'
os.makedirs(index_dir)
# first, generate vm args
vm_args = config.get('vmargs',[])
vm_args.append('-cp')
vm_args.append('.:lib/indextank-trunk.jar:lib/indextank-trunk-deps.jar')
vm_args.append('-verbose:gc')
vm_args.append('-Xloggc:%s'%gc_log_file)
vm_args.append('-XX:+PrintGCTimeStamps')
vm_args.append("-XX:+UseConcMarkSweepGC")
vm_args.append("-XX:+UseParNewGC")
vm_args.append("-Dorg.apache.lucene.FSDirectory.class=org.apache.lucene.store.MMapDirectory")
vm_args.append("-Dapp=INDEX-ENGINE-%s"%config['index_code'])
vm_args.append("-Xmx%sM"%config['xmx'])
# a list of possible IndexEngine params
app_params_mapping = {}
app_params_mapping['base_port'] = "--port"
app_params_mapping['index_code'] = "--index-code"
app_params_mapping['allow_snippets'] = "--snippets" # we may remove this line
app_params_mapping['allows_snippets'] = "--snippets"
app_params_mapping['snippets'] = "--snippets"
app_params_mapping['allow_facets'] = "--facets" # we may remove this line
app_params_mapping['allows_facets'] = "--facets"
app_params_mapping['max_variables'] = "--boosts"
app_params_mapping['autocomplete'] = "--suggest"
app_params_mapping['didyoumean'] = "--didyoumean"
app_params_mapping['rti_size'] = "--rti-size"
app_params_mapping['functions'] = "--functions"
app_params_mapping['storage'] = "--storage"
app_params_mapping['bdb_cache'] = "--bdb-cache"
def adapt_config_kv(key, value, json_config):
if key == '--suggest':
if value:
value = json_config.get('autocomplete_type', 'documents')
else:
key, value = '', ''
if key == '--facets':
if value:
value = ''
else:
key, value = '', ''
if key == '--snippets':
if value:
value = ''
else:
key, value = '', ''
if key == '--didyoumean' and value == True:
value = "" # didyoumean does not take arguments
if key == '--functions':
value = "|".join("%s:%s"%(k,v) for k,v in value.iteritems())
return key, value
# now, app params
app_params = {}
app_params['--conf-file'] = config_file
app_params.update(adapt_config_kv(app_params_mapping.get(k),v, config) for k,v in config.iteritems() if k in app_params_mapping)
# dependency checking
# --didyoumean needs --suggest documents
if '--didyoumean' in app_params:
app_params['--suggest'] == 'documents'
# just make sure to use index dir
app_params['--dir'] = index_dir
app_params['--environment-prefix'] = config.get('environment',env) # let configuration override env.
app_params['--recover'] = '' # recover does not take arguments
# We want to use everything 64 bits because mmap doesn't like things it can't map to 31 bits.
java = 'java'
os.putenv('LD_LIBRARY_PATH','lib/berkeleydb_libs_64/')
full_args = ['nohup', java]
full_args.extend(vm_args)
full_args.append('com.flaptor.indextank.index.IndexEngine')
for k,v in app_params.iteritems():
full_args.extend((k,str(v)))
log_file = open(log_file, 'w')
print >>log_file, ""
print >>log_file, ""
print >>log_file, "="*80
print >>log_file, "%s STARTING JVM %s" % ( "="*33, "="*33)
print >>log_file, "="*80
print >>log_file, "== %s ==" % full_args
print >>log_file, "="*80
pid = subprocess.Popen(full_args, stderr=log_file, stdout=log_file, close_fds=True)
print >>pid_file, pid.pid