This commit is contained in:
Dennis Luxen 2014-03-25 14:54:52 +01:00
parent 33faa2f252
commit aae3637e0c
5 changed files with 56 additions and 66 deletions

View File

@ -43,6 +43,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <fstream> #include <fstream>
#include <string> #include <string>
const static unsigned INIT_OK_START_ENGINE = 0;
const static unsigned INIT_OK_DO_NOT_START_ENGINE = 1;
const static unsigned INIT_FAILED = -1;
// support old capitalized option names by down-casing them with a regex replace // support old capitalized option names by down-casing them with a regex replace
inline void PrepareConfigFile( inline void PrepareConfigFile(
const boost::filesystem::path& path, const boost::filesystem::path& path,
@ -59,7 +63,7 @@ inline void PrepareConfigFile(
} }
// generate boost::program_options object for the routing part // generate boost::program_options object for the routing part
inline bool GenerateServerProgramOptions( inline unsigned GenerateServerProgramOptions(
const int argc, const int argc,
const char * argv[], const char * argv[],
ServerPaths & paths, ServerPaths & paths,
@ -178,12 +182,12 @@ inline bool GenerateServerProgramOptions(
if(option_variables.count("version")) { if(option_variables.count("version")) {
SimpleLogger().Write() << g_GIT_DESCRIPTION; SimpleLogger().Write() << g_GIT_DESCRIPTION;
return false; return INIT_OK_DO_NOT_START_ENGINE;
} }
if(option_variables.count("help")) { if(option_variables.count("help")) {
SimpleLogger().Write() << visible_options; SimpleLogger().Write() << visible_options;
return false; return INIT_OK_DO_NOT_START_ENGINE;
} }
boost::program_options::notify(option_variables); boost::program_options::notify(option_variables);
@ -288,14 +292,14 @@ inline bool GenerateServerProgramOptions(
path_iterator->second = base_string + ".timestamp"; path_iterator->second = base_string + ".timestamp";
} }
return true; return INIT_OK_START_ENGINE;
} }
if (use_shared_memory && !option_variables.count("base")) if (use_shared_memory && !option_variables.count("base"))
{ {
return true; return INIT_OK_START_ENGINE;
} }
SimpleLogger().Write() << visible_options; SimpleLogger().Write() << visible_options;
return false; return INIT_OK_DO_NOT_START_ENGINE;
} }
#endif /* PROGRAM_OPTIONS_H */ #endif /* PROGRAM_OPTIONS_H */

View File

@ -22,6 +22,6 @@ Feature: Command line options: files
And stdout should contain /\d{1,2}\.\d{1,2}\.\d{1,2}/ And stdout should contain /\d{1,2}\.\d{1,2}\.\d{1,2}/
And stdout should contain /compiled at/ And stdout should contain /compiled at/
And stdout should contain /^\[info\] loaded plugin: viaroute/ And stdout should contain /^\[info\] loaded plugin: viaroute/
And stdout should contain /^\[server\] trial run/ And stdout should contain /^\[info\] trial run/
And stdout should contain /^\[server\] shutdown completed/ And stdout should contain /^\[info\] shutdown completed/
And it should exit with code 0 And it should exit with code 0

View File

@ -9,11 +9,11 @@ Feature: Command line options: invalid options
Then stdout should be empty Then stdout should be empty
And stderr should contain "exception" And stderr should contain "exception"
And stderr should contain "fly-me-to-the-moon" And stderr should contain "fly-me-to-the-moon"
And it should exit with code 255 And it should exit with code 1
Scenario: Missing file Scenario: Missing file
When I run "osrm-routed over-the-rainbow.osrm" When I run "osrm-routed over-the-rainbow.osrm"
Then stdout should contain "over-the-rainbow.osrm" Then stdout should contain "over-the-rainbow.osrm"
And stderr should contain "exception" And stderr should contain "exception"
And stderr should contain "does not exist" And stderr should contain "does not exist"
And it should exit with code 255 And it should exit with code 1

