Commit 52ed14894dbbba9b02497135ffe2d406c58a2030
1 parent
a2a24843
Add gammalibd launcher executable and launch daemon in GammaLib initialisation script (#3592)
Showing
8 changed files
with
119 additions
and
6 deletions
.gitignore
ChangeLog
NEWS
| 1 | 1 | New Features and Important Changes in GammaLib 2.0.0 |
| 2 | 2 | |
| 3 | -20 February 2022 | |
| 3 | +24 February 2022 | |
| 4 | 4 | |
| 5 | 5 | |
| 6 | 6 | 1. Introduction |
| ... | ... | @@ -422,7 +422,9 @@ were added to compute the total solid angle within specified sky region(s) (#178 |
| 422 | 422 | Added GDaemon class that implements the GammaLib daemon. The GammaLib daemon collects |
| 423 | 423 | on a regular basis low-level application statistics and generates from this information |
| 424 | 424 | high-level statistics on a daily basis. This avoids that the low-level statistics |
| 425 | -file becomes too large (#3592). | |
| 425 | +file becomes too large. I also added a daemon launcher gammalibd to will be called | |
| 426 | +when initialising gammalib. In addition, any instantiation of a GApplication object | |
| 427 | +will eventually launch the daemon (#3592). | |
| 426 | 428 | |
| 427 | 429 | Added gammalib::gamma_filename() method that returns the full path for a filename in |
| 428 | 430 | the users's .gamma directory. | ... | ... |
README.md
| 1 | 1 | GammaLib information |
| 2 | 2 | ==================== |
| 3 | -* Version: 2.0.0.dev (20 February 2022) | |
| 3 | +* Version: 2.0.0.dev (24 February 2022) | |
| 4 | 4 | |
| 5 | 5 | [](https://cta-jenkins.irap.omp.eu/job/gammalib-integrate-os/) |
| 6 | 6 | ... | ... |
src/Makefile.am
| 1 | 1 | ############################################################################# |
| 2 | 2 | # Makefile.am for source module # |
| 3 | 3 | # ------------------------------------------------------------------------- # |
| 4 | -# Copyright (C) 2016-2020 Juergen Knoedlseder # | |
| 4 | +# Copyright (C) 2016-2022 Juergen Knoedlseder # | |
| 5 | 5 | # ------------------------------------------------------------------------- # |
| 6 | 6 | # # |
| 7 | 7 | # This program is free software: you can redistribute it and/or modify # |
| ... | ... | @@ -69,6 +69,9 @@ scripts = gammalib-setup \ |
| 69 | 69 | gammalib-init.sh \ |
| 70 | 70 | gammalib-init.csh |
| 71 | 71 | |
| 72 | +# Program name | |
| 73 | +bin_PROGRAMS = gammalibd | |
| 74 | + | |
| 72 | 75 | # Build libtool library |
| 73 | 76 | lib_LTLIBRARIES = libgamma.la |
| 74 | 77 | libgamma_la_SOURCES = $(sources) |
| ... | ... | @@ -93,11 +96,22 @@ libgamma_la_LIBADD = $(top_builddir)/src/base/libbase.la \ |
| 93 | 96 | $(INST_COM) |
| 94 | 97 | libgamma_la_LDFLAGS = -version-info $(GAMMALIB_LT_VERSION) @OPENMP_LIB_LDFLAGS@ |
| 95 | 98 | |
| 99 | +# Program definition | |
| 100 | +gammalibd_SOURCES = gammalibd.cpp | |
| 101 | +gammalibd_LDFLAGS = @LDFLAGS@ | |
| 102 | +gammalibd_CPPFLAGS = @CPPFLAGS@ | |
| 103 | +gammalibd_LDADD = $(top_builddir)/src/libgamma.la | |
| 104 | +gammalibd_DEPENDENCIES = libgamma.la | |
| 105 | + | |
| 96 | 106 | # Distribute scripts |
| 97 | 107 | EXTRA_DIST = $(scripts) |
| 98 | 108 | scriptsdir = $(bindir) |
| 99 | 109 | scripts_DATA = $(scripts) |
| 100 | 110 | |
| 111 | +# Add rule to launch daemon prior to unit testing | |
| 112 | +check-local: | |
| 113 | + nohup gammalibd </dev/null &>/dev/null & | |
| 114 | + | |
| 101 | 115 | # Add hook rule to make scripts executable |
| 102 | 116 | install-data-hook: |
| 103 | 117 | @list='$(scripts_DATA)';\ | ... | ... |
src/gammalib-setup.in
| ... | ... | @@ -192,3 +192,8 @@ elif [ $flavor = csh ]; then |
| 192 | 192 | done |
| 193 | 193 | echo "$gammalib_config$$.csh" |
| 194 | 194 | fi |
| 195 | + | |
| 196 | +# | |
| 197 | +# Start gammalib daemon (will do nothing if a daemon is already running) | |
| 198 | +# ====================================================================== | |
| 199 | +nohup gammalibd </dev/null &>/dev/null & | ... | ... |
src/gammalibd.cpp
0 → 100644
| 1 | +/*************************************************************************** | |
| 2 | + * gammalibd.cpp - GammaLib daemon launcher * | |
| 3 | + * ----------------------------------------------------------------------- * | |
| 4 | + * copyright (C) 2022 by Juergen Knoedlseder * | |
| 5 | + * ----------------------------------------------------------------------- * | |
| 6 | + * * | |
| 7 | + * This program is free software: you can redistribute it and/or modify * | |
| 8 | + * it under the terms of the GNU General Public License as published by * | |
| 9 | + * the Free Software Foundation, either version 3 of the License, or * | |
| 10 | + * (at your option) any later version. * | |
| 11 | + * * | |
| 12 | + * This program is distributed in the hope that it will be useful, * | |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of * | |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | |
| 15 | + * GNU General Public License for more details. * | |
| 16 | + * * | |
| 17 | + * You should have received a copy of the GNU General Public License * | |
| 18 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. * | |
| 19 | + * * | |
| 20 | + ***************************************************************************/ | |
| 21 | +/** | |
| 22 | + * @file gammalibd.cpp | |
| 23 | + * @brief GammaLib daemon launcher | |
| 24 | + * @author Juergen Knoedlseder | |
| 25 | + */ | |
| 26 | + | |
| 27 | +/* __ Includes ___________________________________________________________ */ | |
| 28 | +#ifdef HAVE_CONFIG_H | |
| 29 | +#include <config.h> | |
| 30 | +#endif | |
| 31 | +#include <fcntl.h> // for file locking | |
| 32 | +#include <unistd.h> // access() function | |
| 33 | +#include <cstdlib> // exit() function | |
| 34 | +#include <cstdio> // std::fopen(), etc. functions | |
| 35 | +#include <signal.h> // signal() function | |
| 36 | +#include "GammaLib.hpp" // make GammaLib classes available | |
| 37 | + | |
| 38 | + | |
| 39 | +/***********************************************************************//** | |
| 40 | + * @brief GammaLib daemon launcher | |
| 41 | + * | |
| 42 | + * This executable launched the GammaLib daemon. The code is a copy of the | |
| 43 | + * code implemented in the GApplication::start_daemon() method. Calling this | |
| 44 | + * executable during the initialisation of GammaLib will launch a daemon | |
| 45 | + * that is independent of any specific application, and that has the correct | |
| 46 | + * process name on all platforms. | |
| 47 | + ***************************************************************************/ | |
| 48 | +int main(void) { | |
| 49 | + | |
| 50 | + // Initialise daemon | |
| 51 | + GDaemon daemon; | |
| 52 | + | |
| 53 | + // If daemon is not alive then create instance | |
| 54 | + if (!daemon.alive()) { | |
| 55 | + | |
| 56 | + // Create child process to start the daemon. Do nothing if child | |
| 57 | + // process creation fails. | |
| 58 | + int pid = fork(); | |
| 59 | + if (pid >= 0) { | |
| 60 | + | |
| 61 | + // If we have a PID of 0 we are in the child process. In this | |
| 62 | + // case we create and start the daemon ... | |
| 63 | + if (pid == 0) { | |
| 64 | + | |
| 65 | + // The child process becomes session leader | |
| 66 | + setsid(); | |
| 67 | + | |
| 68 | + // Ignore signals | |
| 69 | + signal(SIGCHLD, SIG_IGN); // Ignore if child has stopped | |
| 70 | + signal(SIGHUP, SIG_IGN); // Ignore death of controlling process | |
| 71 | + | |
| 72 | + // Fork for the second time and let the first fork | |
| 73 | + // process terminate | |
| 74 | + pid = fork(); | |
| 75 | + if (pid >= 0) { | |
| 76 | + if (pid == 0) { | |
| 77 | + GDaemon daemon; | |
| 78 | + daemon.start(); | |
| 79 | + exit(EXIT_SUCCESS); | |
| 80 | + } | |
| 81 | + } // endif: child of child process created | |
| 82 | + | |
| 83 | + } | |
| 84 | + | |
| 85 | + } // endif: child proces created | |
| 86 | + | |
| 87 | + } // endif: daemon | |
| 88 | + | |
| 89 | + // Always exit with success | |
| 90 | + return EXIT_SUCCESS; | |
| 91 | +} | ... | ... |
src/support/Makefile.am