1
0
Fork 0

added process title for supervisor

This commit is contained in:
Frank Celler 2012-07-11 10:46:04 +02:00
parent 58d29a78ef
commit 5ffff9edc4
16 changed files with 213 additions and 31 deletions

View File

@ -48,7 +48,7 @@ using namespace triagens::arango;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int main (int argc, char* argv[]) { int main (int argc, char* argv[]) {
TRIAGENS_RESULT_GENERATOR_INITIALISE; TRIAGENS_RESULT_GENERATOR_INITIALISE(argc, argv);
TRI_InitialiseVocBase(); TRI_InitialiseVocBase();
// create and start a ArangoDB server // create and start a ArangoDB server

View File

@ -516,7 +516,7 @@ static void RunShell (mrb_state* mrb) {
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int main (int argc, char* argv[]) { int main (int argc, char* argv[]) {
TRIAGENS_C_INITIALISE; TRIAGENS_C_INITIALISE(argc, argv);
TRI_InitialiseLogging(false); TRI_InitialiseLogging(false);
int ret = EXIT_SUCCESS; int ret = EXIT_SUCCESS;

View File

@ -227,7 +227,7 @@ static void ParseProgramOptions (int argc, char* argv[]) {
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int main (int argc, char* argv[]) { int main (int argc, char* argv[]) {
TRIAGENS_C_INITIALISE; TRIAGENS_C_INITIALISE(argc, argv);
TRI_InitialiseLogging(false); TRI_InitialiseLogging(false);
int ret = EXIT_SUCCESS; int ret = EXIT_SUCCESS;

View File

@ -1141,7 +1141,7 @@ static void addColors (v8::Handle<v8::Context> context) {
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int main (int argc, char* argv[]) { int main (int argc, char* argv[]) {
TRIAGENS_C_INITIALISE; TRIAGENS_C_INITIALISE(argc, argv);
TRI_InitialiseLogging(false); TRI_InitialiseLogging(false);
int ret = EXIT_SUCCESS; int ret = EXIT_SUCCESS;

View File

@ -43,8 +43,8 @@
namespace triagens { namespace triagens {
namespace basics { namespace basics {
void InitialiseBasics () { void InitialiseBasics (int argv, char* argc[]) {
TRIAGENS_C_INITIALISE; TRIAGENS_C_INITIALISE(argv, argc);
Random::random_e v = Random::selectVersion(Random::RAND_MERSENNE); Random::random_e v = Random::selectVersion(Random::RAND_MERSENNE);
Random::UniformInteger random(0,1); Random::UniformInteger random(0,1);

View File

@ -42,7 +42,7 @@ namespace triagens {
/// @brief initialise function /// @brief initialise function
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
extern void InitialiseBasics (); extern void InitialiseBasics (int argv, char* argc[]);
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @brief shutdown function /// @brief shutdown function
@ -56,9 +56,9 @@ namespace triagens {
/// @brief initialise /// @brief initialise
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
#define TRIAGENS_BASICS_INITIALISE \ #define TRIAGENS_BASICS_INITIALISE(a,b) \
do { \ do { \
triagens::basics::InitialiseBasics(); \ triagens::basics::InitialiseBasics((a), (b)); \
} while (0) } while (0)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////

View File

@ -29,6 +29,7 @@
#include "BasicsC/hashes.h" #include "BasicsC/hashes.h"
#include "BasicsC/logging.h" #include "BasicsC/logging.h"
#include "BasicsC/process-utils.h"
#include "BasicsC/random.h" #include "BasicsC/random.h"
#include "BasicsC/socket-utils.h" #include "BasicsC/socket-utils.h"
@ -47,12 +48,13 @@
/// @brief initialise function /// @brief initialise function
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void TRI_InitialiseC () { void TRI_InitialiseC (int argc, char* argv[]) {
TRI_InitialiseMemory(); TRI_InitialiseMemory();
TRI_InitialiseError(); TRI_InitialiseError();
TRI_InitialiseLogging(true); TRI_InitialiseLogging(true);
TRI_InitialiseHashes(); TRI_InitialiseHashes();
TRI_InitialiseRandom(); TRI_InitialiseRandom();
TRI_InitialiseProcess(argc, argv);
TRI_InitialiseSockets(); TRI_InitialiseSockets();
LOG_TRACE("%s", "$Revision: BASICS-C " TRIAGENS_VERSION " (c) triAGENS GmbH $"); LOG_TRACE("%s", "$Revision: BASICS-C " TRIAGENS_VERSION " (c) triAGENS GmbH $");
@ -68,6 +70,7 @@ void TRI_InitialiseC () {
void TRI_ShutdownC () { void TRI_ShutdownC () {
TRI_ShutdownSockets(); TRI_ShutdownSockets();
TRI_ShutdownProcess();
TRI_ShutdownRandom(); TRI_ShutdownRandom();
TRI_ShutdownHashes(); TRI_ShutdownHashes();
TRI_ShutdownLogging(); TRI_ShutdownLogging();

View File

@ -47,7 +47,7 @@ extern "C" {
/// @brief initialise function /// @brief initialise function
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void TRI_InitialiseC (void); void TRI_InitialiseC (int argc, char* argv[]);
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @brief shutdown function /// @brief shutdown function
@ -59,9 +59,9 @@ void TRI_ShutdownC (void);
/// @brief initialise /// @brief initialise
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
#define TRIAGENS_C_INITIALISE \ #define TRIAGENS_C_INITIALISE(a,b) \
do { \ do { \
TRI_InitialiseC(); \ TRI_InitialiseC((a), (b)); \
} while (0) } while (0)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////

View File

@ -27,6 +27,9 @@
#include "process-utils.h" #include "process-utils.h"
#include "BasicsC/strings.h"
#include "BasicsC/logging.h"
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// --SECTION-- private types // --SECTION-- private types
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@ -111,6 +114,49 @@ process_state_t;
/// @} /// @}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// -----------------------------------------------------------------------------
// --SECTION-- private variables
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @addtogroup SystemProcess
/// @{
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// @brief original process name
////////////////////////////////////////////////////////////////////////////////
static char* ProcessName = 0;
////////////////////////////////////////////////////////////////////////////////
/// @brief argc
////////////////////////////////////////////////////////////////////////////////
static int ARGC = 0;
////////////////////////////////////////////////////////////////////////////////
/// @brief argv
////////////////////////////////////////////////////////////////////////////////
static char** ARGV = 0;
////////////////////////////////////////////////////////////////////////////////
/// @brief true, if environment has been copied already
////////////////////////////////////////////////////////////////////////////////
static bool IsEnvironmentEnlarged = false;
////////////////////////////////////////////////////////////////////////////////
/// @brief maximal size of the process title
////////////////////////////////////////////////////////////////////////////////
static size_t MaximalProcessTitleSize = 0;
////////////////////////////////////////////////////////////////////////////////
/// @}
////////////////////////////////////////////////////////////////////////////////
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// --SECTION-- public functions // --SECTION-- public functions
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@ -261,6 +307,92 @@ uint64_t TRI_ProcessSize (TRI_pid_t pid) {
return TRI_ProcessInfo(pid)._virtualSize; return TRI_ProcessInfo(pid)._virtualSize;
} }
////////////////////////////////////////////////////////////////////////////////
/// @brief sets the process name
////////////////////////////////////////////////////////////////////////////////
extern char** environ;
void TRI_SetProcessTitle (char const* title) {
if (! IsEnvironmentEnlarged) {
size_t size;
int envLen = -1;
if (environ) {
while (environ[++envLen]) {
;
}
}
if (envLen > 0) {
size = environ[envLen-1] + strlen(environ[envLen-1]) - ARGV[0];
}
else {
size = ARGV[ARGC-1] + strlen(ARGV[ARGC-1]) - ARGV[0];
}
if (environ) {
char **newEnviron = malloc(envLen*sizeof(char *));
unsigned int i = -1;
while (environ[++i]) {
newEnviron[i] = strdup(environ[i]);
}
environ = newEnviron;
}
IsEnvironmentEnlarged = true;
MaximalProcessTitleSize = size;
}
if (0 < MaximalProcessTitleSize) {
char* args = ARGV[0];
memset(args, '\0', MaximalProcessTitleSize);
snprintf(args, MaximalProcessTitleSize - 1, "%s", title);
}
}
// -----------------------------------------------------------------------------
// --SECTION-- MODULE
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// --SECTION-- public functions
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @addtogroup SystemProcess
/// @{
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// @brief initialises the process components
////////////////////////////////////////////////////////////////////////////////
void TRI_InitialiseProcess (int argc, char* argv[]) {
if (ProcessName != 0) {
return;
}
ProcessName = TRI_DuplicateString(argv[0]);
ARGC = argc;
ARGV = argv;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief shut downs the process components
////////////////////////////////////////////////////////////////////////////////
void TRI_ShutdownProcess () {
TRI_FreeString(TRI_CORE_MEM_ZONE, ProcessName);
}
////////////////////////////////////////////////////////////////////////////////
/// @}
////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @} /// @}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////

View File

@ -125,6 +125,41 @@ uint64_t TRI_ProcessSizeSelf (void);
uint64_t TRI_ProcessSize (TRI_pid_t pid); uint64_t TRI_ProcessSize (TRI_pid_t pid);
////////////////////////////////////////////////////////////////////////////////
/// @brief sets the process name
////////////////////////////////////////////////////////////////////////////////
void TRI_SetProcessTitle (char const* title);
////////////////////////////////////////////////////////////////////////////////
/// @}
////////////////////////////////////////////////////////////////////////////////
// -----------------------------------------------------------------------------
// --SECTION-- MODULE
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// --SECTION-- public functions
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @addtogroup SystemProcess
/// @{
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// @brief initialises the process components
////////////////////////////////////////////////////////////////////////////////
void TRI_InitialiseProcess (int argc, char* argv[]);
////////////////////////////////////////////////////////////////////////////////
/// @brief shut downs the process components
////////////////////////////////////////////////////////////////////////////////
void TRI_ShutdownProcess (void);
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @} /// @}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////

View File

@ -79,7 +79,7 @@ uint32_t TRI_UInt32Random (void);
void TRI_InitialiseRandom (void); void TRI_InitialiseRandom (void);
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @brief shut downs the logging components /// @brief shut downs the random components
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void TRI_ShutdownRandom (void); void TRI_ShutdownRandom (void);

View File

@ -37,9 +37,10 @@
#include <fstream> #include <fstream>
#include "ApplicationServer/ApplicationServer.h" #include "ApplicationServer/ApplicationServer.h"
#include <Basics/FileUtils.h> #include "Basics/FileUtils.h"
#include <Basics/safe_cast.h> #include "Basics/safe_cast.h"
#include <Logger/Logger.h> #include "BasicsC/process-utils.h"
#include "Logger/Logger.h"
using namespace std; using namespace std;
using namespace triagens; using namespace triagens;
@ -364,6 +365,14 @@ int AnyServer::startupSupervisor () {
// parent // parent
if (pid > 0) { if (pid > 0) {
char const* title = "arangodb [supervisor]";
TRI_SetProcessTitle(title);
#ifdef TRI_HAVE_SYS_PRCTL_H
prctl(PR_SET_NAME, title, 0, 0, 0);
#endif
int status; int status;
waitpid(pid, &status, 0); waitpid(pid, &status, 0);
@ -471,6 +480,9 @@ int AnyServer::startupDaemon () {
// main process // main process
if (result == 0) { if (result == 0) {
#ifdef TRI_HAVE_SYS_PRCTL_H
prctl(PR_SET_NAME, "arangodb [daemon]", 0, 0, 0);
#endif
} }
// child process // child process

View File

@ -111,8 +111,8 @@ namespace {
namespace triagens { namespace triagens {
namespace rest { namespace rest {
void InitialiseRest () { void InitialiseRest (int argc, char* argv[]) {
TRIAGENS_BASICS_INITIALISE; TRIAGENS_BASICS_INITIALISE(argc, argv);
TRI_InitialiseUrl(); TRI_InitialiseUrl();

View File

@ -42,7 +42,7 @@ namespace triagens {
/// @brief initialise function /// @brief initialise function
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
extern void InitialiseRest (); extern void InitialiseRest (int argc, char* argv[]);
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @brief shutdown function /// @brief shutdown function
@ -56,9 +56,9 @@ namespace triagens {
/// @brief initialise /// @brief initialise
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
#define TRIAGENS_REST_INITIALISE \ #define TRIAGENS_REST_INITIALISE(a,b) \
do { \ do { \
triagens::rest::InitialiseRest(); \ triagens::rest::InitialiseRest((a), (b)); \
} while (0) } while (0)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////

View File

@ -37,8 +37,8 @@
namespace triagens { namespace triagens {
namespace rest { namespace rest {
void InitialiseResultGenerator () { void InitialiseResultGenerator (int argc, char* argv[]) {
TRIAGENS_REST_INITIALISE; TRIAGENS_REST_INITIALISE(argc, argv);
HtmlResultGenerator::initialise(); HtmlResultGenerator::initialise();
JsonResultGenerator::initialise(); JsonResultGenerator::initialise();

View File

@ -43,9 +43,9 @@
/// @brief initialise /// @brief initialise
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
#define TRIAGENS_RESULT_GENERATOR_INITIALISE \ #define TRIAGENS_RESULT_GENERATOR_INITIALISE(a,b) \
do { \ do { \
triagens::rest::InitialiseResultGenerator(); \ triagens::rest::InitialiseResultGenerator((a), (b)); \
} while (0) } while (0)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -77,7 +77,7 @@ namespace triagens {
/// @brief initialise function /// @brief initialise function
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
extern void InitialiseResultGenerator (); extern void InitialiseResultGenerator (int argc, char* argv[]);
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @brief shutdown function /// @brief shutdown function