Re: about clustering

[email protected]
Newsgroups gmane.linux.redhat.piranha
Message-ID <[email protected]>

hi Sébastien Bonnet,
             Many  thanks.
            In your last email, you attach the piranha-0.7.0.patch in
email. I save it in a file name piranha-0.7.0.patch. Can you check it for
me that the patch file is correct?
thanks again.
zhou(See attached file: piranha-0.7.0.patch.txt)




[email protected]@redhat.com on 12/19/2002 05:44:39 PM

Please respond to [email protected]

Sent by:  [email protected]


To:   [email protected]
cc:

Subject:  Re: about clustering




hi Sébastien Bonnet,
             Many  thanks.
            In your last email, you attach the piranha-0.7.0.patch in
email. I save it in a file name piranha-0.7.0.patch. Can you check it for
me that the patch file is correct?
thanks again.
zhou






Sébastien Bonnet <[email protected]>@redhat.com on 12/19/2002
05:18:20 PM

Please respond to [email protected]

Sent by:  [email protected]


To:   [email protected]
cc:

Subject:  Re: about clustering


>    Can you tell me or email me again about how to use your patch?

gunzip -c piranha-0.7.0.tgz | tar x
cd piranha
patch -p1 <location-of-patch>/piranha-0.7.0.patch
make
make install

The makefile might create 2 services pulse1 and pulse2 instead of just
pulse. You can "correct" that issue this way:
cd /etc/init.d
mv pulse1 pulse
rm pulse2

Then create a first script that will be called when the director becomes
active (master). In my case, where I use Direct Routing, if removes the
VIPs from lo. The second script is called when the director is started
or becomes inactive (backup). It sets the VIPs on lo and hide them.

If you're using NAT, you'll have still handle the VIPs on lo and the
default gateway instead of the ARP issues. That is :
on the active director, set the DGW to the one of the network
on the inactive director (backup), set the DGW to what you've specified
as nat_router in lvs.cf

I created both scripts in /etc/sysconfig/ha and you'll each a copy of
each attached.


OK, now you have two nice scripts, just make sure they as used. And the
following two lines in the main section of lvs.cf:

active_cmd = /etc/sysconfig/ha/cluster-active.sh
inactive_cmd = /etc/sysconfig/ha/cluster-inactive.sh


Finally, in the list of RS for your VS, list both directors with their
usual, NATed, address.

Regards,

--
Sébastien Bonnet
  Centre de contacts - Experian France
(See attached file: cluster-active.sh)
(See attached file: cluster-inactive.sh)

(See attached file: cluster-active.sh)
(See attached file: cluster-inactive.sh)
piranha-0.7.0.patch.txt (application/octet-stream, 23.4 KB)
diff -Naur piranha.orig/Makefile piranha/Makefile
--- piranha.orig/Makefile	Mon Nov 18 13:46:53 2002
+++ piranha/Makefile	Mon Nov 18 13:47:01 2002
@@ -44,10 +44,12 @@

 COPTS   	=

+XTRA_CFLAGS	= -DUSE_REGEX
+
 ifeq ($(CC),ccc)
-		CFLAGS	= -Wall -g -DVERSION=\"$(VERSION)\" -DRELEASE=\"$(RELEASE)\" -DDATE=\"$(DATE)\" $(COPTS)
+		CFLAGS	= -Wall -g -DVERSION=\"$(VERSION)\" -DRELEASE=\"$(RELEASE)\" -DDATE=\"$(DATE)\" $(XTRA_CFLAGS) $(COPTS)
 else
-		CFLAGS	= -Wall -g -DVERSION=\"$(VERSION)\" -DRELEASE=\"$(RELEASE)\" -DDATE=\"$(DATE)\" $(RPM_OPT_FLAGS) $(COPTS)
+		CFLAGS	= -Wall -g -DVERSION=\"$(VERSION)\" -DRELEASE=\"$(RELEASE)\" -DDATE=\"$(DATE)\" $(XTRA_CFLAGS) $(RPM_OPT_FLAGS) $(COPTS)
 endif

 LDFLAGS   	= -ggdb # -lefence
diff -Naur piranha.orig/fos.c piranha/fos.c
--- piranha.orig/fos.c	Mon Nov 18 13:46:53 2002
+++ piranha/fos.c	Mon Nov 18 13:47:21 2002
@@ -282,10 +282,10 @@
 	*arg++ = (char *) "-c";

 	*arg++ = (char *) "-h";
-	*arg++ = virtAddress;
+	*arg++ = realAddress;

 	*arg++ = (char *) "-V";
