added: possibility to save a pid file
new config option: pid_file (a full path to a pid file) git-svn-id: svn://ttmath.org/publicrep/winix/trunk@957 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
@@ -10,14 +10,17 @@
|
||||
#include <cstdlib>
|
||||
#include <ctime>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <sys/param.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include "core/log.h"
|
||||
#include "core/slog.h"
|
||||
#include "core/app.h"
|
||||
#include "core/plugin.h"
|
||||
#include "core/version.h"
|
||||
#include "utf8/utf8.h"
|
||||
|
||||
|
||||
|
||||
@@ -94,6 +97,40 @@ void LogInfo(LogManipulators log_level, const char * msg, bool put_version, cons
|
||||
}
|
||||
|
||||
|
||||
void SavePidFile()
|
||||
{
|
||||
if( !app.config.pid_file.empty() )
|
||||
{
|
||||
std::string file_name;
|
||||
PT::WideToUTF8(app.config.pid_file, file_name);
|
||||
std::ofstream file(file_name);
|
||||
|
||||
if( !file )
|
||||
{
|
||||
log << log1 << "I cannot save the pid to a file: " << app.config.pid_file << logend;
|
||||
}
|
||||
else
|
||||
{
|
||||
file << getpid() << "\n";
|
||||
file.close();
|
||||
log << log3 << "Process pid saved to: " << app.config.pid_file << logend;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void RemovePidFile()
|
||||
{
|
||||
if( !app.config.pid_file.empty() )
|
||||
{
|
||||
std::string file_name;
|
||||
PT::WideToUTF8(app.config.pid_file, file_name);
|
||||
unlink(file_name.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // namespace Winix
|
||||
|
||||
|
||||
@@ -140,8 +177,8 @@ using Winix::app;
|
||||
return 3;
|
||||
|
||||
app.LogUserGroups();
|
||||
|
||||
Winix::log << Winix::log3 << "base_url: " << app.config.base_url << Winix::logend;
|
||||
Winix::SavePidFile();
|
||||
|
||||
// load plugins before loading sessions - session_manager.LoadSessions()
|
||||
// because some of the plugins can init its own sessions dates
|
||||
@@ -149,7 +186,10 @@ using Winix::app;
|
||||
|
||||
// app.Init() starts other threads as well (they will be waiting on the lock)
|
||||
if( !app.Init() )
|
||||
{
|
||||
Winix::RemovePidFile();
|
||||
return 1;
|
||||
}
|
||||
|
||||
app.StartThreads();
|
||||
// now we have more threads, we should use Lock() and Unlock()
|
||||
@@ -173,6 +213,7 @@ using Winix::app;
|
||||
// now all others threads are terminated
|
||||
|
||||
Winix::LogInfo(Winix::log1, "Winix", true, "stopped");
|
||||
Winix::RemovePidFile();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user