|
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):
|
@@ -218,7 +219,43 @@ def merge_commands_env(commands, env):
|
218 | 219 | return commands
|
219 | 220 |
|
220 | 221 |
|
221 |
| -def syncer(logger, loglevel, uri, config_path, sync_period, numworkers, env): |
| 222 | +def indexer_no_projects(logger, uri, config_path, sync_period, |
| 223 | + extra_indexer_options): |
| 224 | + """ |
| 225 | + Project less indexer |
| 226 | + """ |
| 227 | + |
| 228 | + wait_for_tomcat(logger, uri) |
| 229 | + |
| 230 | + while True: |
| 231 | + indexer_options = ['-s', OPENGROK_SRC_ROOT, |
| 232 | + '-d', OPENGROK_DATA_ROOT, |
| 233 | + '-c', '/usr/local/bin/ctags', |
| 234 | + '--remote', 'on', |
| 235 | + '-H', |
| 236 | + '-W', config_path, |
| 237 | + '-U', uri] |
| 238 | + if extra_indexer_options: |
| 239 | + logger.debug("Adding extra indexer options: {}". |
| 240 | + format(extra_indexer_options)) |
| 241 | + indexer_options.extend(extra_indexer_options.split()) |
| 242 | + indexer = Indexer(indexer_options, logger=logger, |
| 243 | + jar=OPENGROK_JAR) |
| 244 | + indexer.execute() |
| 245 | + ret = indexer.getretcode() |
| 246 | + if ret is None or ret != SUCCESS_EXITVAL: |
| 247 | + logger.error('Command returned {}'.format(ret)) |
| 248 | + logger.error(indexer.geterroutputstr()) |
| 249 | + else: |
| 250 | + logger.info(indexer.getoutputstr()) |
| 251 | + |
| 252 | + sleep_seconds = sync_period * 60 |
| 253 | + logger.info("Sleeping for {} seconds".format(sleep_seconds)) |
| 254 | + time.sleep(sleep_seconds) |
| 255 | + |
| 256 | + |
| 257 | +def project_syncer(logger, loglevel, uri, config_path, sync_period, |
| 258 | + numworkers, env): |
222 | 259 | """
|
223 | 260 | Wrapper for running opengrok-sync.
|
224 | 261 | To be run in a thread/process in the background.
|
@@ -267,22 +304,25 @@ def syncer(logger, loglevel, uri, config_path, sync_period, numworkers, env):
|
267 | 304 | time.sleep(sleep_seconds)
|
268 | 305 |
|
269 | 306 |
|
270 |
| -def create_bare_config(logger): |
| 307 | +def create_bare_config(logger, use_projects=True): |
271 | 308 | """
|
272 | 309 | Create bare configuration file with a few basic settings.
|
273 | 310 | """
|
274 | 311 |
|
275 | 312 | logger.info('Creating bare configuration in {}'.
|
276 | 313 | format(OPENGROK_CONFIG_FILE))
|
277 |
| - indexer = Indexer(['-s', OPENGROK_SRC_ROOT, |
| 314 | + indexer_options = ['-s', OPENGROK_SRC_ROOT, |
278 | 315 | '-d', OPENGROK_DATA_ROOT,
|
279 | 316 | '-c', '/usr/local/bin/ctags',
|
280 | 317 | '--remote', 'on',
|
281 |
| - '-P', '-H', |
| 318 | + '-H', |
282 | 319 | '-W', OPENGROK_CONFIG_FILE,
|
283 |
| - '--noIndex'], |
284 |
| - jar=os.path.join(OPENGROK_LIB_DIR, |
285 |
| - 'opengrok.jar'), |
| 320 | + '--noIndex'] |
| 321 | + if use_projects: |
| 322 | + indexer_options.append('-P') |
| 323 | + |
| 324 | + indexer = Indexer(indexer_options, |
| 325 | + jar=OPENGROK_JAR, |
286 | 326 | logger=logger, doprint=True)
|
287 | 327 | indexer.execute()
|
288 | 328 | ret = indexer.getretcode()
|
@@ -329,39 +369,53 @@ def main():
|
329 | 369 | setup_redirect_source(logger, url_root)
|
330 | 370 |
|
331 | 371 | env = {}
|
332 |
| - if os.environ.get('INDEXER_OPT'): |
333 |
| - env['OPENGROK_INDEXER_OPTIONAL_ARGS'] = \ |
334 |
| - os.environ.get('INDEXER_OPT') |
| 372 | + extra_indexer_options = os.environ.get('INDEXER_OPT') |
| 373 | + if extra_indexer_options: |
| 374 | + logger.info("extra indexer options: {}".format(extra_indexer_options)) |
| 375 | + env['OPENGROK_INDEXER_OPTIONAL_ARGS'] = extra_indexer_options |
335 | 376 | if os.environ.get('NOMIRROR'):
|
336 | 377 | env['OPENGROK_NO_MIRROR'] = os.environ.get('NOMIRROR')
|
337 | 378 | logger.debug('Extra environment: {}'.format(env))
|
338 | 379 |
|
| 380 | + use_projects = True |
| 381 | + if os.environ.get('AVOID_PROJECTS'): |
| 382 | + use_projects = False |
| 383 | + |
339 | 384 | #
|
340 | 385 | # Create empty configuration to avoid the non existent file exception
|
341 | 386 | # in the web app during the first web app startup.
|
342 | 387 | #
|
343 | 388 | if not os.path.exists(OPENGROK_CONFIG_FILE) or \
|
344 | 389 | os.path.getsize(OPENGROK_CONFIG_FILE) == 0:
|
345 |
| - create_bare_config(logger) |
| 390 | + create_bare_config(logger, use_projects=use_projects) |
346 | 391 |
|
347 | 392 | 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)) |
| 393 | + if use_projects: |
| 394 | + num_workers = multiprocessing.cpu_count() |
| 395 | + workers_env = os.environ.get('WORKERS') |
| 396 | + if workers_env: |
| 397 | + try: |
| 398 | + n = int(workers_env) |
| 399 | + if n > 0: |
| 400 | + num_workers = n |
| 401 | + except ValueError: |
| 402 | + logger.error("WORKERS is not a number: {}". |
| 403 | + format(workers_env)) |
| 404 | + |
| 405 | + logger.info('Number of sync workers: {}'.format(num_workers)) |
| 406 | + |
| 407 | + worker_function = project_syncer |
| 408 | + syncer_args = (logger, log_level, uri, |
| 409 | + OPENGROK_CONFIG_FILE, |
| 410 | + sync_period, num_workers, env) |
| 411 | + else: |
| 412 | + worker_function = indexer_no_projects |
| 413 | + syncer_args = (logger, uri, OPENGROK_CONFIG_FILE, sync_period, |
| 414 | + extra_indexer_options) |
359 | 415 |
|
360 | 416 | 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)) |
| 417 | + thread = threading.Thread(target=worker_function, name="Sync thread", |
| 418 | + args=syncer_args) |
365 | 419 | thread.start()
|
366 | 420 |
|
367 | 421 | # Start Tomcat last. It will be the foreground process.
|
|
0 commit comments