Process stop/restart commands in main loop instead of signal handler context

It is safe.