Implement command daemon and clean shutdown.