How to reconnect relay_server?

Sometimes the relay server goes down, and after restarting the relay server again, the target service cannot be proxy. How can the target service check that it has disconnected from the relay server? Then what should I do to automatically reconnect the target service and the relay server?