server handles signals to quit gracefully