https://github.com/realityone/raproxy
Reloadable HAProxy inspired from multibinder.
https://github.com/realityone/raproxy
haproxy reload
Last synced: 9 months ago
JSON representation
Reloadable HAProxy inspired from multibinder.
- Host: GitHub
- URL: https://github.com/realityone/raproxy
- Owner: realityone
- Created: 2017-03-03T09:50:43.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-05-22T10:51:03.000Z (over 8 years ago)
- Last Synced: 2025-04-15T19:08:50.211Z (9 months ago)
- Topics: haproxy, reload
- Language: Rust
- Homepage:
- Size: 49.8 KB
- Stars: 4
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# RAProxy
[](https://travis-ci.org/realityone/RAProxy)
Reloadable HAProxy inspired from [multibinder](https://github.com/github/multibinder).
## Requirements
- Rust(only on build)
- HAProxy
- Linux or macOS
## Installation
### Install Rust
Using [rustup](https://www.rustup.rs) is recommended.
### Build from source code
```bash
# git clone https://github.com/realityone/RAProxy.git
# cd Raproxy
# cargo install
```
Then you can run `raproxy` in your terminal.
```bash
# raproxy
error: The following required arguments were not provided:
--binary
--config
--service ...
USAGE:
raproxy --binary --config --service ... --pid
For more information try --help
```
## Usage
### Install HAProxy
First of all, please make sure you have installed original HAProxy on your machine.
Simply type `haproxy` in terminal for test.
```bash
# haproxy
HA-Proxy version 1.7.2 2017/01/13
Copyright 2000-2017 Willy Tarreau
...
```
If error, you should install it first.
### Config your HAProxy config file
Here is an example.
```conf
global
maxconn 256
defaults
mode http
timeout connect 5000ms
timeout client 50000ms
timeout server 50000ms
frontend http-in
bind fd@${APP_1}
use_backend sina
backend sina
server sina www.sina.com:80
```
In frontend `http-in`, use `fd@{__NAME__}` for bind specification. The `__NAME__` should be your service name which will defined in RAProxy, I will explain it later.
### Start RAProxy
- The HAProxy binary is at `/usr/local/bin/haproxy`
- The HAProxy config file is at `/etc/haproxy/haproxy.cfg`
- We want bind frontend `http-in` at address `0.0.0.0:8080` for incoming traffic. And we name it as `APP_1`.
```bash
# raproxy -b /usr/local/bin/haproxy -c /etc/haproxy/haproxy.cfg -s APP_1=0.0.0.0:8080
INFO:raproxy: HAProxy process started: PID 46972
```
Using `curl` for test.
```bash
# curl -H 'Host: sina.com' 127.0.0.1:8080
301 Moved Permanently
301 Moved Permanently
nginx/1.5.2
```
### Reload HAProxy
Find the `raproxy` process, and emit `SIGHUP` signal.
```bash
# ps ax | grep raproxy
46971 s001 S+ 0:00.00 raproxy -b /usr/local/bin/haproxy -c /etc/haproxy/haproxy.cfg -s APP_1=0.0.0.0:8080
47083 s004 S+ 0:00.00 grep raproxy
# kill -s HUP 46971
```
Then the new HAProxy process will be created, and the last will exit gracefully.
```
# raproxy -b /usr/local/bin/haproxy -c /etc/haproxy/haproxy.cfg -s APP_1=0.0.0.0:8080
INFO:raproxy: HAProxy process started: PID 46972
INFO:raproxy: HAProxy process started: PID 47098
INFO:raproxy: Process exited: Exited(46972, 0)
```
## TODO
* [x] Auto detect HAProxy binary.
* [ ] Reload RAProxy self.
* [ ] Integrate with SystemD.
## Reference
- [GLB part 2: HAProxy zero-downtime, zero-delay reloads with multibinder](https://githubengineering.com/glb-part-2-haproxy-zero-downtime-zero-delay-reloads-with-multibinder/)
- [SO_REUSEADDR option](http://man7.org/linux/man-pages/man7/socket.7.html#SO_REUSEADDR)