diff --git a/spectrum/src/main.cpp b/spectrum/src/main.cpp index 0408d16bfda191f8fd78cf6a334b402cdf5dff36..c2505c2761d4f748c5c1d77d4dca6892a711be62 100644 --- a/spectrum/src/main.cpp +++ b/spectrum/src/main.cpp @@ -207,6 +207,16 @@ int main(int argc, char **argv) std::cerr << "Can't create service.working_dir directory " << CONFIG_STRING(&config, "service.working_dir") << ".\n"; return 1; } + // create directories + try { + boost::filesystem::create_directories( + boost::filesystem::path(CONFIG_STRING(&config, "service.portfile")).parent_path().string() + ); + } + catch (...) { + std::cerr << "Can't create service.portfile directory " << CONFIG_STRING(&config, "service.portfile") << ".\n"; + return 1; + } #ifndef WIN32 if (!CONFIG_STRING(&config, "service.group").empty() ||!CONFIG_STRING(&config, "service.user").empty() ) { @@ -223,6 +233,20 @@ int main(int argc, char **argv) chown(CONFIG_STRING(&config, "service.working_dir").c_str(), pw->pw_uid, gr->gr_gid); } + char backendport[20]; + FILE* port_file_f; + port_file_f = fopen(CONFIG_STRING(&config, "service.portfile").c_str(), "w+"); + if (port_file_f == NULL) { + std::cerr << "Cannot create port_file file " << CONFIG_STRING(&config, "service.portfile").c_str() << ". Exiting\n"; + exit(1); + } + sprintf(backendport,"%s\n",CONFIG_STRING(&config, "service.backend_port").c_str()); + if (fwrite(backendport,1,strlen(backendport),port_file_f) < strlen(backendport)) { + std::cerr << "Cannot write to port file " << CONFIG_STRING(&config, "service.portfile") << ". Exiting\n"; + exit(1); + } + fclose(port_file_f); + if (!no_daemon) { // daemonize daemonize(CONFIG_STRING(&config, "service.working_dir").c_str(), CONFIG_STRING(&config, "service.pidfile").c_str());