@@ -151,6 +151,7 @@ def is_systemd_active(feat):
151151def restart_systemd_service (server , feat , owner ):
152152 log_debug ("Restart service {} to owner:{}" .format (feat , owner ))
153153 if not UNIT_TESTING :
154+ subprocess .call (["systemctl" , "reset-failed" , str (feat )])
154155 status = subprocess .call (["systemctl" , "restart" , str (feat )])
155156 else :
156157 server .mod_db_entry (STATE_DB_NAME ,
@@ -551,6 +552,7 @@ def on_state_update(self, key, op, data):
551552
552553 self .st_data [key ] = _update_entry (dflt_st_feat , data )
553554 remote_state = self .st_data [key ][ST_FEAT_REMOTE_STATE ]
555+ current_owner = self .st_data [key ][ST_FEAT_OWNER ]
554556
555557 if (remote_state == REMOTE_RUNNING ) and (old_remote_state != remote_state ):
556558 # Tag latest
@@ -563,6 +565,13 @@ def on_state_update(self, key, op, data):
563565
564566 log_debug ("try to tag latest label after {} seconds @{}" .format (
565567 remote_ctr_config [TAG_IMAGE_LATEST ], start_time ))
568+
569+ # This is for going back to local without waiting the systemd restart time
570+ # when k8s is down, can't deploy containers to worker and need to go back to local
571+ # if current owner is already local, we don't do restart
572+ if (current_owner != OWNER_LOCAL ) and (remote_state == REMOTE_NONE ) and (old_remote_state == REMOTE_STOPPED ):
573+ restart_systemd_service (self .server , key , OWNER_LOCAL )
574+ return
566575
567576 if (not init ):
568577 if (old_remote_state == remote_state ):
0 commit comments