-	*arg++ = realAddress;
+	*arg++ = virtAddress;

 	*arg++ = (char *) "-p";
 	*arg++ = portNum;
@@ -300,7 +300,7 @@
 	if (FOserver->send_program) {
 		send_str = strdup (FOserver->send_program);
 		*arg++ = (char *) "-e";
-		*arg++ = strip_quotes (send_program);
+		*arg++ = strip_quotes (send_str);
 	}

 	if (FOserver->send_str) {
@@ -652,7 +652,7 @@
 	}

 	if (flags & LVS_FLAG_ASDAEMON)
-		unlink ("/var/run/fos.pid");
+		removePidFile ();

 	piranha_log (flags, (char *) "will now exit to notify pulse...");

diff -Naur piranha.orig/lvs.c piranha/lvs.c
--- piranha.orig/lvs.c	Mon Nov 18 13:46:53 2002
+++ piranha/lvs.c	Mon Nov 18 13:47:01 2002
@@ -412,6 +412,12 @@

   *arg++ = (char *) "--lvs";

+  /* pass along the real server hostname which might be used */
+  /* by the loadMonitor command */
+
+  *arg++ = (char *) "--servername";
+  *arg++ = service->name;
+
   /* Terminate the command line call */

   *arg++ = NULL;
@@ -452,6 +458,38 @@


 int
+zeroClientMonitor (struct lvsConfig *config,
+		   struct lvsVirtualServer *vserver,
+		   struct lvsService *service,
+		   struct clientInfo *clients,
+		   int *numClientsPtr, int flags)
+{
+
+  int which;
+  struct clientInfo clientInfo;
+
+  clientInfo.vip = vserver->virtualAddress;
+  clientInfo.address = service->address;
+  clientInfo.protocol = vserver->protocol;
+  clientInfo.port = service->port;
+
+  which = findClientInList (clients, *numClientsPtr, &clientInfo);
+
+  if (which == -1)
+    return 0;
+
+  if (clients->clientMonitor != -1)
+    {
+      kill (clients[which].clientMonitor, SIGTSTP);
+    }
+
+  return 0;
+}
+
+
+
+
+int
 shutdownClientMonitor (struct lvsConfig *config,
 		       struct lvsVirtualServer *vserver,
 		       struct lvsService *service,
@@ -699,7 +737,7 @@

   int old, new;
   enum
-  { WHAT_UNKNOWN, WHAT_START, WHAT_STOP, WHAT_SKIP }
+  { WHAT_UNKNOWN, WHAT_START, WHAT_STOP, WHAT_SKIP, WHAT_ZERO }
   what;


@@ -760,7 +798,15 @@
 	       vserver->servers[new].isActive)
 	{
 	  /* old active, new active */
-	  what = WHAT_SKIP;
+	  if (oldVserver->servers[old].weight &&
+	      !vserver->servers[new].weight)
+	    {
+	      what = WHAT_ZERO;
+	    }
+	  else
+	    {
+	      what = WHAT_SKIP;
+	    }

 	}
       else if (!oldVserver->servers[old].isActive &&
@@ -791,6 +837,10 @@
       else if (what == WHAT_STOP)
 	shutdownClientMonitor (config, vserver, vserver->servers + new,
 			       clients, numClientsPtr, flags);
+
+      else if (what == WHAT_ZERO)
+	zeroClientMonitor (config, vserver, vserver->servers + new,
+			   clients, numClientsPtr, flags);
     }

   return 0;
@@ -1044,7 +1094,7 @@
     }

   if (flags & LVS_FLAG_ASDAEMON)
-    unlink ("/var/run/lvs.pid");
+    removePidFile ();

   return 0;
 }
diff -Naur piranha.orig/lvsconfig.c piranha/lvsconfig.c
--- piranha.orig/lvsconfig.c	Mon Nov 18 13:46:53 2002
+++ piranha/lvsconfig.c	Mon Nov 18 13:47:01 2002
@@ -121,6 +121,9 @@
 #define LVS_SAW_BACKUPSHARED        (1 << 21)
 #define LVS_SAW_RCA		    (1 << 22)
 #define LVS_SAW_SERIAL_NO	    (1 << 23)
+#define LVS_SAW_USESYNCDAEMON	    (1 << 24)
+#define LVS_SAW_ACTIVE_CMD          (1 << 25)
+#define LVS_SAW_INACTIVE_CMD        (1 << 26)

 #define LVS_SAW_VS_CLIENTMONITOR    (1 << 1)
 #define LVS_SAW_VS_VIRTUALADDRESS   (1 << 2)
@@ -1526,6 +1529,18 @@
 		}

 	    }
+          else if (TOKEN ("active_cmd"))
+            {
+              CHECK_ARGS (1) free (config->activeCommand);
+                config->activeCommand = strdup (toks.argv[2]);
+              OUTPUT_STR (eConfig, activeCommand, 2, LVS_SAW_ACTIVE_CMD);
+            }
+          else if (TOKEN ("inactive_cmd"))
+            {
+              CHECK_ARGS (1) free (config->inactiveCommand);
+                config->inactiveCommand = strdup (toks.argv[2]);
+              OUTPUT_STR (eConfig, inactiveCommand, 2, LVS_SAW_ACTIVE_CMD);
+            }
 	  else if (TOKEN ("debug_level"))
 	    {
 	      CHECK_ARGS (1) free (config->debug_level);
@@ -1555,6 +1570,12 @@
 	      config->rshCommand = strdup (toks.argv[2]);

 	    OUTPUT_STR (eConfig, rshCommand, 2, LVS_SAW_RSHCOMMAND)}
+	  else if (TOKEN ("syncdaemon"))
+	    {
+	      CHECK_ARGS (1)
+		if ((rc = getBoolean (&config->useSyncDaemon, toks.argv[2])))
+		return rc;
+	    OUTPUT_NUM (eConfig, useSyncDaemon, 2, LVS_SAW_USESYNCDAEMON)}
 	  else if (TOKEN ("heartbeat"))
 	    {
 	      CHECK_ARGS (1)
@@ -1769,6 +1790,14 @@
 			  inet_ntoa (eConfig->natRouter),
 			  eConfig->natRouterDevice);

+	  OUTPUT_MISSING_STR (LVS_SAW_ACTIVE_CMD,
+			      eConfig->activeCommand, "",
+			      "active_cmd = %s\n");
+
+	  OUTPUT_MISSING_STR (LVS_SAW_INACTIVE_CMD,
+			      eConfig->inactiveCommand, "",
+			      "inactive_cmd = %s\n");
+
 	  OUTPUT_MISSING_STR (LVS_SAW_RSHCOMMAND, eConfig->rshCommand,
 			      (char *) "rsh", (char *) "rsh_command = %s\n")
 	    OUTPUT_MISSING_STR (LVS_SAW_DEBUG_LEVEL, eConfig->debug_level,
@@ -1777,6 +1806,9 @@
 	    OUTPUT_MISSING_STR (LVS_SAW_VSADM, eConfig->vsadm,
 				(char *) IPVSADM,
 				(char *) "ipvsadm = %s\n")
+	    OUTPUT_MISSING_NUM (LVS_SAW_USESYNCDAEMON, eConfig->useSyncDaemon,
+				0,
+				(char *) "syncdaemon = %d\n")
 	    OUTPUT_MISSING_NUM (LVS_SAW_USEHEARTBEAT, eConfig->useHeartbeat,
 				0,
 				(char *) "heatbeart = %d\n")
@@ -1946,6 +1978,7 @@
     configFile.lineEnd = NULL;

     /* Set default values */
+    config->useSyncDaemon = 0;
     config->useHeartbeat = 0;
     config->heartbeatPort = 539;
     config->keepAliveTime = 2;
@@ -2079,6 +2112,8 @@
 	FREE(config->vsadm);
 	FREE(config->reserve);
 	FREE(config->reservation_conflict_action);
+	FREE(config->activeCommand);
+	FREE(config->inactiveCommand);

 	for (i = 0; i < config->numVirtServers; i++)
 		lvsFreeVirtServer(config->virtServers + i);
diff -Naur piranha.orig/lvsconfig.h piranha/lvsconfig.h
--- piranha.orig/lvsconfig.h	Mon Nov 18 13:46:53 2002
+++ piranha/lvsconfig.h	Mon Nov 18 13:47:01 2002
@@ -180,6 +180,9 @@
   struct lvsVirtualServer *virtServers;
   struct lvsVirtualServer *failoverServices;
   char *reservation_conflict_action;	/* "preempt" or "nothing" */
+  int useSyncDaemon;
+  char *activeCommand;
+  char *inactiveCommand;
 };

 int lvsParseConfig (int fd, struct lvsConfig *config, int *badLineNum);
