A script is needed for the server on Centos, which will ping for example the yandex.ru site, and as soon as the response from the site disappears (no response 15 seconds), restart the service network restart until the connection is restored.

PS Ping is not on the crown, but constantly, and as soon as the connection disappears - restart

  • one
    Somehow it seems to me that a cyclic restart of services does not really solve your problem (which, you have not described here). - What actually happens at you, and what do you want? - avp
  • exactly! I adhere to the same opinion as @avp And the restart of the network in modern CentOS has long been carried out by the service NetworkManager restart team - Justicet
  • How to understand the "cyclic", and how to run it ONLY when the ping disappears? Justicet, explain to me, I'm in Moscow, and the server is in St. Petersburg, how can I remotely reboot the network if the network does not work? - Nicolayka
  • one
    @Nicolayka, cyclic - this means that as soon as the ping is gone, you restart the network. Once again I want to draw your attention to the fact that this will not change anything (even if this restart is implemented "smartly"). The OS and network is not a fish that goes dead by itself. If server unavailability is connected to network equipment, then the service network restart will give nothing. You need to understand the cause of the problem and fix it. - avp
  • There is a problem with the provider, the DNS drops, and it restarts after a while, and my server tries to get IP 50 times and stops, and the DNS has not yet recovered from the provider. So you have to call the system. admin that he would manually restart the network. But it already bothers you, and you need to write a script that will ping the external resource itself, and as soon as the connection is gone, restart the network until the connection is restored. - Nicolayka

1 answer 1

Here is the information

ping -w 5 -c 3 yandex.ru

It behaves like this: if within 5 seconds there were 3 or more answers, then in $? will be 0, if there were less than 3 answers, then in $? will be 1

ping and check $? in a while :;do cmd;done loop while :;do cmd;done and restart the service if necessary,

configure supervisord to keep your script running all the time.

conditions in bash

while loop

supervisord