|
60 | 60 | OPENGROK_CONFIG_FILE = os.path.join(OPENGROK_BASE_DIR, "etc",
|
61 | 61 | "configuration.xml")
|
62 | 62 | OPENGROK_WEBAPPS_DIR = os.path.join(tomcat_root, "webapps")
|
| 63 | +OPENGROK_JAR = os.path.join(OPENGROK_LIB_DIR, 'opengrok.jar') |
63 | 64 |
|
64 | 65 |
|
65 | 66 | def set_url_root(logger, url_root):
|
66 | 67 | """
|
67 | 68 | Set URL root and URI based on input
|
| 69 | + :param logger: logger instance |
68 | 70 | :param url_root: input
|
69 | 71 | :return: URI and URL root
|
70 | 72 | """
|
@@ -108,6 +110,7 @@ def get_war_name(url_root):
|
108 | 110 | def deploy(logger, url_root):
|
109 | 111 | """
|
110 | 112 | Deploy the web application
|
| 113 | + :param logger: logger instance |
111 | 114 | :param url_root: web app URL root
|
112 | 115 | """
|
113 | 116 |
|
@@ -190,6 +193,7 @@ def refresh_projects(logger, uri):
|
190 | 193 | def save_config(logger, uri, config_path):
|
191 | 194 | """
|
192 | 195 | Retrieve configuration from the web app and write it to file.
|
| 196 | + :param logger: logger instance |
193 | 197 | :param uri: web app URI
|
194 | 198 | :param config_path: file path
|
195 | 199 | """
|
@@ -218,7 +222,37 @@ def merge_commands_env(commands, env):
|
218 | 222 | return commands
|
219 | 223 |
|
220 | 224 |
|
221 |
| -def syncer(logger, loglevel, uri, config_path, sync_period, numworkers, env): |
| 225 | +def indexer_no_projects(logger, uri, config_path, sync_period, |
| 226 | + extra_indexer_options): |
| 227 | + """ |
| 228 | + Project less indexer |
| 229 | + """ |
| 230 | + |
| 231 | + wait_for_tomcat(logger, uri) |
| 232 | + |
| 233 | + while True: |
| 234 | + indexer_options = ['-s', OPENGROK_SRC_ROOT, |
| 235 | + '-d', OPENGROK_DATA_ROOT, |
| 236 | + '-c', '/usr/local/bin/ctags', |
| 237 | + '--remote', 'on', |
| 238 | + '-H', |
| 239 | + '-W', config_path, |
| 240 | + '-U', uri] |
| 241 | + if extra_indexer_options: |
| 242 | + logger.debug("Adding extra indexer options: {}". |
| 243 | + format(extra_indexer_options)) |
| 244 | + indexer_options.extend(extra_indexer_options.split()) |
| 245 | + indexer = Indexer(indexer_options, logger=logger, |
| 246 | + jar=OPENGROK_JAR, doprint=True) |
| 247 | + indexer.execute() |
| 248 | + |
| 249 | + sleep_seconds = sync_period * 60 |
| 250 | + logger.info("Sleeping for {} seconds".format(sleep_seconds)) |
| 251 | + time.sleep(sleep_seconds) |
| 252 | + |
| 253 | + |
| 254 | +def project_syncer(logger, loglevel, uri, config_path, sync_period, |
| 255 | + numworkers, env): |
222 | 256 | """
|
223 | 257 | Wrapper for running opengrok-sync.
|
224 | 258 | To be run in a thread/process in the background.
|
@@ -267,22 +301,25 @@ def syncer(logger, loglevel, uri, config_path, sync_period, numworkers, env):
|
267 | 301 | time.sleep(sleep_seconds)
|
268 | 302 |
|
269 | 303 |
|
270 |
| -def create_bare_config(logger): |
| 304 | +def create_bare_config(logger, use_projects=True): |
271 | 305 | """
|
272 | 306 | Create bare configuration file with a few basic settings.
|
273 | 307 | """
|
274 | 308 |
|
275 | 309 | logger.info('Creating bare configuration in {}'.
|
276 | 310 | format(OPENGROK_CONFIG_FILE))
|
277 |
| - indexer = Indexer(['-s', OPENGROK_SRC_ROOT, |
| 311 | + indexer_options = ['-s', OPENGROK_SRC_ROOT, |
278 | 312 | '-d', OPENGROK_DATA_ROOT,
|
279 | 313 | '-c', '/usr/local/bin/ctags',
|
280 | 314 | '--remote', 'on',
|
281 |
| - '-P', '-H', |
| 315 | + '-H', |
282 | 316 | '-W', OPENGROK_CONFIG_FILE,
|
283 |
| - '--noIndex'], |
284 |
| - jar=os.path.join(OPENGROK_LIB_DIR, |
285 |
| - 'opengrok.jar'), |
| 317 | + '--noIndex'] |
| 318 | + if use_projects: |
| 319 | + indexer_options.append('-P') |
| 320 | + |
| 321 | + indexer = Indexer(indexer_options, |
| 322 | + jar=OPENGROK_JAR, |
286 | 323 | logger=logger, doprint=True)
|
287 | 324 | indexer.execute()
|
288 | 325 | ret = indexer.getretcode()
|
@@ -329,39 +366,53 @@ def main():
|
329 | 366 | setup_redirect_source(logger, url_root)
|
330 | 367 |
|
331 | 368 | env = {}
|
332 |
| - if os.environ.get('INDEXER_OPT'): |
333 |
| - env['OPENGROK_INDEXER_OPTIONAL_ARGS'] = \ |
334 |
| - os.environ.get('INDEXER_OPT') |
| 369 | + extra_indexer_options = os.environ.get('INDEXER_OPT') |
| 370 | + if extra_indexer_options: |
| 371 | + logger.info("extra indexer options: {}".format(extra_indexer_options)) |
| 372 | + env['OPENGROK_INDEXER_OPTIONAL_ARGS'] = extra_indexer_options |
335 | 373 | if os.environ.get('NOMIRROR'):
|
336 | 374 | env['OPENGROK_NO_MIRROR'] = os.environ.get('NOMIRROR')
|
337 | 375 | logger.debug('Extra environment: {}'.format(env))
|
338 | 376 |
|
| 377 | + use_projects = True |
| 378 | + if os.environ.get('AVOID_PROJECTS'): |
| 379 | + use_projects = False |
| 380 | + |
339 | 381 | #
|
340 | 382 | # Create empty configuration to avoid the non existent file exception
|
341 | 383 | # in the web app during the first web app startup.
|
342 | 384 | #
|
343 | 385 | if not os.path.exists(OPENGROK_CONFIG_FILE) or \
|
344 | 386 | os.path.getsize(OPENGROK_CONFIG_FILE) == 0:
|
345 |
| - create_bare_config(logger) |
| 387 | + create_bare_config(logger, use_projects=use_projects) |
346 | 388 |
|
347 | 389 | if sync_period > 0:
|
348 |
| - num_workers = multiprocessing.cpu_count() |
349 |
| - workers_env = os.environ.get('WORKERS') |
350 |
| - if workers_env: |
351 |
| - try: |
352 |
| - n = int(workers_env) |
353 |
| - if n > 0: |
354 |
| - num_workers = n |
355 |
| - except ValueError: |
356 |
| - logger.error("WORKERS is not a number: {}".format(workers_env)) |
357 |
| - |
358 |
| - logger.info('Number of sync workers: {}'.format(num_workers)) |
| 390 | + if use_projects: |
| 391 | + num_workers = multiprocessing.cpu_count() |
| 392 | + workers_env = os.environ.get('WORKERS') |
| 393 | + if workers_env: |
| 394 | + try: |
| 395 | + n = int(workers_env) |
| 396 | + if n > 0: |
| 397 | + num_workers = n |
| 398 | + except ValueError: |
| 399 | + logger.error("WORKERS is not a number: {}". |
| 400 | + format(workers_env)) |
| 401 | + |
| 402 | + logger.info('Number of sync workers: {}'.format(num_workers)) |
| 403 | + |
| 404 | + worker_function = project_syncer |
| 405 | + syncer_args = (logger, log_level, uri, |
| 406 | + OPENGROK_CONFIG_FILE, |
| 407 | + sync_period, num_workers, env) |
| 408 | + else: |
| 409 | + worker_function = indexer_no_projects |
| 410 | + syncer_args = (logger, uri, OPENGROK_CONFIG_FILE, sync_period, |
| 411 | + extra_indexer_options) |
359 | 412 |
|
360 | 413 | logger.debug("Starting sync thread")
|
361 |
| - thread = threading.Thread(target=syncer, name="Sync thread", |
362 |
| - args=(logger, log_level, uri, |
363 |
| - OPENGROK_CONFIG_FILE, |
364 |
| - sync_period, num_workers, env)) |
| 414 | + thread = threading.Thread(target=worker_function, name="Sync thread", |
| 415 | + args=syncer_args) |
365 | 416 | thread.start()
|
366 | 417 |
|
367 | 418 | # Start Tomcat last. It will be the foreground process.
|
|
0 commit comments