diff -Naur piranha.orig/nanny.c piranha/nanny.c
--- piranha.orig/nanny.c	Mon Nov 18 13:46:53 2002
+++ piranha/nanny.c	Mon Nov 18 13:47:01 2002
@@ -139,6 +139,11 @@
 #include <math.h>		/* for pow() */
 #include <time.h>

+#if defined(USE_REGEX)
+	#include <sys/types.h>
+	#include <regex.h>
+#endif
+
 #include "globals.h"
 #include "util.h"
 #include "nanny.h"
@@ -158,13 +163,14 @@

 static int childDead = 0;
 static int gotAlarm = 0;
+static int gotStop  = 0;
 sigjmp_buf killYourself;
 static int nextState = 0;
 pid_t needsKilling = 0;
 int use_udp = 0;
 unsigned int fwmark = 0;

-static const char *http_send_str = "GET / HTTP/1.0\r\n\r\n";
+/* static const char *http_send_str = "GET / HTTP/1.0\r\n\r\n"; */
 /* static const char *http_recv_str = "HTTP"; */
 /* Default send/expect for port 80 */

@@ -189,6 +195,12 @@
 }

 static void
+handleStop (int signal)
+{
+	gotStop = 1;
+}
+
+static void
 changeState (int signal)
 {
 	if (signal == SIGHUP)
@@ -269,6 +281,25 @@
 	struct iphdr *ip;
 #endif

+#if defined(USE_REGEX)
+	static regex_t regExpr;
+	static char regCompiled = 0;
+	char regError[255];
+#endif
+
+#if defined(USE_REGEX)
+	if (!regCompiled) {
+		if ((i = regcomp (&regExpr, expect_str, REG_EXTENDED)) == 0) {
+			regCompiled = 1;
+		} else {
+			regerror (i, &regExpr, regError, sizeof (regError));
+			piranha_log (flags, (char *)
+				     "Error '%s' processing expected regular expression",
+				     regError);
+		}
+	}
+#endif
+
 	if (pingTimeout < 500)
 		pingTimeout = 500;

@@ -502,7 +533,11 @@
 			*/

 			if (expect_str)
+#if defined(USE_REGEX)
+				read_len = sizeof (read_buf) - 1;
+#else
 				read_len = strlen (expect_str);
+#endif
 			else
 				read_len = 1;	/* for UDP */

@@ -555,11 +590,15 @@
 				}

 				if ((read_len == 1) && (*expect_str == '*')) {
+					/* Wildcard */
 					read_buf[0] = '*';
 					read_buf[1] = 0;
 					i = 1;
 				}
-				/* Wildcard */
+#if defined(USE_REGEX)
+				if (!regCompiled || regexec (&regExpr, read_buf, 0, NULL, 0))
+					return_status = 1;
+#else
 				if (i >= read_len) {
 					if (strncmp ((const char *) expect_str,
 						     (const char *) read_buf,
@@ -572,6 +611,7 @@
 						     port);
 					return_status = 1;
 				}
+#endif
 			}
 		}
 	}
