4747 add_project , delete_project , get_configuration
4848from opengrok_tools .utils .readconfig import read_config
4949from opengrok_tools .utils .exitvals import SUCCESS_EXITVAL
50+ from opengrok_tools .utils .mirror import check_configuration
5051
5152
5253fs_root = os .path .abspath ('.' ).split (os .path .sep )[0 ] + os .path .sep
7071OPENGROK_WEBAPPS_DIR = os .path .join (tomcat_root , "webapps" )
7172OPENGROK_JAR = os .path .join (OPENGROK_LIB_DIR , 'opengrok.jar' )
7273
74+ NOMIRROR_ENV_NAME = 'NOMIRROR'
75+
7376expected_token = None
7477
7578sleep_event = threading .Event ()
@@ -485,8 +488,8 @@ def main():
485488 if extra_indexer_options :
486489 logger .info ("extra indexer options: {}" .format (extra_indexer_options ))
487490 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 )
490493 logger .debug ('Extra environment: {}' .format (env ))
491494
492495 use_projects = True
@@ -531,15 +534,25 @@ def main():
531534 if out_file :
532535 os .remove (out_file )
533536
537+ sync_enabled = True
534538 if use_projects :
535539 num_workers = get_num_from_env (logger , 'WORKERS' ,
536540 multiprocessing .cpu_count ())
537541 logger .info ('Number of sync workers: {}' .format (num_workers ))
538542
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
543556
544557 worker_function = project_syncer
545558 syncer_args = (logger , log_level , uri ,
@@ -550,14 +563,16 @@ def main():
550563 syncer_args = (logger , uri , OPENGROK_CONFIG_FILE ,
551564 extra_indexer_options )
552565
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 ()
557572
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 )
561576
562577 # Start Tomcat last. It will be the foreground process.
563578 logger .info ("Starting Tomcat" )
0 commit comments