]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: mworker: exit-on-failure option
authorWilliam Lallemand <wlallemand@haproxy.com>
Thu, 1 Jun 2017 15:38:54 +0000 (17:38 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 2 Jun 2017 08:56:32 +0000 (10:56 +0200)
This option exits every workers when one of the current workers die.

It allows you to monitor the master process in order to relaunch
everything on a failure.

For example it can be used with systemd and Restart=on-failure in a spec
file.

include/types/global.h
src/cfgparse.c
src/haproxy.c

index ee8e95e0e8b2368d2547c127901e4bc72c2573c9..cce3de77fa9dca19fcd8a7275309581c11d09696 100644 (file)
@@ -63,6 +63,7 @@
 #define GTUNE_RESOLVE_DONTFAIL   (1<<7)
 
 #define GTUNE_SOCKET_TRANSFER   (1<<8)
+#define GTUNE_EXIT_ONFAILURE     (1<<9)
 
 /* Access level for a stats socket */
 #define ACCESS_LVL_NONE     0
index bdf55a8da551c0021ef8a78abb3a421c751f92eb..76a4f318c5e5075a0e6135e62c82a527429f27ef 100644 (file)
@@ -625,8 +625,17 @@ int cfg_parse_global(const char *file, int linenum, char **args, int kwm)
                global.mode |= MODE_DAEMON;
        }
        else if (!strcmp(args[0], "master-worker")) {
-               if (alertif_too_many_args(0, file, linenum, args, &err_code))
+               if (alertif_too_many_args(1, file, linenum, args, &err_code))
                        goto out;
+               if (*args[1]) {
+                       if (!strcmp(args[1], "exit-on-failure")) {
+                               global.tune.options |= GTUNE_EXIT_ONFAILURE;
+                       } else {
+                               Alert("parsing [%s:%d] : '%s' only supports 'exit-on-failure' option.\n", file, linenum, args[0]);
+                               err_code |= ERR_ALERT | ERR_FATAL;
+                               goto out;
+                       }
+               }
                global.mode |= MODE_MWORKER;
        }
        else if (!strcmp(args[0], "debug")) {
index 4e892c099566f10dbe3b902898f8775c634fa04b..10ddf160206290b959e573210d60a52ce6621917 100644 (file)
@@ -671,6 +671,11 @@ static void mworker_wait()
                        /* check if exited child was in the current children list */
                        if (current_child(exitpid)) {
                                Alert("Current worker %d left with exit code %d\n", exitpid, status);
+                               if (status != 0 && status != 130 && status != 143
+                                   && global.tune.options & GTUNE_EXIT_ONFAILURE) {
+                                       Alert("exit-on-failure: killing every workers with SIGTERM\n");
+                                       mworker_kill(SIGTERM);
+                               }
                        } else {
                                Warning("Former worker %d left with exit code %d\n", exitpid, status);
                                delete_oldpid(exitpid);