mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-15 09:31:45 +00:00
monitor update
This commit is contained in:
committed by
Mohammad Al-Turany
parent
abcc5083f2
commit
13678f9f6d
@@ -9,12 +9,60 @@
|
||||
|
||||
#include <boost/program_options.hpp>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
using namespace boost::program_options;
|
||||
|
||||
static void daemonize()
|
||||
{
|
||||
// already a daemon?
|
||||
// if (getppid() == 1) return;
|
||||
|
||||
// Fork off the parent process
|
||||
// pid_t pid = fork();
|
||||
// if (pid < 0) exit(1);
|
||||
|
||||
// If we got a good PID, then we can exit the parent process.
|
||||
// if (pid > 0) exit(0);
|
||||
|
||||
// Change the file mode mask
|
||||
umask(0);
|
||||
|
||||
// Create a new SID for the child process
|
||||
if (setsid() < 0)
|
||||
{
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// Change the current working directory. This prevents the current directory from being locked; hence not being able to remove it.
|
||||
if ((chdir("/")) < 0)
|
||||
{
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// Redirect standard files to /dev/null
|
||||
if (!freopen("/dev/null", "r", stdin))
|
||||
{
|
||||
cout << "could not redirect stdin to /dev/null" << endl;
|
||||
}
|
||||
if (!freopen("/dev/null", "w", stdout))
|
||||
{
|
||||
cout << "could not redirect stdout to /dev/null" << endl;
|
||||
}
|
||||
if (!freopen("/dev/null", "w", stderr))
|
||||
{
|
||||
cout << "could not redirect stderr to /dev/null" << endl;
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
try
|
||||
@@ -24,15 +72,19 @@ int main(int argc, char** argv)
|
||||
bool selfDestruct = false;
|
||||
bool interactive = false;
|
||||
unsigned int timeoutInMS;
|
||||
bool runAsDaemon = false;
|
||||
bool cleanOnExit = false;
|
||||
|
||||
options_description desc("Options");
|
||||
desc.add_options()
|
||||
("session", value<string>(&sessionName)->default_value("default"), "Name of the session which to monitor")
|
||||
("cleanup", value<bool>(&cleanup)->implicit_value(true), "Perform cleanup and quit")
|
||||
("self-destruct", value<bool>(&selfDestruct)->implicit_value(true), "Quit after first closing of the memory")
|
||||
("interactive", value<bool>(&interactive)->implicit_value(true), "Interactive run")
|
||||
("timeout", value<unsigned int>(&timeoutInMS)->default_value(5000), "Heartbeat timeout in milliseconds")
|
||||
("help", "Print help");
|
||||
("session,s", value<string>(&sessionName)->default_value("default"), "Name of the session which to monitor")
|
||||
("cleanup,c", value<bool>(&cleanup)->implicit_value(true), "Perform cleanup and quit")
|
||||
("self-destruct,x", value<bool>(&selfDestruct)->implicit_value(true), "Quit after first closing of the memory")
|
||||
("interactive,i", value<bool>(&interactive)->implicit_value(true), "Interactive run")
|
||||
("timeout,t", value<unsigned int>(&timeoutInMS)->default_value(5000), "Heartbeat timeout in milliseconds")
|
||||
("daemonize,d", value<bool>(&runAsDaemon)->implicit_value(true), "Daemonize the monitor")
|
||||
("clean-on-exit,e", value<bool>(&cleanOnExit)->implicit_value(true), "Perform cleanup on exit")
|
||||
("help,h", "Print help");
|
||||
|
||||
variables_map vm;
|
||||
store(parse_command_line(argc, argv, desc), vm);
|
||||
@@ -47,6 +99,11 @@ int main(int argc, char** argv)
|
||||
|
||||
sessionName.resize(8, '_'); // shorten the session name, to accommodate for name size limit on some systems (MacOS)
|
||||
|
||||
if (runAsDaemon)
|
||||
{
|
||||
daemonize();
|
||||
}
|
||||
|
||||
if (cleanup)
|
||||
{
|
||||
cout << "Cleaning up \"" << sessionName << "\"..." << endl;
|
||||
@@ -57,7 +114,7 @@ int main(int argc, char** argv)
|
||||
|
||||
cout << "Starting shared memory monitor for session: \"" << sessionName << "\"..." << endl;
|
||||
|
||||
fair::mq::shmem::Monitor monitor{sessionName, selfDestruct, interactive, timeoutInMS};
|
||||
fair::mq::shmem::Monitor monitor{sessionName, selfDestruct, interactive, timeoutInMS, runAsDaemon, cleanOnExit};
|
||||
|
||||
monitor.CatchSignals();
|
||||
monitor.Run();
|
||||
|
Reference in New Issue
Block a user