Store pid into file also for logd, and adapt startup script to use it.
authorAleš Křenek <ljocha@ics.muni.cz>
Fri, 27 Nov 2009 09:37:22 +0000 (09:37 +0000)
committerAleš Křenek <ljocha@ics.muni.cz>
Fri, 27 Nov 2009 09:37:22 +0000 (09:37 +0000)
Fixes bug #52451.

org.glite.lb.logger/config/startup
org.glite.lb.logger/doc/glite-lb-interlogd.8
org.glite.lb.logger/doc/glite-lb-logd.8
org.glite.lb.logger/src/logd.c

index c48d52a..9104144 100755 (executable)
@@ -12,6 +12,9 @@ GLITE_LOCATION_VAR=${GLITE_LOCATION_VAR:-$GLITE_LOCATION/var}
 
 [ -f $HOME/.glite.conf ] && . $HOME/.glite.conf
 
+LL_PIDFILE=${LL_PIDFILE:-$GLITE_LOCATION_VAR/glite-lb-logd.pid}
+IL_PIDFILE=${IL_PIDFILE:-$GLITE_LOCATION_VAR/glite-lb-interlogd.pid}
+
 unset creds port
 
 start()
@@ -49,21 +52,36 @@ start()
        echo -n Starting glite-lb-logd ...
         (cd /tmp && ls -f /tmp |grep ^dglogd_sock_ |xargs rm -f)
        su - $GLITE_USER -c "$GLITE_LOCATION/bin/glite-lb-logd \
-               $creds $port $sock $fprefix" && echo " done" || echo " FAILED"
+               -i $LL_PIDFILE $creds $port $sock $fprefix" && echo " done" || echo " FAILED"
 
        echo -n Starting glite-lb-interlogd ...
        su - $GLITE_USER -c "$GLITE_LOCATION/bin/glite-lb-interlogd \
-               $creds $sock $fprefix" && echo " done" || echo " FAILED"
+               -i $IL_PIDFILE $creds $sock $fprefix" && echo " done" || echo " FAILED"
+}
+
+killwait()
+{
+       pidfile=$1
+       if [ -f $pidfile ] && pid=`cat $pidfile` && kill $pid 2>/dev/null; then
+               cnt=0
+               while ps p $pid 2>/dev/null >/dev/null; do
+                       sleep 1;
+                       cnt=`expr $cnt + 1`
+                       if [ $cnt = 120 ]; then break; fi
+               done
+               if [ $cnt = 100 ]; then echo " can't stop"
+               else echo " done"; fi
+       else
+               echo " not running"
+       fi
 }
 
 stop()
 {
                echo -n Stopping glite-lb-logd ...
-               killall glite-lb-logd
-               echo " done"
+               killwait $LL_PIDFILE
                echo -n Stopping glite-lb-interlogd ...
-               killall glite-lb-interlogd
-               echo " done"
+               killwait $IL_PIDFILE
 }
 
 status()
index 1f6a013..68ae914 100644 (file)
@@ -138,10 +138,10 @@ Print help and exit.
 .I /tmp/interlogger.sock
 Default name of local socket.
 .TP
-.I /tmp/dglogd.log*
+.I /var/glite/log/dglogd.log*
 Default location of event files.
 
-.I /tmp/dglogd.log*.ctl
+.I /var/glite/log/dglogd.log*.ctl
 Interlogger's control files keeping the information on status of
 the corresponding event file wrt. delivery to the target server.
 
index a28529a..2a04be6 100644 (file)
@@ -82,6 +82,12 @@ Send the messages to interlogger through the UNIX socket
 The value has to be same as used in the cooperating glite-lb-interlogd.
 
 .TP
+.BI \-i " FILE" "\fR,\fP --pidfile " FILE
+Store pid into 
+.I FILE\fR.\fP
+Defaults to /var/glite/glite-lb-logd.pid.
+
+.TP
 .B "-V\fR,\fP --version"
 Print version and exit.
 
@@ -115,7 +121,7 @@ Dangerous, for debugging only! Don't use at all.
 Default name of local socket.
 
 .TP
