Move atexit to signal handler for server shutdown