server: improve exit handling