blob: bd35adc4e3ce76818a5a30997d16a9eaefef005b (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
#!/bin/bash
use_dnbd3() {
mountpoint -q /mnt/store && [ -x "/opt/dnbd3/dnbd3-server" ]
}
is_dnbd3() {
systemctl -q is-active dnbd3-server.service || return 1
systemctl -q is-active dnbd3-ssl-in.service || return 1
systemctl -q is-active dnbd3-ssl-out.service || return 1
return 0
}
enable_dnbd3() {
echo "Enabling dnbd3 proxy"
systemctl disable --now bwlp-master-socat@5006.service
systemctl enable --now dnbd3-server.service
systemctl enable --now dnbd3-ssl-in.service
systemctl enable --now dnbd3-ssl-out.service
}
disable_dnbd3() {
echo "Disabling dnbd3 proxy"
systemctl disable --now dnbd3-server.service
systemctl disable --now dnbd3-ssl-in.service
systemctl disable --now dnbd3-ssl-out.service
}
is_passthrough() {
systemctl -q is-active apache2.service || return 1
systemctl -q is-active bwlp-master-socat@9090.service || return 1
systemctl -q is-active bwlp-master-socat@9091.service || return 1
local lnk=$( readlink -f /etc/apache2/sites-enabled/110-bwlp.conf )
[ "$lnk" = "/etc/apache2/sites-available/110-bwlp-passthrough.conf" ] || return 1
return 0
}
is_active() {
systemctl -q is-active apache2.service || return 1
systemctl -q is-active bwlp-master.service || return 1
local lnk=$( readlink -f /etc/apache2/sites-enabled/110-bwlp.conf )
[ "$lnk" = "/etc/apache2/sites-available/110-bwlp-active.conf" ] || return 1
return 0
}
passthrough() {
is_passthrough && return 0
echo "Enabling passthrough"
systemctl disable --now bwlp-master.service
ln -nfs ../sites-available/110-bwlp-passthrough.conf /etc/apache2/sites-enabled/110-bwlp.conf
systemctl restart apache2.service
systemctl enable --now bwlp-master-socat@9090.service
systemctl enable --now bwlp-master-socat@9091.service
systemctl enable --now bwlp-master-socat@9050.service
systemctl enable --now bwlp-master-socat@9051.service
if ! use_dnbd3; then
systemctl enable --now bwlp-master-socat@5006.service
fi
}
activate() {
is_active && return 0
echo "Enabling active mode"
systemctl disable --now bwlp-master-socat@9090.service
systemctl disable --now bwlp-master-socat@9091.service
systemctl disable --now bwlp-master-socat@9050.service
systemctl disable --now bwlp-master-socat@9051.service
systemctl disable --now bwlp-master-socat@5006.service
ln -nfs ../sites-available/110-bwlp-active.conf /etc/apache2/sites-enabled/110-bwlp.conf
systemctl restart apache2.service
systemctl enable --now bwlp-master.service
}
# Check connectivity
if curl -L -m 10 -o /dev/null -sS \
--retry-max-time 40 --retry 4 --retry-all-errors \
https://%DOMAIN%/webif/; then
# OK
passthrough
else
# Take over
activate
fi
if use_dnbd3; then
is_dnbd3 || enable_dnbd3
else
is_dnbd3 && disable_dnbd3
fi
exit 0
|