@@ -896,29 +936,20 @@

 float
 getRemoteLoad (int flags, struct in_addr *remoteAddr, int timeout,
-	       char *loadCommand)
+	       char *loadCommandArgv[])
 {

-	char *argv[40];
-	char **argp = argv;
 	char *output;
 	char *start, *chptr;
 	float avg;

-	*argp++ = loadCommand;
-	*argp++ = inet_ntoa (*remoteAddr);
-
-	if (strcmp (loadCommand, (char *) "none") == 0)
+	if (strcmp (loadCommandArgv[0], (char *) "none") == 0)
 		/* == 0 per bugzilla #24843 */
 		return -1.0;	/* nothing to see here, go home silently */

-	if (strcmp (loadCommand, (char *) "rup"))
-		*argp++ = (char *) "uptime";
-	*argp++ = NULL;
-
-	logArgv (flags, argv);
+	logArgv (flags, loadCommandArgv);

-	output = getExecOutput (flags, argv, timeout);
+	output = getExecOutput (flags, loadCommandArgv, timeout);

 	if (!output) {
 		piranha_log (flags, (char *) "failed to read remote load");
@@ -965,7 +996,7 @@
 int
 adjustWeight (int flags, char *ipvsadm, char *virtualAddress, int port,
 	      struct in_addr *remoteAddr, char *routingMethod, int weight,
-	      int interval, int scale, char *loadCommand, int lastWeight)
+	      int interval, int scale, char *loadCommandArgv[], int lastWeight)
 {
 	int newWeight;

@@ -994,7 +1025,7 @@

 		load = getRemoteLoad (flags, remoteAddr,
 				      interval,
-				      loadCommand);
+				      loadCommandArgv);

 		if ((load >= 0.0) && (load != 1.0)) {
 			if (load < 1.0) {
@@ -1105,7 +1136,7 @@
 int
 run (int flags, char *ipvsadm, char *virtualAddress, int port,
      struct in_addr *remoteAddr, char *routingMethod, int weight,
-     int interval, int countThresh, int scale, char *loadCommand,
+     int interval, int countThresh, int scale, char *loadCommandArgv[],
      char *send_program, char *send_str, char *expect_str,
      int quiesce_srv, int service_type)
 {
@@ -1129,6 +1160,7 @@
 	sigaddset (&sigs, SIGHUP);
 	sigaddset (&sigs, SIGUSR1);
 	sigaddset (&sigs, SIGUSR2);
+	sigaddset (&sigs, SIGTSTP);
 	sigprocmask (SIG_BLOCK, &sigs, NULL);

 	if (flags & NANNY_FLAG_VERBOSE) {
@@ -1187,6 +1219,7 @@
 	signal (SIGUSR1, changeState);
 	signal (SIGUSR2, changeState);
 	signal (SIGHUP, changeState);
+	signal (SIGTSTP, handleStop);

 	sigfillset (&sigs);
 	sigdelset (&sigs, SIGTERM);
@@ -1195,6 +1228,7 @@
 	sigdelset (&sigs, SIGHUP);
 	sigdelset (&sigs, SIGUSR1);
 	sigdelset (&sigs, SIGUSR2);
+	sigdelset (&sigs, SIGTSTP);

 	/* we keep a single socket for pings */
 	pingSocket = socket (AF_INET, SOCK_RAW, IPPROTO_ICMP);
@@ -1366,12 +1400,27 @@
 					   virtualAddress, port,
 					   remoteAddr, routingMethod,
 					   weight, interval, scale,
-					   loadCommand, lastWeight);
+					   loadCommandArgv, lastWeight);
 			if (rc < 0)
 				return rc;
 			lastWeight = rc;
 		}

+		if (gotStop && (service_type == SERV_LVS) && isActive && isSrvUp) {
+			gotStop = 0;
+			piranha_log (flags, (char *)
+				     "de-activating %s:%d without shutting it down",
+				     inet_ntoa (*remoteAddr), port);
+
+			if (adjustDevice
+			    (flags, ipvsadm,
+			     virtualAddress, port,
+			     remoteAddr, routingMethod, 0))
+				return -1;
+
+			lastWeight = 0;
+		}
+
 		/*
 		**  Monitor loop
 		*/
@@ -1499,15 +1548,20 @@
 	int service_type = SERV_UNK;

 	char *server = NULL;
+	char *servername = NULL;
 	char *virtualAddress = NULL;
 	char *routingMethod = (char *) "-m";
 	char *specifiedRM;
 	char *vsadmPath = (char *) IPVSADM;
-	char *loadCommand = (char *) "rup";
+	char *loadCommand = NULL;
 	char *send_program = NULL;
 	char *send_str = NULL;
 	char *expect_str = NULL;

+	char *loadCommandArgv[40];
+	char **argp = loadCommandArgv;
+	char *token;
+
 	/* Letters taken: DIMRSTUV acnpstuvwx */

 	struct poptOption options[] = {
@@ -1542,6 +1596,9 @@
 		{"server", 'h', POPT_ARG_STRING, &server, 0,
 		 N_("IP address of remote server")},

+		{"servername", '\0', POPT_ARG_STRING, &servername, 0,
+		 N_("Hostname of remote server")},
+
 		{"send_program", 'e', POPT_ARG_STRING, &send_program, 0,
 		 N_("Use an external program to test a service")},

@@ -1715,8 +1772,24 @@
 			     "starting LVS client monitor for %s:%d",
 			     virtualAddress, port);

+	if (loadCommand == NULL)
+		loadCommand = strdup ("none");
+
+	token = strtok (loadCommand, " ");
+	while (token != NULL)
+	{
+		if (!strcmp (token, "%a"))
+			*argp++ = strdup (server);
+		else if (!strcmp (token, "%h") && (servername != NULL))
+			*argp++ = strdup (servername);
+		else
+			*argp++ = strdup (token);
+		token = strtok (NULL, " ");
+	}
+	*argp++ = NULL;
+
 	return run (flags, vsadmPath, virtualAddress, port, &remoteAddr,
 		    routingMethod, weight, interval, countThresh, scale,
-		    loadCommand, send_program, send_str, expect_str,
+		    loadCommandArgv, send_program, send_str, expect_str,
 		    quiesce_srv, service_type);
 }
diff -Naur piranha.orig/pulse.c piranha/pulse.c
--- piranha.orig/pulse.c	Mon Nov 18 13:46:53 2002
+++ piranha/pulse.c	Mon Nov 18 13:47:51 2002
@@ -662,14 +662,6 @@
   if (flags & PULSE_FLAG_NORUN)
     return;

-  if (HA_Process > 0)
-    {
-      kill (HA_Process, SIGTERM);
-      waitpid (HA_Process, NULL, 0);
-      HA_Process = 0;
-    }
-
-
   if (cleanup)
     {
       /* deactivate the interfaces */
@@ -692,6 +684,13 @@
 			      flags);
 	}
     }