View File

@ -31,7 +31,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "Util/GitDescription.h" #include "Util/GitDescription.h"
#include "Util/InputFileUtil.h" #include "Util/InputFileUtil.h"
// #include "Util/OpenMPWrapper.h"
#include "Util/ProgramOptions.h" #include "Util/ProgramOptions.h"
#include "Util/SimpleLogger.h" #include "Util/SimpleLogger.h"
#include "Util/UUID.h" #include "Util/UUID.h"
@ -43,7 +42,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <signal.h> #include <signal.h>
#include <boost/bind.hpp> #include <boost/bind.hpp>
#include <boost/date_time.hpp> // #include <boost/date_time.hpp>
#include <boost/thread.hpp> #include <boost/thread.hpp>
#include <iostream> #include <iostream>
@ -73,32 +72,27 @@ int main (int argc, const char * argv[])
{ {
LogPolicy::GetInstance().Unmute(); LogPolicy::GetInstance().Unmute();
bool use_shared_memory = false; bool use_shared_memory = false, trial = false;
std::string ip_address; std::string ip_address;
int ip_port, requested_thread_num; int ip_port, requested_thread_num;
bool trial = false;
ServerPaths server_paths; ServerPaths server_paths;
if( !GenerateServerProgramOptions(
argc, const unsigned init_result = GenerateServerProgramOptions(argc, argv, server_paths, ip_address, ip_port, requested_thread_num, use_shared_memory, trial);
argv, if (init_result == INIT_OK_DO_NOT_START_ENGINE)
server_paths, {
ip_address,
ip_port,
requested_thread_num,
use_shared_memory,
trial
)
) {
return 0; return 0;
} }
if (init_result == INIT_FAILED)
{
return 1;
}
#ifdef __linux__ #ifdef __linux__
const int lock_flags = (MCL_CURRENT | MCL_FUTURE); const int lock_flags = (MCL_CURRENT | MCL_FUTURE);
if (-1 == mlockall(lock_flags)) if (-1 == mlockall(lock_flags))
{ {
SimpleLogger().Write(logWARNING) << SimpleLogger().Write(logWARNING) << "Process " << argv[0] << " could not be locked to RAM";
"Process " << argv[0] << " could not be locked to RAM";
} }
#endif #endif
SimpleLogger().Write() << SimpleLogger().Write() <<
@ -111,26 +105,16 @@ int main (int argc, const char * argv[])
} }
else else
{ {
SimpleLogger().Write() << SimpleLogger().Write() << "HSGR file:\t" << server_paths["hsgrdata"];
"HSGR file:\t" << server_paths["hsgrdata"]; SimpleLogger().Write(logDEBUG) << "Nodes file:\t" << server_paths["nodesdata"];
SimpleLogger().Write(logDEBUG) << SimpleLogger().Write(logDEBUG) << "Edges file:\t" << server_paths["edgesdata"];
"Nodes file:\t" << server_paths["nodesdata"]; SimpleLogger().Write(logDEBUG) << "RAM file:\t" << server_paths["ramindex"];
SimpleLogger().Write(logDEBUG) << SimpleLogger().Write(logDEBUG) << "Index file:\t" << server_paths["fileindex"];
"Edges file:\t" << server_paths["edgesdata"]; SimpleLogger().Write(logDEBUG) << "Names file:\t" << server_paths["namesdata"];
SimpleLogger().Write(logDEBUG) << SimpleLogger().Write(logDEBUG) << "Timestamp file:\t" << server_paths["timestamp"];
"RAM file:\t" << server_paths["ramindex"]; SimpleLogger().Write(logDEBUG) << "Threads:\t" << requested_thread_num;
SimpleLogger().Write(logDEBUG) << SimpleLogger().Write(logDEBUG) << "IP address:\t" << ip_address;
"Index file:\t" << server_paths["fileindex"]; SimpleLogger().Write(logDEBUG) << "IP port:\t" << ip_port;
SimpleLogger().Write(logDEBUG) <<
"Names file:\t" << server_paths["namesdata"];
SimpleLogger().Write(logDEBUG) <<
"Timestamp file:\t" << server_paths["timestamp"];
SimpleLogger().Write(logDEBUG) <<
"Threads:\t" << requested_thread_num;
SimpleLogger().Write(logDEBUG) <<
"IP address:\t" << ip_address;
SimpleLogger().Write(logDEBUG) <<
"IP port:\t" << ip_port;
} }
#ifndef _WIN32 #ifndef _WIN32
int sig = 0; int sig = 0;
@ -149,9 +133,12 @@ int main (int argc, const char * argv[])
routing_server->GetRequestHandlerPtr().RegisterRoutingMachine(&osrm_lib); routing_server->GetRequestHandlerPtr().RegisterRoutingMachine(&osrm_lib);
if( trial ) { if( trial )
std::cout << "[server] trial run, quitting after successful initialization" << std::endl; {
} else { SimpleLogger().Write() << "trial run, quitting after successful initialization";
}
else
{
boost::thread server_thread(boost::bind(&Server::Run, routing_server)); boost::thread server_thread(boost::bind(&Server::Run, routing_server));
#ifndef _WIN32 #ifndef _WIN32
@ -162,34 +149,33 @@ int main (int argc, const char * argv[])
sigaddset(&wait_mask, SIGQUIT); sigaddset(&wait_mask, SIGQUIT);
sigaddset(&wait_mask, SIGTERM); sigaddset(&wait_mask, SIGTERM);
pthread_sigmask(SIG_BLOCK, &wait_mask, 0); pthread_sigmask(SIG_BLOCK, &wait_mask, 0);
std::cout << "[server] running and waiting for requests" << std::endl; SimpleLogger().Write() << "running and waiting for requests";
sigwait(&wait_mask, &sig); sigwait(&wait_mask, &sig);
#else #else
// Set console control handler to allow server to be stopped. // Set console control handler to allow server to be stopped.
console_ctrl_function = boost::bind(&Server::Stop, routing_server); console_ctrl_function = boost::bind(&Server::Stop, routing_server);
SetConsoleCtrlHandler(console_ctrl_handler, TRUE); SetConsoleCtrlHandler(console_ctrl_handler, TRUE);
std::cout << "[server] running and waiting for requests" << std::endl; SimpleLogger().Write() << "running and waiting for requests";
routing_server->Run(); routing_server->Run();
#endif #endif
std::cout << "[server] initiating shutdown" << std::endl; SimpleLogger().Write() << "initiating shutdown";
routing_server->Stop(); routing_server->Stop();
std::cout << "[server] stopping threads" << std::endl; SimpleLogger().Write() << "stopping threads";
if (!server_thread.timed_join(boost::posix_time::seconds(2))) if (!server_thread.timed_join(boost::posix_time::seconds(2)))
{ {
SimpleLogger().Write(logDEBUG) << SimpleLogger().Write(logDEBUG) << "Threads did not finish within 2 seconds. Hard abort!";
"Threads did not finish within 2 seconds. Hard abort!";
} }
} }
std::cout << "[server] freeing objects" << std::endl; SimpleLogger().Write() << "freeing objects";
delete routing_server; delete routing_server;
std::cout << "[server] shutdown completed" << std::endl; SimpleLogger().Write() << "shutdown completed";
} }
catch (std::exception& e) catch (const std::exception& e)
{ {
std::cerr << "[fatal error] exception: " << e.what() << std::endl; SimpleLogger().Write(logWARNING) << "exception: " << e.what();
return -1; return 1;
} }
#ifdef __linux__ #ifdef __linux__
munlockall(); munlockall();