Skip to content

Commit a27264a

Browse files
Add haproxy (ct)
1 parent 928c930 commit a27264a

3 files changed

Lines changed: 141 additions & 0 deletions

File tree

ct/haproxy.sh

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/usr/bin/env bash
2+
_CS_DEFAULT_URL="https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main"
3+
_cs_boot="${COMMUNITY_SCRIPTS_CORE_DIR:-$(dirname "${BASH_SOURCE[0]}")/../../core}/core/build.func"
4+
source "$_cs_boot" 2>/dev/null || source <(curl -fsSL "${COMMUNITY_SCRIPTS_CORE_URL:-https://raw.githubusercontent.com/community-scripts/core/main}/core/build.func")
5+
# Copyright (c) 2021-2026 community-scripts ORG
6+
# Author: MickLesk (CanbiZ)
7+
# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
8+
# Source: https://www.haproxy.org/
9+
10+
APP="HAProxy"
11+
var_tags="${var_tags:-network;proxy}"
12+
var_cpu="${var_cpu:-1}"
13+
var_ram="${var_ram:-512}"
14+
var_disk="${var_disk:-4}"
15+
var_os="${var_os:-debian}"
16+
var_version="${var_version:-13}"
17+
#var_arm64="${var_arm64:-no}" # unset = ask the user; set yes/no only when verified
18+
var_unprivileged="${var_unprivileged:-1}"
19+
20+
header_info "$APP"
21+
variables
22+
color
23+
catch_errors
24+
25+
function update_script() {
26+
header_info
27+
check_container_storage
28+
check_container_resources
29+
30+
if [[ ! -f /etc/haproxy/haproxy.cfg ]]; then
31+
msg_error "No ${APP} Installation Found!"
32+
exit
33+
fi
34+
35+
msg_info "Updating ${APP}"
36+
$STD apt update
37+
$STD apt install -y haproxy
38+
msg_ok "Updated ${APP}"
39+
40+
msg_info "Validating Configuration"
41+
if ! $STD haproxy -c -f /etc/haproxy/haproxy.cfg; then
42+
msg_error "Configuration is invalid - service not restarted"
43+
exit
44+
fi
45+
msg_ok "Validated Configuration"
46+
47+
msg_info "Restarting Service"
48+
systemctl restart haproxy
49+
msg_ok "Restarted Service"
50+
msg_ok "Updated successfully!"
51+
exit
52+
}
53+
54+
start
55+
build_container
56+
description
57+
58+
msg_ok "Completed Successfully!\n"
59+
echo -e "${CREATING}${GN}${APP} setup has been successfully initialized!${CL}"
60+
echo -e "${INFO}${YW}Statistics page:${CL}"
61+
echo -e "${GATEWAY}${BGN}http://${IP}:8404${CL}"
62+
echo -e "${INFO}${YW}The generated stats password is in /etc/haproxy/haproxy.cfg${CL}"

ct/headers/haproxy

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
__ _____ ____
2+
/ / / / | / __ \_________ _ ____ __
3+
/ /_/ / /| | / /_/ / ___/ __ \| |/_/ / / /
4+
/ __ / ___ |/ ____/ / / /_/ /> </ /_/ /
5+
/_/ /_/_/ |_/_/ /_/ \____/_/|_|\__, /
6+
/____/

install/haproxy-install.sh

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright (c) 2021-2026 community-scripts ORG
4+
# Author: MickLesk (CanbiZ)
5+
# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
6+
# Source: https://www.haproxy.org/
7+
8+
source /dev/stdin <<<"$FUNCTIONS_FILE_PATH"
9+
color
10+
verb_ip6
11+
catch_errors
12+
setting_up_container
13+
network_check
14+
update_os
15+
16+
msg_info "Installing HAProxy"
17+
$STD apt install -y haproxy
18+
msg_ok "Installed HAProxy"
19+
20+
msg_info "Configuring HAProxy"
21+
HAPROXY_STATS_PASSWORD=$(openssl rand -base64 18)
22+
cat <<EOF >/etc/haproxy/haproxy.cfg
23+
global
24+
log /dev/log local0
25+
chroot /var/lib/haproxy
26+
stats socket /run/haproxy/admin.sock mode 660 level admin
27+
stats timeout 30s
28+
user haproxy
29+
group haproxy
30+
daemon
31+
ssl-default-bind-options ssl-min-ver TLSv1.2 no-tls-tickets
32+
33+
defaults
34+
log global
35+
mode http
36+
option httplog
37+
option dontlognull
38+
timeout connect 5s
39+
timeout client 50s
40+
timeout server 50s
41+
errorfile 400 /etc/haproxy/errors/400.http
42+
errorfile 403 /etc/haproxy/errors/403.http
43+
errorfile 408 /etc/haproxy/errors/408.http
44+
errorfile 500 /etc/haproxy/errors/500.http
45+
errorfile 502 /etc/haproxy/errors/502.http
46+
errorfile 503 /etc/haproxy/errors/503.http
47+
errorfile 504 /etc/haproxy/errors/504.http
48+
49+
listen stats
50+
bind *:8404
51+
stats enable
52+
stats uri /
53+
stats refresh 10s
54+
stats admin if TRUE
55+
stats auth admin:${HAPROXY_STATS_PASSWORD}
56+
57+
# Example: replace with your own frontend/backend pairs.
58+
#frontend http_in
59+
# bind *:80
60+
# default_backend servers
61+
#
62+
#backend servers
63+
# balance roundrobin
64+
# server web1 192.168.1.10:80 check
65+
# server web2 192.168.1.11:80 check
66+
EOF
67+
$STD haproxy -c -f /etc/haproxy/haproxy.cfg
68+
systemctl restart haproxy
69+
msg_ok "Configured HAProxy"
70+
71+
motd_ssh
72+
customize
73+
cleanup_lxc

0 commit comments

Comments
 (0)