+
+  if (HA_Process > 0)
+    {
+      kill (HA_Process, SIGTERM);
+      waitpid (HA_Process, NULL, 0);
+      HA_Process = 0;
+    }
 }


@@ -1137,45 +1136,78 @@
    SHARED SCSI ROUTINES END HERE
 */

+
+
+
+
 /*
-**  activateLvs() -- Start LVS program, then send arps for all VIPs
+** syncDaemon() -- (re)start IPVS synchronisation daemon
 */

-static pid_t
-activateLvs (struct lvsConfig *config, int flags)
+static void
+syncDaemon (struct lvsConfig *config, int flags, int master)
 {

-  pid_t child = 0;
-  pid_t fake1;
-  pid_t *fake = alloca (sizeof (*fake) * (config->numVirtServers + 1));
-  int i;
-  int j;
-  int numFakes;
+  pid_t child;
+  char *ipvsadmArgs[4];

-  char *argv[5];
+  if (config->useSyncDaemon == 0)
+    return;

-  argv[0] = lvsBinary;
-  argv[1] = (char *) "--nodaemon";
-  argv[2] = (char *) "-c";
-  argv[3] = configFile;
-  argv[4] = NULL;
+  ipvsadmArgs[0] = (char *) config->vsadm;
+  ipvsadmArgs[1] = (char *) "--stop-daemon";
+  ipvsadmArgs[2] = NULL;

+  if (pulse_debug)
+    piranha_log (flags,
+		 (char *)
+		 "DEBUG -- Executing 'ipvsadm --stop-daemon'");

-  if (flags & PULSE_FLAG_ASDAEMON)
-    argv[1] = (char *) "--nofork";
+  if (!(child = fork ()))
+    {
+      logArgv (flags, ipvsadmArgs);
+      execv (ipvsadmArgs[0], ipvsadmArgs);
+      exit (-1);
+    }
+
+  waitpid (child, NULL, 0);
+
+  ipvsadmArgs[0] = (char *) config->vsadm;
+  ipvsadmArgs[1] = (char *) "--start-daemon";
+  ipvsadmArgs[2] = (char *) ((master) ? "master" : "backup");
+  ipvsadmArgs[3] = NULL;

   if (pulse_debug)
-    logArgv (flags, argv);
+    piranha_log (flags,
+		 (char *)
+		 "DEBUG -- Executing 'ipvsadm --start-daemon %s'", ipvsadmArgs[2]);

-  if (!(flags & PULSE_FLAG_NORUN))
+  if (!(child = fork ()))
     {
-      if (!(child = fork ()))
-	{
-	  execv (lvsBinary, argv);
-	  exit (-1);
-	}
+      logArgv (flags, ipvsadmArgs);
+      execv (ipvsadmArgs[0], ipvsadmArgs);
+      exit (-1);
     }

+  waitpid (child, NULL, 0);
+}
+
+
+
+
+
+/*
+**  sendLvsArps() -- send arps for all VIPs
+*/
+
+static void
+sendLvsArps (struct lvsConfig *config, int flags)
+{
+  pid_t fake1;
+  pid_t *fake = alloca (sizeof (*fake) * (config->numVirtServers + 1));
+  int i;
+  int j;
+  int numFakes;

   /* Run fake for 5 seconds on each interface */
   if (!(fake1 = fork ()))
@@ -1240,6 +1272,107 @@
     }

   waitpid (fake1, NULL, 0);
