Commit 2ab1e828 authored by François Grisez's avatar François Grisez

Make the logs to be opened after forking when Flexisip has been launched with --daemon option

That fix an issue that lead Flexisip to write its log messages into an already rotated
file (e.g. flexisip-proxy.log.1) when the instance has been respawned after crashing.
parent 3ba0a222
Pipeline #6859 passed with stages
in 42 minutes and 20 seconds
......@@ -815,30 +815,6 @@ int main(int argc, char *argv[]) {
sip_update_default_mclass(sip_extend_mclass(NULL));
root = su_root_create(NULL);
// in case we don't plan to launch flexisip, don't setup the logs.
if (!dumpDefault.getValue().length() && !listOverrides.getValue().length() && !listModules && !dumpMibs && !dumpAll) {
if (cfg->getGlobal()->get<ConfigByteSize>("max-log-size")->read() != -1) {
LOGF("Setting 'global/max-log-size' parameter has been forbbiden since log size control was delegated to logrotate. Please "
"edit /etc/logrotate.d/flexisip-logrotate for log rotation customization."
);
}
LogManager::Parameters logParams;
logParams.root = root;
logParams.logDirectory = cfg->getGlobal()->get<ConfigString>("log-directory")->read();
logParams.logFilename = "flexisip-" + fName + ".log";
logParams.level = debug ? BCTBX_LOG_DEBUG : LogManager::get().logLevelFromName(log_level);
logParams.enableSyslog = useSyslog;
logParams.syslogLevel = LogManager::get().logLevelFromName(syslog_level);
logParams.enableStdout = debug && !daemonMode; // No need to log to stdout in daemon mode.
logParams.enableUserErrors = user_errors;
LogManager::get().initialize(logParams);
LogManager::get().setContextualFilter(cfg->getGlobal()->get<ConfigString>("contextual-log-filter")->read());
LogManager::get().setContextualLevel(LogManager::get().logLevelFromName(cfg->getGlobal()->get<ConfigString>("contextual-log-level")->read()));
} else {
LogManager::get().disable();
}
signal(SIGPIPE, SIG_IGN);
signal(SIGTERM, flexisip_stop);
......@@ -890,6 +866,33 @@ int main(int argc, char *argv[]) {
makePidFile(pidFile.getValue());
}
/* Log initialisation.
* This must be done after forking in order the log file be reopen after respawn should Flexisip crash.
* The condition intent to avoid log initialization should the user have passed command line options that doesn't
* require to start the server e.g. dumping default configuration file. */
if (!dumpDefault.getValue().length() && !listOverrides.getValue().length() && !listModules && !dumpMibs && !dumpAll) {
if (cfg->getGlobal()->get<ConfigByteSize>("max-log-size")->read() != -1) {
LOGF("Setting 'global/max-log-size' parameter has been forbbiden since log size control was delegated to logrotate. Please "
"edit /etc/logrotate.d/flexisip-logrotate for log rotation customization."
);
}
LogManager::Parameters logParams;
logParams.root = root;
logParams.logDirectory = cfg->getGlobal()->get<ConfigString>("log-directory")->read();
logParams.logFilename = "flexisip-" + fName + ".log";
logParams.level = debug ? BCTBX_LOG_DEBUG : LogManager::get().logLevelFromName(log_level);
logParams.enableSyslog = useSyslog;
logParams.syslogLevel = LogManager::get().logLevelFromName(syslog_level);
logParams.enableStdout = debug && !daemonMode; // No need to log to stdout in daemon mode.
logParams.enableUserErrors = user_errors;
LogManager::get().initialize(logParams);
LogManager::get().setContextualFilter(cfg->getGlobal()->get<ConfigString>("contextual-log-filter")->read());
LogManager::get().setContextualLevel(LogManager::get().logLevelFromName(cfg->getGlobal()->get<ConfigString>("contextual-log-level")->read()));
} else {
LogManager::get().disable();
}
/*
* From now on, we are a flexisip daemon, that is a process that will run proxy, presence, or conference server.
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment