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:
parent
8379acdb7f
commit
6614919c13
|
@ -267,6 +267,7 @@ void Config::AssignValues(bool stdout_is_closed)
|
||||||
incorrect_login_cannot_login_treshold = Size(L"incorrect_login_cannot_login_treshold", 20);
|
incorrect_login_cannot_login_treshold = Size(L"incorrect_login_cannot_login_treshold", 20);
|
||||||
incorrect_login_cannot_login_delay = Size(L"incorrect_login_cannot_login_delay", 1800);
|
incorrect_login_cannot_login_delay = Size(L"incorrect_login_cannot_login_delay", 1800);
|
||||||
|
|
||||||
|
pid_file = Text(L"pid_file", L"");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -620,6 +620,10 @@ public:
|
||||||
// will be taken accordingly
|
// will be taken accordingly
|
||||||
size_t incorrect_login_cannot_login_delay;
|
size_t incorrect_login_cannot_login_delay;
|
||||||
|
|
||||||
|
// pid file (a full path to a pid file)
|
||||||
|
// default: empty which means there is not a pid file used
|
||||||
|
// pid file is saved after winix has dropped privileges
|
||||||
|
std::wstring pid_file;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -10,14 +10,17 @@
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <unistd.h>
|
||||||
#include "core/log.h"
|
#include "core/log.h"
|
||||||
#include "core/slog.h"
|
#include "core/slog.h"
|
||||||
#include "core/app.h"
|
#include "core/app.h"
|
||||||
#include "core/plugin.h"
|
#include "core/plugin.h"
|
||||||
#include "core/version.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
|
} // namespace Winix
|
||||||
|
|
||||||
|
|
||||||
|
@ -140,8 +177,8 @@ using Winix::app;
|
||||||
return 3;
|
return 3;
|
||||||
|
|
||||||
app.LogUserGroups();
|
app.LogUserGroups();
|
||||||
|
|
||||||
Winix::log << Winix::log3 << "base_url: " << app.config.base_url << Winix::logend;
|
Winix::log << Winix::log3 << "base_url: " << app.config.base_url << Winix::logend;
|
||||||
|
Winix::SavePidFile();
|
||||||
|
|
||||||
// load plugins before loading sessions - session_manager.LoadSessions()
|
// load plugins before loading sessions - session_manager.LoadSessions()
|
||||||
// because some of the plugins can init its own sessions dates
|
// 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)
|
// app.Init() starts other threads as well (they will be waiting on the lock)
|
||||||
if( !app.Init() )
|
if( !app.Init() )
|
||||||
|
{
|
||||||
|
Winix::RemovePidFile();
|
||||||
return 1;
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
app.StartThreads();
|
app.StartThreads();
|
||||||
// now we have more threads, we should use Lock() and Unlock()
|
// now we have more threads, we should use Lock() and Unlock()
|
||||||
|
@ -173,6 +213,7 @@ using Winix::app;
|
||||||
// now all others threads are terminated
|
// now all others threads are terminated
|
||||||
|
|
||||||
Winix::LogInfo(Winix::log1, "Winix", true, "stopped");
|
Winix::LogInfo(Winix::log1, "Winix", true, "stopped");
|
||||||
|
Winix::RemovePidFile();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue