Fix logrotate config.

Fixes #6229
This commit is contained in:
Gunnar Beutner 2014-05-22 11:22:30 +02:00
parent fceeeba05e
commit 2350593ef0
7 changed files with 73 additions and 17 deletions

View File

@ -2,6 +2,7 @@ debian/tmp/etc/icinga2
debian/config/apt.conf etc/icinga2/conf.d/hosts/localhost
debian/config/kernel.conf etc/icinga2/conf.d/hosts/localhost
debian/config/check_kernel etc/sudoers.d
etc/logrotate.d
usr/bin/icinga2-build*
usr/bin/icinga2-sign-key
usr/sbin/icinga2-*-feature

View File

@ -8,22 +8,11 @@
notifempty
create 644 icinga icinga
copytruncate
#postrotate
# if /etc/init.d/icinga2 status > /dev/null ; then \
# /etc/init.d/icinga2 reload > /dev/null; \
# fi;
#endscript
}
/var/log/icinga2/error.log {
daily
rotate 90
compress
delaycompress
missingok
notifempty
create 644 icinga icinga
copytruncate
postrotate
if ! killall -q -USR1 icinga2; then
exit 1
fi
endscript
}
/var/log/icinga2/debug.log {
@ -35,5 +24,21 @@
notifempty
create 644 icinga icinga
copytruncate
postrotate
if ! killall -q -USR1 icinga2; then
exit 1
fi
endscript
}
/var/log/icinga2/error.log {
daily
rotate 90
compress
delaycompress
missingok
notifempty
create 644 icinga icinga
copytruncate
}

View File

@ -43,9 +43,11 @@ using namespace icinga;
REGISTER_TYPE(Application);
boost::signals2::signal<void (void)> Application::OnReopenLogs;
Application *Application::m_Instance = NULL;
bool Application::m_ShuttingDown = false;
bool Application::m_RequestRestart = false;
bool Application::m_RequestReopenLogs = false;
pid_t Application::m_ReloadProcess = 0;
static bool l_Restarting = false;
bool Application::m_Debugging = false;
@ -238,6 +240,12 @@ mainloop:
/* Watches for changes to the system time. Adjusts timers if necessary. */
Utility::Sleep(2.5);
if (m_RequestReopenLogs) {
Log(LogInformation, "base", "Reopening log files");
m_RequestReopenLogs = false;
OnReopenLogs();
}
double now = Utility::GetTime();
double timeDiff = lastLoop - now;
@ -336,6 +344,15 @@ void Application::RequestRestart(void)
m_RequestRestart = true;
}
/**
* Signals the application to reopen log files during the
* next execution of the event loop.
*/
void Application::RequestReopenLogs(void)
{
m_RequestReopenLogs = true;
}
/**
* Retrieves the full path of the executable.
*
@ -484,6 +501,17 @@ void Application::SigIntTermHandler(int signum)
instance->RequestShutdown();
}
/**
* Signal handler for SIGUSR1. This signal causes Icinga to re-open
* its log files and is mainly for use by logrotate.
*
* @param - The signal number.
*/
void Application::SigUsr1Handler(int)
{
RequestReopenLogs();
}
/**
* Signal handler for SIGABRT. Helps with debugging ASSERT()s.
*
@ -614,6 +642,9 @@ int Application::Run(void)
sa.sa_handler = SIG_IGN;
sigaction(SIGPIPE, &sa, NULL);
sa.sa_handler = &Application::SigUsr1Handler;
sigaction(SIGUSR1, &sa, NULL);
#else /* _WIN32 */
SetConsoleCtrlHandler(&Application::CtrlHandler, TRUE);
#endif /* _WIN32 */

View File

@ -37,6 +37,8 @@ class I2_BASE_API Application : public ObjectImpl<Application> {
public:
DECLARE_PTR_TYPEDEFS(Application);
static boost::signals2::signal<void (void)> OnReopenLogs;
~Application(void);
static void InitializeBase(void);
@ -64,6 +66,7 @@ public:
static void RequestShutdown(void);
static void RequestRestart(void);
static void RequestReopenLogs(void);
static void SetDebugging(bool debug);
static bool IsDebugging(void);
@ -128,6 +131,7 @@ private:
static bool m_RequestRestart; /**< A restart was requested through SIGHUP */
static pid_t m_ReloadProcess; /**< The PID of a subprocess doing a reload,
only valid when l_Restarting==true */
static bool m_RequestReopenLogs; /**< Whether we should re-open log files. */
static int m_ArgC; /**< The number of command-line arguments. */
static char **m_ArgV; /**< Command-line arguments. */
@ -146,6 +150,7 @@ private:
static void DisplayBugMessage(void);
static void SigAbrtHandler(int signum);
static void SigUsr1Handler(int signum);
static void ExceptionHandler(void);
};

View File

@ -20,6 +20,7 @@
#include "base/filelogger.h"
#include "base/dynamictype.h"
#include "base/statsfunction.h"
#include "base/application.h"
#include <fstream>
using namespace icinga;
@ -44,10 +45,17 @@ Value FileLogger::StatsFunc(Dictionary::Ptr& status, Dictionary::Ptr&)
/**
* Constructor for the FileLogger class.
*/
void FileLogger::Start()
void FileLogger::Start(void)
{
StreamLogger::Start();
ReopenLogFile();
Application::OnReopenLogs.connect(boost::bind(&FileLogger::ReopenLogFile, this));
}
void FileLogger::ReopenLogFile(void)
{
std::ofstream *stream = new std::ofstream();
String path = GetPath();

View File

@ -40,6 +40,9 @@ public:
static Value StatsFunc(Dictionary::Ptr& status, Dictionary::Ptr& perfdata);
virtual void Start(void);
private:
void ReopenLogFile(void);
};
}

View File

@ -67,6 +67,9 @@ void StreamLogger::BindStream(std::ostream *stream, bool ownsStream)
{
ObjectLock olock(this);
if (m_OwnsStream)
delete m_Stream;
m_Stream = stream;
m_OwnsStream = ownsStream;
m_Tty = IsTty(*stream);