How to restart service with CLI when connection are closed?

Hello,

Is it possible to restart the "Serv-u File Server" service with CLI, but only after all the connexion are closed? Or any other way to automate this.

In resume, doing something like this but with CLI:

Thanks in advance !