-.I /tmp/dglogd.log*
+.I /var/glite/log/dglogd.log*
 Default location of the event storage files.
 .TP
 No configuration files needed.
index 9197bad..5556da3 100644 (file)
@@ -13,6 +13,7 @@
 #include <unistd.h> 
 #include <string.h>
 #include <getopt.h>
+#include <assert.h>
 #include <errno.h>
 
 #include "glite/lb/context-int.h"
 #include "glite/lb/lb_perftest.h"
 #endif
 
+#define DEFAULT_PIDFILE "/var/glite/glite-lb-logd.pid"
+
 static const char rcsid[] = "@(#)$Id$";
 static int verbose = 0;
 static int debug = 0;
 static int port = EDG_WLL_LOG_PORT_DEFAULT;
 static char *prefix = EDG_WLL_LOG_PREFIX_DEFAULT;
+static char *pidfile = DEFAULT_PIDFILE;
 static char *cert_file = NULL;
 static char *key_file = NULL;
 static char *CAcert_dir = NULL;
@@ -51,6 +55,7 @@ static struct option const long_options[] = {
        { "cert", required_argument, 0, 'c' },
        { "key", required_argument, 0, 'k' },
        { "CAdir", required_argument, 0, 'C' },
+       { "pidfile",required_argument, 0, 'i' },
        { "socket",required_argument, 0, 's' },
        { "noAuth", no_argument, 0, 'x' },
        { "noIPC", no_argument, 0, 'y' },
@@ -83,6 +88,7 @@ usage(char *program_name) {
                "-k, --key  <file>          location of server private key\n"
                "-C, --CAdir <dir>          directory containing CA certificates\n"
                "-s, --socket <dir>         interlogger's socket to send messages to\n"
+               "-i, --pidfile <file>       pid file\n"
                "--noAuth                   do not check caller's identity\n"
                "--noIPC                    do not send messages to inter-logger\n"
                "--noParse                  do not parse messages for correctness\n",
@@ -133,6 +139,7 @@ void handle_signal(int num) {
                                close(confirm_sock);
                                unlink(confirm_sock_name);
                        }
+                       unlink(pidfile);
                        exit(1);
                        break;
                default: break;
@@ -269,6 +276,7 @@ int main(int argc, char *argv[])
    int ret;
    int childpid;
    int opt;
+   FILE *pidf;
 
    int listener_fd;
    int client_fd;
@@ -299,6 +307,7 @@ This is LocalLogger, part of Workload Management System in EU DataGrid & EGEE.\n
        "k:" /* key */
        "C:" /* CA dir */
        "s:" /* socket */
+       "i:" /* pidfile */
        "x"  /* noAuth */
        "y"  /* noIPC */
        "z",  /* noParse */
@@ -314,6 +323,7 @@ This is LocalLogger, part of Workload Management System in EU DataGrid & EGEE.\n
                case 'k': key_file = optarg; break;
                case 'C': CAcert_dir = optarg; break;
                case 's': socket_path = optarg; break;
+               case 'i': pidfile = optarg; break;
                case 'x': noAuth = 1; break;
                case 'y': noIPC = 1; break;
                case 'z': noParse = 1; break;
@@ -397,6 +407,14 @@ This is LocalLogger, part of Workload Management System in EU DataGrid & EGEE.\n
    client_addr_len = sizeof(client_addr);
    bzero((char *) &client_addr, client_addr_len);
 
+/* just try it before deamonizing to be able to complain aloud */
+  if (!(pidf = fopen(pidfile,"w"))) {
+        perror(pidfile);
+        exit(-1);
+  }
+  fclose(pidf);
+
+
    /* daemonize */
    if (debug) {
        edg_wll_ll_log(LOG_INFO,"Running as daemon... [no]\n");
@@ -409,6 +427,10 @@ This is LocalLogger, part of Workload Management System in EU DataGrid & EGEE.\n
        }
    }
 
+  pidf = fopen(pidfile,"w"); assert(pidf); /* XXX */
+  fprintf(pidf,"%d\n",getpid());
+  fclose(pidf);
+
    /*
     * Main loop
     */