@@ -898,10 +898,47 @@ def _reset_failed_services():
898898 for service in _get_sonic_services ():
899899 clicommon .run_command (['systemctl' , 'reset-failed' , str (service )])
900900
901+
902+ def get_service_finish_timestamp (service ):
903+ out , _ = clicommon .run_command (['sudo' ,
904+ 'systemctl' ,
905+ 'show' ,
906+ '--no-pager' ,
907+ service ,
908+ '-p' ,
909+ 'ExecMainExitTimestamp' ,
910+ '--value' ],
911+ return_cmd = True )
912+ return out .strip (' \t \n \r ' )
913+
914+
915+ def wait_service_restart_finish (service , last_timestamp , timeout = 30 ):
916+ start_time = time .time ()
917+ elapsed_time = 0
918+ while elapsed_time < timeout :
919+ current_timestamp = get_service_finish_timestamp (service )
920+ if current_timestamp and (current_timestamp != last_timestamp ):
921+ return
922+
923+ time .sleep (1 )
924+ elapsed_time = time .time () - start_time
925+
926+ log .log_warning ("Service: {} does not restart in {} seconds, stop waiting" .format (service , timeout ))
927+
928+
901929def _restart_services ():
930+ last_interface_config_timestamp = get_service_finish_timestamp ('interfaces-config' )
931+ last_networking_timestamp = get_service_finish_timestamp ('networking' )
932+
902933 click .echo ("Restarting SONiC target ..." )
903934 clicommon .run_command (['sudo' , 'systemctl' , 'restart' , 'sonic.target' ])
904935
936+ # These service will restart eth0 and cause device lost network for 10 seconds
937+ # When enable TACACS, every remote user commands will authorize by TACACS service via network
938+ # If load_minigraph exit before eth0 restart, commands after load_minigraph may failed
939+ wait_service_restart_finish ('interfaces-config' , last_interface_config_timestamp )
940+ wait_service_restart_finish ('networking' , last_networking_timestamp )
941+
905942 try :
906943 subprocess .check_call (['sudo' , 'monit' , 'status' ], stdout = subprocess .DEVNULL , stderr = subprocess .DEVNULL )
907944 click .echo ("Enabling container monitoring ..." )
0 commit comments