mirror of https://gitee.com/bigwinds/arangodb
added process title for supervisor
This commit is contained in:
parent
58d29a78ef
commit
5ffff9edc4
|
@ -48,7 +48,7 @@ using namespace triagens::arango;
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int main (int argc, char* argv[]) {
|
||||
TRIAGENS_RESULT_GENERATOR_INITIALISE;
|
||||
TRIAGENS_RESULT_GENERATOR_INITIALISE(argc, argv);
|
||||
TRI_InitialiseVocBase();
|
||||
|
||||
// create and start a ArangoDB server
|
||||
|
|
|
@ -516,7 +516,7 @@ static void RunShell (mrb_state* mrb) {
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int main (int argc, char* argv[]) {
|
||||
TRIAGENS_C_INITIALISE;
|
||||
TRIAGENS_C_INITIALISE(argc, argv);
|
||||
TRI_InitialiseLogging(false);
|
||||
int ret = EXIT_SUCCESS;
|
||||
|
||||
|
|
|
@ -227,7 +227,7 @@ static void ParseProgramOptions (int argc, char* argv[]) {
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int main (int argc, char* argv[]) {
|
||||
TRIAGENS_C_INITIALISE;
|
||||
TRIAGENS_C_INITIALISE(argc, argv);
|
||||
TRI_InitialiseLogging(false);
|
||||
int ret = EXIT_SUCCESS;
|
||||
|
||||
|
|
|
@ -1141,7 +1141,7 @@ static void addColors (v8::Handle<v8::Context> context) {
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int main (int argc, char* argv[]) {
|
||||
TRIAGENS_C_INITIALISE;
|
||||
TRIAGENS_C_INITIALISE(argc, argv);
|
||||
TRI_InitialiseLogging(false);
|
||||
int ret = EXIT_SUCCESS;
|
||||
|
||||
|
|
|
@ -43,8 +43,8 @@
|
|||
|
||||
namespace triagens {
|
||||
namespace basics {
|
||||
void InitialiseBasics () {
|
||||
TRIAGENS_C_INITIALISE;
|
||||
void InitialiseBasics (int argv, char* argc[]) {
|
||||
TRIAGENS_C_INITIALISE(argv, argc);
|
||||
|
||||
Random::random_e v = Random::selectVersion(Random::RAND_MERSENNE);
|
||||
Random::UniformInteger random(0,1);
|
||||
|
|
|
@ -42,7 +42,7 @@ namespace triagens {
|
|||
/// @brief initialise function
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
extern void InitialiseBasics ();
|
||||
extern void InitialiseBasics (int argv, char* argc[]);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief shutdown function
|
||||
|
@ -56,9 +56,9 @@ namespace triagens {
|
|||
/// @brief initialise
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#define TRIAGENS_BASICS_INITIALISE \
|
||||
do { \
|
||||
triagens::basics::InitialiseBasics(); \
|
||||
#define TRIAGENS_BASICS_INITIALISE(a,b) \
|
||||
do { \
|
||||
triagens::basics::InitialiseBasics((a), (b)); \
|
||||
} while (0)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
|
||||
#include "BasicsC/hashes.h"
|
||||
#include "BasicsC/logging.h"
|
||||
#include "BasicsC/process-utils.h"
|
||||
#include "BasicsC/random.h"
|
||||
#include "BasicsC/socket-utils.h"
|
||||
|
||||
|
@ -47,12 +48,13 @@
|
|||
/// @brief initialise function
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void TRI_InitialiseC () {
|
||||
void TRI_InitialiseC (int argc, char* argv[]) {
|
||||
TRI_InitialiseMemory();
|
||||
TRI_InitialiseError();
|
||||
TRI_InitialiseLogging(true);
|
||||
TRI_InitialiseHashes();
|
||||
TRI_InitialiseRandom();
|
||||
TRI_InitialiseProcess(argc, argv);
|
||||
TRI_InitialiseSockets();
|
||||
|
||||
LOG_TRACE("%s", "$Revision: BASICS-C " TRIAGENS_VERSION " (c) triAGENS GmbH $");
|
||||
|
@ -68,6 +70,7 @@ void TRI_InitialiseC () {
|
|||
|
||||
void TRI_ShutdownC () {
|
||||
TRI_ShutdownSockets();
|
||||
TRI_ShutdownProcess();
|
||||
TRI_ShutdownRandom();
|
||||
TRI_ShutdownHashes();
|
||||
TRI_ShutdownLogging();
|
||||
|
|
|
@ -47,7 +47,7 @@ extern "C" {
|
|||
/// @brief initialise function
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void TRI_InitialiseC (void);
|
||||
void TRI_InitialiseC (int argc, char* argv[]);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief shutdown function
|
||||
|
@ -59,9 +59,9 @@ void TRI_ShutdownC (void);
|
|||
/// @brief initialise
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#define TRIAGENS_C_INITIALISE \
|
||||
do { \
|
||||
TRI_InitialiseC(); \
|
||||
#define TRIAGENS_C_INITIALISE(a,b) \
|
||||
do { \
|
||||
TRI_InitialiseC((a), (b)); \
|
||||
} while (0)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -27,6 +27,9 @@
|
|||
|
||||
#include "process-utils.h"
|
||||
|
||||
#include "BasicsC/strings.h"
|
||||
#include "BasicsC/logging.h"
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --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
|
||||
// -----------------------------------------------------------------------------
|
||||
|
@ -261,6 +307,92 @@ uint64_t TRI_ProcessSize (TRI_pid_t pid) {
|
|||
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);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -125,6 +125,41 @@ uint64_t TRI_ProcessSizeSelf (void);
|
|||
|
||||
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);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -79,7 +79,7 @@ uint32_t TRI_UInt32Random (void);
|
|||
void TRI_InitialiseRandom (void);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief shut downs the logging components
|
||||
/// @brief shut downs the random components
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void TRI_ShutdownRandom (void);
|
||||
|
|
|
@ -37,9 +37,10 @@
|
|||
#include <fstream>
|
||||
|
||||
#include "ApplicationServer/ApplicationServer.h"
|
||||
#include <Basics/FileUtils.h>
|
||||
#include <Basics/safe_cast.h>
|
||||
#include <Logger/Logger.h>
|
||||
#include "Basics/FileUtils.h"
|
||||
#include "Basics/safe_cast.h"
|
||||
#include "BasicsC/process-utils.h"
|
||||
#include "Logger/Logger.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace triagens;
|
||||
|
@ -364,6 +365,14 @@ int AnyServer::startupSupervisor () {
|
|||
|
||||
// parent
|
||||
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;
|
||||
waitpid(pid, &status, 0);
|
||||
|
||||
|
@ -471,6 +480,9 @@ int AnyServer::startupDaemon () {
|
|||
|
||||
// main process
|
||||
if (result == 0) {
|
||||
#ifdef TRI_HAVE_SYS_PRCTL_H
|
||||
prctl(PR_SET_NAME, "arangodb [daemon]", 0, 0, 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
// child process
|
||||
|
|
|
@ -111,8 +111,8 @@ namespace {
|
|||
|
||||
namespace triagens {
|
||||
namespace rest {
|
||||
void InitialiseRest () {
|
||||
TRIAGENS_BASICS_INITIALISE;
|
||||
void InitialiseRest (int argc, char* argv[]) {
|
||||
TRIAGENS_BASICS_INITIALISE(argc, argv);
|
||||
|
||||
TRI_InitialiseUrl();
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ namespace triagens {
|
|||
/// @brief initialise function
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
extern void InitialiseRest ();
|
||||
extern void InitialiseRest (int argc, char* argv[]);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief shutdown function
|
||||
|
@ -56,9 +56,9 @@ namespace triagens {
|
|||
/// @brief initialise
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#define TRIAGENS_REST_INITIALISE \
|
||||
do { \
|
||||
triagens::rest::InitialiseRest(); \
|
||||
#define TRIAGENS_REST_INITIALISE(a,b) \
|
||||
do { \
|
||||
triagens::rest::InitialiseRest((a), (b)); \
|
||||
} while (0)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -37,8 +37,8 @@
|
|||
|
||||
namespace triagens {
|
||||
namespace rest {
|
||||
void InitialiseResultGenerator () {
|
||||
TRIAGENS_REST_INITIALISE;
|
||||
void InitialiseResultGenerator (int argc, char* argv[]) {
|
||||
TRIAGENS_REST_INITIALISE(argc, argv);
|
||||
|
||||
HtmlResultGenerator::initialise();
|
||||
JsonResultGenerator::initialise();
|
||||
|
|
|
@ -43,9 +43,9 @@
|
|||
/// @brief initialise
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#define TRIAGENS_RESULT_GENERATOR_INITIALISE \
|
||||
do { \
|
||||
triagens::rest::InitialiseResultGenerator(); \
|
||||
#define TRIAGENS_RESULT_GENERATOR_INITIALISE(a,b) \
|
||||
do { \
|
||||
triagens::rest::InitialiseResultGenerator((a), (b)); \
|
||||
} while (0)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -77,7 +77,7 @@ namespace triagens {
|
|||
/// @brief initialise function
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
extern void InitialiseResultGenerator ();
|
||||
extern void InitialiseResultGenerator (int argc, char* argv[]);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief shutdown function
|
||||
|
|
Loading…
Reference in New Issue