+}
+
+
+
+
+
+/*
+**  executeCommand() --
+*/
+
+static void
+executeCommand (struct lvsConfig *config, int flags, char *cmd)
+{
+
+  pid_t child = 0;
+  char *argv[40];
+  char **argp;
+  char *token;
+  char *command;
+
+
+  if (!cmd)
+    return;
+
+  command = strdup (cmd);
+
+  if (!(flags & PULSE_FLAG_NORUN))
+    {
+      if (pulse_debug)
+        piranha_log (flags,
+		     (char *)
+		     "DEBUG -- Executing '%s'", command);
+
+      if (!(child = fork ()))
+	{
+          argp = argv;
+          token = strtok (command, " ");
+          while (token != NULL)
+            {
+              *argp++ = strdup (token);
+              token = strtok (NULL, " ");
+            }
+          *argp++ = NULL;
+
+          logArgv (flags, argv);
+	  execv (argv[0], argv);
+	  exit (-1);
+	}
+
+      //waitpid (child, NULL, 0);
+    }
+
+  free (command);
+}
+
+
+
+
+
+/*
+**  activateLvs() -- Start LVS program, then send arps for all VIPs
+*/
+
+static pid_t
+activateLvs (struct lvsConfig *config, int flags)
+{
+
+  pid_t child = 0;
+  char *argv[6];
+
+
+  executeCommand (config, flags, config->activeCommand);
+
+  argv[0] = lvsBinary;
+  argv[1] = (char *) "--nodaemon";
+  argv[2] = (char *) "-c";
+  argv[3] = configFile;
+  argv[4] = NULL;
+  argv[5] = NULL;
+
+  if (flags & PULSE_FLAG_ASDAEMON)
+    argv[1] = (char *) "--nofork";
+
+  if (pulse_debug)
+    argv[4] = (char *) "-v";
+
+  if (pulse_debug)
+    logArgv (flags, argv);
+
+  if (!(flags & PULSE_FLAG_NORUN))
+    {
+      if (!(child = fork ()))
+	{
+	  execv (lvsBinary, argv);
+	  exit (-1);
+	}
+    }
+
+  syncDaemon (config, flags, 1);
+  sendLvsArps (config, flags);
+
   return child;
 }

@@ -1258,6 +1391,10 @@
   int i, j;


+  executeCommand (config, flags, config->inactiveCommand);
+
+  syncDaemon (config, flags, 0);
+
   if ((flags & PULSE_FLAG_NORUN) || !(flags & PULSE_FLAG_AMACTIVE))
     return;

@@ -1653,7 +1790,11 @@
     }

   if (use_fos == 0)
-    sigprocmask (SIG_UNBLOCK, &sigs, NULL);
+    {
+      sigprocmask (SIG_UNBLOCK, &sigs, NULL);
+      executeCommand (config, flags, config->inactiveCommand);
+      syncDaemon (config, flags, 0);
+    }

   flags |= PULSE_FLAG_SUPPRESS_ERRORS;	/* Suppress useless start errs */

@@ -2085,16 +2226,13 @@

 			  /* Both are running & we are master */

-			  if ((config->redirectType == LVS_REDIRECT_NAT) &&
-			      (config->natRouterDevice != NULL) &&
-			      (use_fos == 0))
+			  if (use_fos == 0)
 			    {
 			      piranha_log (flags,
 					   (char *)
 					   "partner active: resending arps");
-			      sendArps (config->natRouterDevice,
-					&config->natRouter,
-					&config->nat_nmask, 5, flags);
+                              executeCommand (config, flags, config->activeCommand);
+			      sendLvsArps (config, flags);
 			    }
 			  else
 			    piranha_log (flags, (char *) "partner active");
@@ -2429,7 +2567,7 @@
     }

   poptFreeContext (optCon);
-  logName ((char *) "pulse");
+  logName ((char *) argv[0]);

   if (display_ver)
     {
@@ -2582,10 +2720,8 @@
   if (!rc)
     rc = run (&config, fd, fd_priv, flags);

-
   if (flags & PULSE_FLAG_ASDAEMON)
-    unlink ("/var/run/pulse.pid");
-
+    removePidFile ();

   if (rc == 2)
     rc = 0;
diff -Naur piranha.orig/pulse.init piranha/pulse.init
--- piranha.orig/pulse.init	Mon Nov 18 13:46:53 2002
+++ piranha/pulse.init	Mon Nov 18 13:47:01 2002
@@ -11,6 +11,8 @@
 # pidfile: /var/run/pulse.pid
 # config: /etc/sysconfig/ha/lvs.cf

+pulse=`basename $0`
+
 # Source function library.
 . /etc/rc.d/init.d/functions

@@ -20,32 +22,32 @@
 # Check that networking is up.
 [ ${NETWORKING} = "no" ] && exit 0

-[ -f /usr/sbin/pulse ] || exit 0
+[ -f /usr/sbin/$pulse ] || exit 0

-[ -f /etc/sysconfig/ha/lvs.cf ] || exit 0
+[ -f /etc/sysconfig/ha/$pulse.cf ] || exit 0

 RETVAL=0

 # See how we were called.
 case "$1" in
   start)
