cli: refactored re-connecting part after reload/restart to void errors and hangs