diff --git a/spectrum/src/main.cpp b/spectrum/src/main.cpp index a55a5ad9..5afdeb19 100644 --- a/spectrum/src/main.cpp +++ b/spectrum/src/main.cpp @@ -8,6 +8,7 @@ #include "transport/networkpluginserver.h" #include "transport/admininterface.h" #include "Swiften/EventLoop/SimpleEventLoop.h" +#include #ifndef WIN32 #include "sys/signal.h" #else @@ -18,6 +19,7 @@ #include "log4cxx/patternlayout.h" #include "log4cxx/propertyconfigurator.h" #include "log4cxx/consoleappender.h" +#include "libgen.h" using namespace log4cxx; @@ -161,7 +163,23 @@ int main(int argc, char **argv) #ifndef WIN32 if (!no_daemon) { - daemonize("/", NULL); + try { + boost::filesystem::create_directories(CONFIG_STRING(&config, "service.working_dir")); + } + catch (...) { + std::cerr << "Can't create service.working_dir directory " << CONFIG_STRING(&config, "service.working_dir") << ".\n"; + return 1; + } + try { + boost::filesystem::create_directories( + boost::filesystem::path(CONFIG_STRING(&config, "service.pidfile")).parent_path().string() + ); + } + catch (...) { + std::cerr << "Can't create service.pidfile directory " << boost::filesystem::path(CONFIG_STRING(&config, "service.pidfile")).parent_path().string() << ".\n"; + return 1; + } + daemonize(CONFIG_STRING(&config, "service.working_dir").c_str(), CONFIG_STRING(&config, "service.pidfile").c_str()); } #endif diff --git a/src/config.cpp b/src/config.cpp index 82f3aa47..f171697e 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -52,6 +52,8 @@ bool Config::load(std::istream &ifs, boost::program_options::options_description ("service.port", value()->default_value(0), "Port the server is listening on") ("service.backend", value()->default_value("libpurple_backend"), "Backend") ("service.protocol", value()->default_value(""), "Protocol") + ("service.pidfile", value()->default_value("/var/run/spectrum2/spectrum2.pid"), "Full path to pid file") + ("service.working_dir", value()->default_value("/var/lib/spectrum2"), "Working dir") ("service.allowed_servers", value()->default_value(""), "Only users from these servers can connect") ("service.server_mode", value()->default_value(false), "True if Spectrum should behave as server") ("service.users_per_backend", value()->default_value(100), "Number of users per one legacy network backend")