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
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
+ postrotate
+ if ! killall -q -USR1 icinga2; then
+ exit 1
+ fi
+ endscript
}
-/var/log/icinga2/error.log {
- daily
+/var/log/icinga2/debug.log {
+ hourly
rotate 90
compress
delaycompress
notifempty
create 644 icinga icinga
copytruncate
+ postrotate
+ if ! killall -q -USR1 icinga2; then
+ exit 1
+ fi
+ endscript
}
-/var/log/icinga2/debug.log {
- hourly
+/var/log/icinga2/error.log {
+ daily
rotate 90
compress
delaycompress
- missingok
- notifempty
- create 644 icinga icinga
+ missingok
+ notifempty
+ create 644 icinga icinga
copytruncate
}
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;
/* 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;
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.
*
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.
*
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 */
public:
DECLARE_PTR_TYPEDEFS(Application);
+ static boost::signals2::signal<void (void)> OnReopenLogs;
+
~Application(void);
static void InitializeBase(void);
static void RequestShutdown(void);
static void RequestRestart(void);
+ static void RequestReopenLogs(void);
static void SetDebugging(bool debug);
static bool IsDebugging(void);
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. */
static void DisplayBugMessage(void);
static void SigAbrtHandler(int signum);
+ static void SigUsr1Handler(int signum);
static void ExceptionHandler(void);
};
#include "base/filelogger.h"
#include "base/dynamictype.h"
#include "base/statsfunction.h"
+#include "base/application.h"
#include <fstream>
using namespace icinga;
/**
* 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();
static Value StatsFunc(Dictionary::Ptr& status, Dictionary::Ptr& perfdata);
virtual void Start(void);
+
+private:
+ void ReopenLogFile(void);
};
}
{
ObjectLock olock(this);
+ if (m_OwnsStream)
+ delete m_Stream;
+
m_Stream = stream;
m_OwnsStream = ownsStream;
m_Tty = IsTty(*stream);