2222// For GFlag's built-in help message flag
2323DECLARE_bool (help);
2424
25- void RunPelotonServer () {
25+ int RunPelotonServer () {
26+ int return_code = 0 ;
2627 try {
2728 // Setup
2829 peloton::PelotonInit::Initialize ();
@@ -34,15 +35,18 @@ void RunPelotonServer() {
3435
3536 peloton_server.SetupServer ().ServerLoop ();
3637 } catch (peloton::ConnectionException &exception) {
37- // Nothing to do here!
38+ // log error message and mark failure
39+ peloton::LOG_ERROR (" Cannot start server. Failure detail : %s\n " , exception.GetMessage ().c_str ());
40+ return_code = EXIT_FAILURE;
3841 }
3942
4043 // Teardown
4144 peloton::PelotonInit::Shutdown ();
45+ return return_code;
4246}
4347
4448
45- void RunPelotonBrain () {
49+ int RunPelotonBrain () {
4650 // TODO(tianyu): boot up other peloton resources as needed here
4751 peloton::brain::Brain brain;
4852 evthread_use_pthreads ();
@@ -62,6 +66,7 @@ void RunPelotonBrain() {
6266
6367 brain.RegisterJob <peloton::brain::SimpleBrainJob>(&one_second, " test" , example_task);
6468 brain.Run ();
69+ return 0 ;
6570}
6671
6772int main (int argc, char *argv[]) {
@@ -84,13 +89,14 @@ int main(int argc, char *argv[]) {
8489 }
8590 } catch (peloton::SettingsException &exception) {
8691 peloton::LOG_ERROR (" Cannot load settings. Failed with %s\n " , exception.GetMessage ().c_str ());
87- return 0 ; // TODO: Use an enum with exit error codes
92+ return EXIT_FAILURE ; // TODO: Use an enum with exit error codes
8893 }
8994
95+ int exit_code = 0 ;
9096 if (peloton::settings::SettingsManager::GetBool (
9197 peloton::settings::SettingId::brain))
92- RunPelotonBrain ();
98+ exit_code = RunPelotonBrain ();
9399 else
94- RunPelotonServer ();
95- return 0 ;
100+ exit_code = RunPelotonServer ();
101+ return exit_code ;
96102}
0 commit comments