[ -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()
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()
#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;
{ "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' },
"-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",
close(confirm_sock);
unlink(confirm_sock_name);
}
+ unlink(pidfile);
exit(1);
break;
default: break;
int ret;
int childpid;
int opt;
+ FILE *pidf;
int listener_fd;
int client_fd;
"k:" /* key */
"C:" /* CA dir */
"s:" /* socket */
+ "i:" /* pidfile */
"x" /* noAuth */
"y" /* noIPC */
"z", /* noParse */
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;
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");
}
}
+ pidf = fopen(pidfile,"w"); assert(pidf); /* XXX */
+ fprintf(pidf,"%d\n",getpid());
+ fclose(pidf);
+
/*
* Main loop
*/