Baptiste Assmann | 71503d3 | 2015-09-18 16:38:21 +0200 | [diff] [blame] | 1 | Reloading HAProxy without impacting server states |
| 2 | ================================================= |
| 3 | |
| 4 | Of course, to fully understand below information please consult |
| 5 | doc/configuration.txt to understand how each HAProxy directive works. |
| 6 | |
| 7 | In the mean line, we update HAProxy's configuration to tell it where to |
| 8 | retrieve the last know trustable servers state. |
| 9 | Then, before reloading HAProxy, we simply dump servers state from running |
| 10 | process into the locations we pointed into the configuration. |
| 11 | And voilĂ :) |
| 12 | |
| 13 | |
| 14 | Using one file for all backends |
| 15 | ------------------------------- |
| 16 | |
| 17 | HAProxy configuration |
| 18 | ********************* |
| 19 | |
| 20 | global |
| 21 | [...] |
| 22 | stats socket /var/run/haproxy/socket |
| 23 | server-state-file global |
| 24 | server-state-base /var/state/haproxy/ |
| 25 | |
| 26 | defaults |
| 27 | [...] |
| 28 | load-server-state-from-file global |
| 29 | |
| 30 | HAProxy init script |
| 31 | ******************* |
| 32 | |
| 33 | Run the following command BEFORE reloading: |
| 34 | |
| 35 | socat /var/run/haproxy/socket - <<< "show servers state" > /var/state/haproxy/global |
| 36 | |
| 37 | |
| 38 | Using one state file per backend |
| 39 | -------------------------------- |
| 40 | |
| 41 | HAProxy configuration |
| 42 | ********************* |
| 43 | |
| 44 | global |
| 45 | [...] |
| 46 | stats socket /var/run/haproxy/socket |
| 47 | server-state-base /var/state/haproxy/ |
| 48 | |
| 49 | defaults |
| 50 | [...] |
| 51 | load-server-state-from-file local |
| 52 | |
| 53 | HAProxy init script |
| 54 | ******************* |
| 55 | |
| 56 | Run the following command BEFORE reloading: |
| 57 | |
| 58 | for b in $(socat /var/run/haproxy/socket - <<< "show backend" | fgrep -v '#') |
| 59 | do |
| 60 | socat /var/run/haproxy/socket - <<< "show servers state $b" > /var/state/haproxy/$b |
| 61 | done |
| 62 | |