d72f5af
From 12e58a6c40b3bfa18f0db5db9e36ed09f68d7a0c Mon Sep 17 00:00:00 2001
d72f5af
From: Ryan O'Hara <rohara@redhat.com>
d72f5af
Date: Mon, 29 Oct 2012 14:10:57 -0500
d72f5af
Subject: [PATCH 01/10] Add option to prevent respawn of child processes.
d72f5af
d72f5af
This patch adds a command-line option (--dont-respawn, -R) that will
d72f5af
prevent the child processes from respawning. When this option is
d72f5af
specified, if either the checker or vrrp child processes exit the
d72f5af
parent process will raise the SIGTERM signal and exit.
d72f5af
d72f5af
Signed-off-by: Ryan O'Hara <rohara@redhat.com>
d72f5af
---
d72f5af
 keepalived/check/check_daemon.c |    9 +++++++--
d72f5af
 keepalived/core/main.c          |   10 +++++++++-
d72f5af
 keepalived/vrrp/vrrp_daemon.c   |    9 +++++++--
d72f5af
 3 files changed, 23 insertions(+), 5 deletions(-)
d72f5af
d72f5af
diff --git a/keepalived/check/check_daemon.c b/keepalived/check/check_daemon.c
d72f5af
index 1119075..68759f4 100644
d72f5af
--- a/keepalived/check/check_daemon.c
d72f5af
+++ b/keepalived/check/check_daemon.c
d72f5af
@@ -227,8 +227,13 @@ check_respawn_thread(thread_t * thread)
d72f5af
 	}
d72f5af
 
d72f5af
 	/* We catch a SIGCHLD, handle it */
d72f5af
-	log_message(LOG_ALERT, "Healthcheck child process(%d) died: Respawning", pid);
d72f5af
-	start_check_child();
d72f5af
+	if (!(debug & 64)) {
d72f5af
+		log_message(LOG_ALERT, "Healthcheck child process(%d) died: Respawning", pid);
d72f5af
+		start_check_child();
d72f5af
+	} else {
d72f5af
+		log_message(LOG_ALERT, "Healthcheck child process(%d) died: Exiting", pid);
d72f5af
+		raise(SIGTERM);
d72f5af
+	}
d72f5af
 	return 0;
d72f5af
 }
d72f5af
 
d72f5af
diff --git a/keepalived/core/main.c b/keepalived/core/main.c
d72f5af
index 57fa134..9445a4c 100644
d72f5af
--- a/keepalived/core/main.c
d72f5af
+++ b/keepalived/core/main.c
d72f5af
@@ -146,6 +146,7 @@ usage(const char *prog)
d72f5af
 		"  %s --check              -C    Only run with Health-checker subsystem.\n"
d72f5af
 		"  %s --dont-release-vrrp  -V    Dont remove VRRP VIPs & VROUTEs on daemon stop.\n"
d72f5af
 		"  %s --dont-release-ipvs  -I    Dont remove IPVS topology on daemon stop.\n"
d72f5af
+		"  %s --dont-respawn       -R    Dont respawn child processes.\n"
d72f5af
 		"  %s --dont-fork          -n    Dont fork the daemon process.\n"
d72f5af
 		"  %s --use-file           -f    Use the specified configuration file.\n"
d72f5af
 		"                                Default is /etc/keepalived/keepalived.conf.\n"
d72f5af
@@ -165,7 +166,7 @@ usage(const char *prog)
d72f5af
 #ifdef _WITH_SNMP_
d72f5af
 		prog,
d72f5af
 #endif
d72f5af
-		prog, prog, prog, prog, prog, prog, prog);
d72f5af
+		prog, prog, prog, prog, prog, prog, prog, prog);
d72f5af
 }
d72f5af
 
d72f5af
 /* Command line parser */
d72f5af
@@ -184,6 +185,7 @@ parse_cmdline(int argc, char **argv)
d72f5af
 		{"log-facility", 'S', POPT_ARG_STRING, &option_arg, 'S'},
d72f5af
 		{"dont-release-vrrp", 'V', POPT_ARG_NONE, NULL, 'V'},
d72f5af
 		{"dont-release-ipvs", 'I', POPT_ARG_NONE, NULL, 'I'},
d72f5af
+		{"dont-respawn", 'R', POPT_ARG_NONE, NULL, 'R'},
d72f5af
 		{"dont-fork", 'n', POPT_ARG_NONE, NULL, 'n'},
d72f5af
 		{"dump-conf", 'd', POPT_ARG_NONE, NULL, 'd'},
d72f5af
 		{"use-file", 'f', POPT_ARG_STRING, &option_arg, 'f'},
d72f5af
@@ -232,6 +234,9 @@ parse_cmdline(int argc, char **argv)
d72f5af
 	case 'D':
d72f5af
 		debug |= 32;
d72f5af
 		break;
d72f5af
+	case 'R':
d72f5af
+		debug |= 64;
d72f5af
+		break;
d72f5af
 	case 'S':
d72f5af
 		log_facility = LOG_FACILITY[atoi(option_arg)].facility;
d72f5af
 		break;
d72f5af
@@ -282,6 +287,9 @@ parse_cmdline(int argc, char **argv)
d72f5af
 		case 'D':
d72f5af
 			debug |= 32;
d72f5af
 			break;
d72f5af
+		case 'R':
d72f5af
+			debug |= 64;
d72f5af
+			break;
d72f5af
 		case 'S':
d72f5af
 			log_facility = LOG_FACILITY[atoi(option_arg)].facility;
d72f5af
 			break;
d72f5af
diff --git a/keepalived/vrrp/vrrp_daemon.c b/keepalived/vrrp/vrrp_daemon.c
d72f5af
index 23ff09f..cee6c80 100644
d72f5af
--- a/keepalived/vrrp/vrrp_daemon.c
d72f5af
+++ b/keepalived/vrrp/vrrp_daemon.c
d72f5af
@@ -249,8 +249,13 @@ vrrp_respawn_thread(thread_t * thread)
d72f5af
 	}
d72f5af
 
d72f5af
 	/* We catch a SIGCHLD, handle it */
d72f5af
-	log_message(LOG_ALERT, "VRRP child process(%d) died: Respawning", pid);
d72f5af
-	start_vrrp_child();
d72f5af
+	if (!(debug & 64)) {
d72f5af
+		log_message(LOG_ALERT, "VRRP child process(%d) died: Respawning", pid);
d72f5af
+		start_vrrp_child();
d72f5af
+	} else {
d72f5af
+		log_message(LOG_ALERT, "VRRP child process(%d) died: Exiting", pid);
d72f5af
+		raise(SIGTERM);
d72f5af
+	}
d72f5af
 	return 0;
d72f5af
 }
d72f5af
 
d72f5af
-- 
d72f5af
1.7.1
d72f5af