I'm using Ubuntu 16.04 servers. Each server hosts multiple services.
Sometimes, when a service is restarted, it fails to bind to the port and says that the port is already in used. Indeed, some system service (or some other service which downloads tons of stuff from multiple websites) might be using the port at that particular moment.
So I retry again and again to bind to the port until it finally succeeds, but this can take some time.
How can I prevent that from happening ? How can I make sure a port is not in used while my service is not running ?