22
22
// For GFlag's built-in help message flag
23
23
DECLARE_bool (help);
24
24
25
- void RunPelotonServer () {
25
+ int RunPelotonServer () {
26
+ int return_code = 0 ;
26
27
try {
27
28
// Setup
28
29
peloton::PelotonInit::Initialize ();
@@ -34,15 +35,18 @@ void RunPelotonServer() {
34
35
35
36
peloton_server.SetupServer ().ServerLoop ();
36
37
} 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;
38
41
}
39
42
40
43
// Teardown
41
44
peloton::PelotonInit::Shutdown ();
45
+ return return_code;
42
46
}
43
47
44
48
45
- void RunPelotonBrain () {
49
+ int RunPelotonBrain () {
46
50
// TODO(tianyu): boot up other peloton resources as needed here
47
51
peloton::brain::Brain brain;
48
52
evthread_use_pthreads ();
@@ -62,6 +66,7 @@ void RunPelotonBrain() {
62
66
63
67
brain.RegisterJob <peloton::brain::SimpleBrainJob>(&one_second, " test" , example_task);
64
68
brain.Run ();
69
+ return 0 ;
65
70
}
66
71
67
72
int main (int argc, char *argv[]) {
@@ -84,13 +89,14 @@ int main(int argc, char *argv[]) {
84
89
}
85
90
} catch (peloton::SettingsException &exception) {
86
91
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
88
93
}
89
94
95
+ int exit_code = 0 ;
90
96
if (peloton::settings::SettingsManager::GetBool (
91
97
peloton::settings::SettingId::brain))
92
- RunPelotonBrain ();
98
+ exit_code = RunPelotonBrain ();
93
99
else
94
- RunPelotonServer ();
95
- return 0 ;
100
+ exit_code = RunPelotonServer ();
101
+ return exit_code ;
96
102
}
0 commit comments