Implement a main program with both daemon and standalone mode.