Skip to content
Navigation Menu
Toggle navigation
Sign in
In this repository
All GitHub Enterprise
↵
Jump to
↵
No suggested jump to results
In this repository
All GitHub Enterprise
↵
Jump to
↵
In this organization
All GitHub Enterprise
↵
Jump to
↵
In this repository
All GitHub Enterprise
↵
Jump to
↵
Sign in
Reseting focus
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
mariux64
/
mxstartup
Public
Notifications
You must be signed in to change notification settings
Fork
2
Star
0
Code
Issues
1
Pull requests
0
Actions
Projects
0
Security
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security
Insights
Files
36e9774
Makefile
mxservicectl
mxstartup.service
mxstartup2mxconfig
mxstartupctl
mxvipctl
Breadcrumbs
mxstartup
/
mxvipctl
Blame
Blame
Latest commit
History
History
executable file
·
217 lines (157 loc) · 6.11 KB
Breadcrumbs
mxstartup
/
mxvipctl
Top
File metadata and controls
Code
Blame
executable file
·
217 lines (157 loc) · 6.11 KB
Raw
#!/bin/bash CMD_IP="/sbin/ip" CMD_IPTABLES="/usr/sbin/iptables" CMD_MXS2MXVIP="/usr/sbin/mxstartup2mxconfig" RUNDIR="/run/mariux" # expands *-pattern in pathnames to null if no matching files are found.. shopt -s nullglob function mxvip_start_one() { local vip=$1 local -i i mip mfwd echo "starting ${vip} .." . ${vip} mip=${#MX_IP_ADDRESS[*]} mfwd=${#MX_FWD_IP[*]} # echo "ip addresses found: ${mip}" #MX_FWD_DST_IP=([0]="141.14.30.222" [1]="141.14.20.135" [2]="141.14.27.44" [3]="141.14.27.44") #MX_FWD_DST_PORT=([0]="8080" [1]="9191" [2]="9090" [3]="6789") #MX_FWD_IP=([0]="-1" [1]="0" [2]="1" [3]="1") #MX_FWD_SRC_IP=([0]="141.14.30.222" [1]="141.14.20.135" [2]="141.14.27.44" [3]="141.14.27.44") #MX_FWD_SRC_PORT=([0]="80" [1]="91" [2]="90" [3]="80") #MX_IP_ADDRESS=([0]="141.14.20.135" [1]="141.14.27.44") #MX_IP_ADDRESSPREFIX=([0]="20" [1]="20") #MX_IP_BROADCAST=([0]="141.14.31.255" [1]="141.14.31.255") #MX_IP_DEVICE=([0]="eth0" [1]="eth0") i=0 while [ ${i} -lt ${mip} ] ; do # echo " $i -> ${MX_IP_ADDRESS[$i]}" echo "adding ip ${MX_IP_ADDRESS[$i]}/${MX_IP_ADDRESSPREFIX[$i]} broadcast ${MX_IP_BROADCAST[$i]} to ${MX_IP_DEVICE[$i]}" ${CMD_IP} addr add ${MX_IP_ADDRESS[$i]}/${MX_IP_ADDRESSPREFIX[$i]} broadcast ${MX_IP_BROADCAST[$i]} dev ${MX_IP_DEVICE[$i]} ${CMD_IP} link set up dev ${MX_IP_DEVICE[$i]} i=i+1 done # echo "fwds found: ${mfwd}" i=0 while [ ${i} -lt ${mfwd} ] ; do echo "adding forward ${MX_FWD_SRC_IP[$i]}:${MX_FWD_SRC_PORT[$i]} <-> ${MX_FWD_DST_IP[$i]}:${MX_FWD_DST_PORT[$i]}" ${CMD_IPTABLES} -t nat -A PREROUTING -p tcp -j DNAT -d ${MX_FWD_SRC_IP[$i]} --dport ${MX_FWD_SRC_PORT[$i]} --to-destination ${MX_FWD_DST_IP[$i]}:${MX_FWD_DST_PORT[$i]} ${CMD_IPTABLES} -t nat -A OUTPUT -p tcp -j DNAT -d ${MX_FWD_SRC_IP[$i]} --dport ${MX_FWD_SRC_PORT[$i]} --to-destination ${MX_FWD_DST_IP[$i]}:${MX_FWD_DST_PORT[$i]} ${CMD_IPTABLES} -t nat -A POSTROUTING -p tcp -j SNAT --dst ${MX_FWD_DST_IP[$i]} --dport ${MX_FWD_SRC_PORT[$i]} --to-source ${MX_FWD_SRC_IP[$i]} i=i+1 done unset ${!MX_IP_*} unset ${!MX_FWD_*} mv ${vip}{,.r} } function mxvip_stop_one() { local vip=$1 local -i i mip mfwd echo "stopping ${vip} .." . ${vip} mip=${#MX_IP_ADDRESS[*]} mfwd=${#MX_FWD_IP[*]} # echo "ip addresses found: ${mip}" #MX_FWD_DST_IP=([0]="141.14.30.222" [1]="141.14.20.135" [2]="141.14.27.44" [3]="141.14.27.44") #MX_FWD_DST_PORT=([0]="8080" [1]="9191" [2]="9090" [3]="6789") #MX_FWD_IP=([0]="-1" [1]="0" [2]="1" [3]="1") #MX_FWD_SRC_IP=([0]="141.14.30.222" [1]="141.14.20.135" [2]="141.14.27.44" [3]="141.14.27.44") #MX_FWD_SRC_PORT=([0]="80" [1]="91" [2]="90" [3]="80") #MX_IP_ADDRESS=([0]="141.14.20.135" [1]="141.14.27.44") #MX_IP_ADDRESSPREFIX=([0]="20" [1]="20") #MX_IP_BROADCAST=([0]="141.14.31.255" [1]="141.14.31.255") #MX_IP_DEVICE=([0]="eth0" [1]="eth0") # echo "fwds found: ${mfwd}" i=0 while [ ${i} -lt ${mfwd} ] ; do echo "removing forward ${MX_FWD_SRC_IP[$i]}:${MX_FWD_SRC_PORT[$i]} <-> ${MX_FWD_DST_IP[$i]}:${MX_FWD_DST_PORT[$i]}" ${CMD_IPTABLES} -t nat -D PREROUTING -p tcp -j DNAT -d ${MX_FWD_SRC_IP[$i]} --dport ${MX_FWD_SRC_PORT[$i]} --to-destination ${MX_FWD_DST_IP[$i]}:${MX_FWD_DST_PORT[$i]} ${CMD_IPTABLES} -t nat -D OUTPUT -p tcp -j DNAT -d ${MX_FWD_SRC_IP[$i]} --dport ${MX_FWD_SRC_PORT[$i]} --to-destination ${MX_FWD_DST_IP[$i]}:${MX_FWD_DST_PORT[$i]} ${CMD_IPTABLES} -t nat -D POSTROUTING -p tcp -j SNAT --dst ${MX_FWD_DST_IP[$i]} --dport ${MX_FWD_SRC_PORT[$i]} --to-source ${MX_FWD_SRC_IP[$i]} i=i+1 done i=0 while [ ${i} -lt ${mip} ] ; do # echo " $i -> ${MX_IP_ADDRESS[$i]}" dev=${MX_IP_DEVICE[$i]} if [ ! -d "/sys/class/net/${dev}" -a "${dev:0:3}" = "eth" ] ; then net=$(printf "net%02d" "${dev:3}") if [ -d "/sys/class/net/${net}" ] ; then MX_IP_DEVICE[$i]=$net fi fi echo "removing ip ${MX_IP_ADDRESS[$i]}/${MX_IP_ADDRESSPREFIX[$i]} broadcast ${MX_IP_BROADCAST[$i]} to ${MX_IP_DEVICE[$i]}" ${CMD_IP} addr del ${MX_IP_ADDRESS[$i]}/${MX_IP_ADDRESSPREFIX[$i]} broadcast ${MX_IP_BROADCAST[$i]} dev ${MX_IP_DEVICE[$i]} # echo "${CMD_IP} link set up dev ${MX_IP_DEVICE[$i]}" i=i+1 done unset ${!MX_IP_*} unset ${!MX_FWD_*} rm ${vip} } function mxvip_start() { local vip local pattern=$1 : ${pattern:=*} for vip in ${RUNDIR}/mxvip.${pattern}.cfg ; do if [ -e ${vip}.r ] ; then echo >&2 "skipping $vip: already running.." continue fi if [ ! -r ${vip} ] ; then echo >&2 "skipping $vip: can't read file" continue fi if [ ! -O ${vip} ] ; then echo >&2 "skipping $vip: possible hack attempt?" continue fi mxvip_start_one ${vip} done } function mxvip_stop() { local vip local pattern=$1 : ${pattern:=*} for vip in ${RUNDIR}/mxvip.${pattern}.cfg.r ; do if [ ! -r ${vip} ] ; then echo >&2 "skipping $vip: can't read file" continue fi if [ ! -O ${vip} ] ; then echo >&2 "skipping $vip: possible hack attempt?" continue fi mxvip_stop_one ${vip} done } function create_run_dir_if_not_exists() { if [ ! -d ${RUNDIR} ] ; then mkdir -m 0700 ${RUNDIR} fi if [ ! -O ${RUNDIR} ] ; then echo >&2 "${RUNDIR}: wrong owner: possible hack attempt? exiting.." exit 1 fi } function create_mxvip() { ${CMD_MXS2MXVIP} ${RUNDIR} >/dev/null } ############################################################################## create_run_dir_if_not_exists case "${1}" in start) create_mxvip mxvip_start $2 ;; stop) mxvip_stop $2 ;; restart) mxvip_stop $2 create_mxvip mxvip_start $2 ;; *) echo >&2 "$0 start|stop" ;; esac
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
93
94
95
96
97
98
99
100
101
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
You can’t perform that action at this time.