40 #include <boost/log/expressions.hpp> 41 #include <boost/log/utility/setup/file.hpp> 44 using boost::program_options::options_description;
45 using boost::make_shared;
62 #define OPT(_name, _shortcut) (string(_name).append(",").append(_shortcut)).c_str() 63 using namespace boost::program_options;
69 "Specifies a config file which will be loaded at program start. Absolute and relative paths are possible. Additionally we search in " SYSCONFDIR
".")
74 (
OPT(
opt::logfile,
"l"), value<string>()->default_value(
"log.txt"),
"specifies the logfile")
77 (
OPT(
opt::server::access_log,
"a"), value<string>()->default_value(
"access_log.txt"),
"file where server access will be logged")
80 (
OPT(
opt::server::num_threads,
"n"), value<int>()->default_value(std::thread::hardware_concurrency()),
"number of threads used to process a request")
91 (
opt::server::performance_log, value<string>(),
"path, where the performance log will be saved. If not set the performance log will not be created.")
105 if (max_queue_size < 1) {
110 int hardware_concurrency = std::thread::hardware_concurrency();
112 if (hardware_concurrency == 0)
114 LOG_SEV(server_log, info) <<
"Couldn't detect amount of cores in this machine.";
116 else if (threads > hardware_concurrency)
118 LOG_SEV(server_log, info) <<
"It's not recommended to use more than " << hardware_concurrency <<
" (amount of cores) threads.";
128 if (parse_timeout < 50) {
143 if (!boost::filesystem::is_directory(folder)) {
155 if (!boost::filesystem::is_directory(folder)) {
157 boost::filesystem::create_directory(folder);
158 }
catch (boost::filesystem::filesystem_error) {
170 fileLogger->set_filter(logging::expressions::attr<std::string>(
"Channel") !=
"Access");
171 consoleLogger->set_filter(logging::expressions::attr<std::string>(
"Channel") !=
"Access");
173 logging::add_file_log(
175 keywords::rotation_size = 10 * 1024 * 1024,
176 keywords::time_based_rotation = logging::sinks::file::rotation_at_time_point(0, 0, 0),
177 keywords::format =
"%Message%",
178 keywords::filter = (logging::expressions::attr<std::string>(
"Channel") ==
"Access")
192 shared_ptr<Geodata> geodata = make_shared<Geodata>();
197 BOOST_LOG_TRIVIAL(error) <<
"Failed to load geodata!";
198 BOOST_LOG_TRIVIAL(error) <<
"Try to import your osm data again!";
201 shared_ptr<Cache> cache = make_shared<Cache>(
config);
203 shared_ptr<StylesheetManager> ssm = make_shared<StylesheetManager>(
config);
205 shared_ptr<Renderer> renderer = make_shared<Renderer>(geodata);
207 shared_ptr<RequestManager> req_manager = make_shared<RequestManager>(
config, geodata, renderer, cache, ssm);
209 shared_ptr<HttpServer> server = make_shared<HttpServer>(
config, req_manager);
211 ssm->startStylesheetObserving(req_manager);
218 ssm->stopStylesheetObserving();
227 int main(
int argc,
char** argv)
231 int result = app.
start(argc, argv);
boost::program_options::positional_options_description pos_desc
static const char * server_address
Address of the server (type: string)
virtual void onRun(const shared_ptr< Configuration > &config)
Contains the main functionality for the server.
AlacarteServerApp()
Inits the Configuration descriptions.
static const char * path_to_default_style
Path to the default stylesheet (type: string)
static void Shutdown()
Frees all internal memory used by the cache mechanism.
shared_ptr< logging::sinks::synchronous_sink< logging::sinks::basic_text_ostream_backend< char > > > consoleLogger
static const char * path_to_geodata
Filepath where the geodata is located (type: string)
shared_ptr< logging::sinks::synchronous_sink< logging::sinks::text_file_backend > > fileLogger
static const char * cache_size
Option to get the cache size (type: int)
#define OPT(_name, _shortcut)
static const char * cache_keep_tile
Option to get the zoomlevel until tiles are kept on harddrive (type: int)
Represents the Server-Application.
#define LOG_SEV(log, lvl)
static const char * performance_log
Filepath to the performance log (type: string)
static const char * style_source
Path to be observed for stylesheets (type: string)
static const char * access_log
Filepath to the access log (type: string)
bool diagnosticCheckFile(const shared_ptr< Configuration > &config, const string &key)
boost::program_options::options_description config_desc
virtual bool startupDiagnostic(const shared_ptr< Configuration > &config)
static const char * max_queue_size
Maximum size for the queue (type: int)
static const char * path_to_default_tile
Path to the default tile (type: string)
#define DEFAULT_CONFIG_NAME
boost::program_options::options_description cmd_desc
static const char * config
Option to get the configuration filename (type: string)
static const char * parse_timeout
Option to get the timeout for stylesheet-parsing (type: int)
static const char * log_mute_component
Option to get the muted Components.
static void Init(const shared_ptr< Configuration > &conf)
virtual void customInitLog(const shared_ptr< Configuration > &config)
static const char * cache_path
Option to get the cache path (type: string)
static const char * num_threads
Option to get number of worker threads (type: int)
static const char * help
Use Configuration::has to check weather the user wanted help.
static const char * prerender_level
Option to get the timeout for request-processing (type: int)
int start(int argc, char **argv)
Starts the aplication with or without Exceptionhandling.
static const char * server_port
Port the server should listen at (type: int)
static const char * logfile
Option to get the filename of the log (type: string)