-        echo -n "Starting pulse: "
-        daemon pulse
+        echo -n "Starting $pulse: "
+        daemon $pulse -c /etc/sysconfig/ha/$pulse.cf
 	RETVAL=$?
         echo
-        [ $RETVAL -eq 0 ] && touch /var/lock/subsys/pulse
+        [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$pulse
         ;;

   stop)
-        echo -n "Shutting down pulse: "
-	killproc pulse
+        echo -n "Shutting down $pulse: "
+	killproc $pulse
 	RETVAL=$?
         echo
-        [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/pulse
+        [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$pulse
         ;;

   status)
-	status pulse
+	status $pulse
 	RETVAL=$?
 	;;

@@ -56,13 +58,13 @@
 	;;

   reload)
-	echo -n "Reloading pulse: "
-	killproc pulse -HUP
+	echo -n "Reloading $pulse: "
+	killproc $pulse -HUP
 	RETVAL=$?
 	;;

   *)
-        echo "Usage: pulse {start|stop|status|restart|reload}"
+        echo "Usage: $pulse {start|stop|status|restart|reload}"
         exit 1
 esac

diff -Naur piranha.orig/util.c piranha/util.c
--- piranha.orig/util.c	Mon Nov 18 13:46:53 2002
+++ piranha/util.c	Mon Nov 18 13:47:01 2002
@@ -29,6 +29,7 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <unistd.h>
+#include <libgen.h>

 #include "util.h"

@@ -37,7 +38,11 @@
 void
 logName (char *newName)
 {
-  name = newName;
+  char *path;
+
+  path = strdup (newName);
+  name = strdup (basename (path));
+  free (path);
 }

 static void
@@ -150,6 +155,15 @@
 }

 void
+removePidFile ()
+{
+  char pidFile[80];
+
+  sprintf (pidFile, "/var/run/%s.pid", name);
+  unlink (pidFile);
+}
+
+void
 logArgv (int flags, char **argv)
 {
   char *argList;
diff -Naur piranha.orig/util.h piranha/util.h
--- piranha.orig/util.h	Mon Nov 18 13:46:53 2002
+++ piranha/util.h	Mon Nov 18 13:47:01 2002
@@ -36,6 +36,7 @@
 void piranha_log (int flags, char *format, ...);
 void logArgv (int flags, char **argv);
 void logName (char *name);
+void removePidFile ();

 #define LVS_FLAG_TESTSTARTS     (1 << 26)
 #define LVS_FLAG_ASDAEMON       (1 << 27)
cluster-active.sh (application/octet-stream, 461 B)
#! /bin/sh

exec 1>/tmp/toto.1 2>/tmp/toto.2
set -x
OLDIFS=$IFS
PATH=/sbin:/usr/sbin:$PATH

insmod noarp >/dev/null 2>&1

grep -E 'address.*:' /etc/sysconfig/ha/pulse1.cf | \
awk '{ print $3 " " $4; }' | \
sort -u | \
while read line
do
	set $line
	ip=$1
	if=$2
	IFS=":"
	set $if
	IFS=$OLDIFS
	if=$2
	ifconfig lo:$if down
	noarpctl del $ip
done

( ifconfig ; cat /proc/net/noarp ) | mail -s "$HOSTNAME becoming active" [email protected]
cluster-inactive.sh (application/octet-stream, 489 B)
#! /bin/sh

exec 1>/tmp/toto.1 2>/tmp/toto.2
set -x
OLDIFS=$IFS
PATH=/sbin:/usr/sbin:$PATH

insmod noarp >/dev/null 2>&1

grep -E 'address.*:' /etc/sysconfig/ha/pulse1.cf | \
awk '{ print $3 " " $4; }' | \
sort -u | \
while read line
do
	set $line
	ip=$1
	if=$2
	IFS=":"
	set $if
	IFS=$OLDIFS
	if=$2
	noarpctl add $ip
	ifconfig lo:$if $ip netmask 255.255.255.255 up
done

( ifconfig ; cat /proc/net/noarp ) | mail -s "$HOSTNAME becoming inactive" [email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.