47
47
add_project , delete_project , get_configuration
48
48
from opengrok_tools .utils .readconfig import read_config
49
49
from opengrok_tools .utils .exitvals import SUCCESS_EXITVAL
50
+ from opengrok_tools .utils .mirror import check_configuration
50
51
51
52
52
53
fs_root = os .path .abspath ('.' ).split (os .path .sep )[0 ] + os .path .sep
70
71
OPENGROK_WEBAPPS_DIR = os .path .join (tomcat_root , "webapps" )
71
72
OPENGROK_JAR = os .path .join (OPENGROK_LIB_DIR , 'opengrok.jar' )
72
73
74
+ NOMIRROR_ENV_NAME = 'NOMIRROR'
75
+
73
76
expected_token = None
74
77
75
78
sleep_event = threading .Event ()
@@ -485,8 +488,8 @@ def main():
485
488
if extra_indexer_options :
486
489
logger .info ("extra indexer options: {}" .format (extra_indexer_options ))
487
490
env ['OPENGROK_INDEXER_OPTIONAL_ARGS' ] = extra_indexer_options
488
- if os .environ .get ('NOMIRROR' ):
489
- env ['OPENGROK_NO_MIRROR' ] = os .environ .get ('NOMIRROR' )
491
+ if os .environ .get (NOMIRROR_ENV_NAME ):
492
+ env ['OPENGROK_NO_MIRROR' ] = os .environ .get (NOMIRROR_ENV_NAME )
490
493
logger .debug ('Extra environment: {}' .format (env ))
491
494
492
495
use_projects = True
@@ -531,15 +534,25 @@ def main():
531
534
if out_file :
532
535
os .remove (out_file )
533
536
537
+ sync_enabled = True
534
538
if use_projects :
535
539
num_workers = get_num_from_env (logger , 'WORKERS' ,
536
540
multiprocessing .cpu_count ())
537
541
logger .info ('Number of sync workers: {}' .format (num_workers ))
538
542
539
- mirror_config = os .path .join (OPENGROK_CONFIG_DIR , "mirror.yml" )
540
- if not os .path .exists (mirror_config ):
541
- with open (mirror_config , 'w' ) as fp :
542
- fp .write ("# Empty config file for opengrok-mirror\n " )
543
+ if not os .environ .get (NOMIRROR_ENV_NAME ):
544
+ mirror_config = os .path .join (OPENGROK_CONFIG_DIR , "mirror.yml" )
545
+ if not os .path .exists (mirror_config ):
546
+ with open (mirror_config , 'w' ) as fp :
547
+ fp .write ("# Empty config file for opengrok-mirror\n " )
548
+ else :
549
+ conf = read_config (logger , mirror_config )
550
+ logger .info ("Checking mirror configuration in '{}'" .
551
+ format (mirror_config ))
552
+ if not check_configuration (conf ):
553
+ logger .error ("Mirror configuration in '{}' is invalid, "
554
+ "disabling sync" .format (mirror_config ))
555
+ sync_enabled = False
543
556
544
557
worker_function = project_syncer
545
558
syncer_args = (logger , log_level , uri ,
@@ -550,14 +563,16 @@ def main():
550
563
syncer_args = (logger , uri , OPENGROK_CONFIG_FILE ,
551
564
extra_indexer_options )
552
565
553
- logger .debug ("Starting sync thread" )
554
- sync_thread = threading .Thread (target = worker_function , name = "Sync thread" ,
555
- args = syncer_args , daemon = True )
556
- sync_thread .start ()
566
+ if sync_enabled :
567
+ logger .debug ("Starting sync thread" )
568
+ sync_thread = threading .Thread (target = worker_function ,
569
+ name = "Sync thread" ,
570
+ args = syncer_args , daemon = True )
571
+ sync_thread .start ()
557
572
558
- start_rest_thread (logger )
559
- if sync_period > 0 :
560
- start_timeout_thread (logger , sync_period )
573
+ start_rest_thread (logger )
574
+ if sync_period > 0 :
575
+ start_timeout_thread (logger , sync_period )
561
576
562
577
# Start Tomcat last. It will be the foreground process.
563
578
logger .info ("Starting Tomcat" )
0 commit comments