Application starting logic. Daemon and terminal mode.