Commit 6c37c796 authored by 神楽坂玲奈's avatar 神楽坂玲奈

fix

parent ac46a468
...@@ -6,16 +6,14 @@ set -o allexport ...@@ -6,16 +6,14 @@ set -o allexport
source /etc/railgun/profile source /etc/railgun/profile
set +o allexport set +o allexport
cd `dirname $0` if grep -q $1 /etc/railgun/hacks.csv; then
sed -i "s/$1.*/$1,$2/" /etc/railgun/hacks.csv
if grep -q $1 hacks.csv; then
sed -i "s/$1.*/$1,$2/" hacks.csv
else else
echo $1,$2 >> hacks.csv echo $1,$2 >> /etc/railgun/hacks.csv
fi fi
gateway=$(awk -F, "\$1 == $2 { print \$2 }" regions.csv) gateway=$(awk -F, "\$1 == $2 { print \$2 }" /etc/railgun/regions.csv)
next_hop=$(awk -F, "\$1 == $2 { print \$3 }" regions.csv) next_hop=$(awk -F, "\$1 == $2 { print \$3 }" /etc/railgun/regions.csv)
if [ -z "${gateway}" ] || [ -z "${next_hop}" ]; then if [ -z "${gateway}" ] || [ -z "${next_hop}" ]; then
echo "can't find route for region$2" echo "can't find route for region$2"
exit 1 exit 1
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
}, },
"homepage": "https://github.com/railgun-accelerator/railgun-network-client#readme", "homepage": "https://github.com/railgun-accelerator/railgun-network-client#readme",
"dependencies": { "dependencies": {
"pg": "^4.4.3" "pg": "latest",
"csv": "latest"
} }
} }
fs = require 'fs' fs = require 'fs'
child_process = require 'child_process' child_process = require 'child_process'
csv = require 'csv'
ip_exec = (commands, force=false, callback)-> ip_exec = (commands, force=false, callback)->
args = ['-batch', '-'] args = ['-batch', '-']
...@@ -17,6 +18,15 @@ iptables_exec = (commands, noflush = false, callback )-> ...@@ -17,6 +18,15 @@ iptables_exec = (commands, noflush = false, callback )->
child.on 'close', callback child.on 'close', callback
child.stdin.end result child.stdin.end result
exec = (ipforce, ip, iptables)->
ip_exec ipforce, true, (code)->
console.log code
ip_exec ip, false, (code)->
console.log code
iptables_exec iptables, true, (code)->
console.log code
process.exit()
module.exports = module.exports =
init: (server_id, servers, regions)-> init: (server_id, servers, regions)->
...@@ -105,20 +115,23 @@ module.exports = ...@@ -105,20 +115,23 @@ module.exports =
else else
ip.push "route add #{address} advmss 1360 dev railgun#{servers[region.gateway].next_hop} src #{servers[server_id].host} realm #{region.gateway} table 101" ip.push "route add #{address} advmss 1360 dev railgun#{servers[region.gateway].next_hop} src #{servers[server_id].host} realm #{region.gateway} table 101"
#console.log ipforce.join("\n") # hacks
#console.log '-' csv.stringify ([region.id, region.gateway, servers[region.gateway].next_hop] for i, region of regions when region.gateway?), (error, data)->
ip_exec ipforce, true, (code)-> throw error if error
console.log code fs.writeFile '/etc/railgun/regions.csv', (error)->
#console.log error, stdout, stderr throw error if error
#console.log ip.join("\n") fs.readFile '/etc/railgun/hacks.csv', (error, data)->
ip_exec ip, false, (code)-> if data
#throw error if error csv.parse data, (error, data)->
console.log code if data
iptables_exec iptables, true, (code)-> for hack in data
console.log code [address,region_id] = hack
#throw error if error region = regions[region_id]
# save route to file, for hacks if region and region.gateway?
# fs.writeFile 'servers.csv', ([server.id, server.next_hop].join(',') for server in servers when server.next_hop?).join("\n") # we don't need it now. if region.gateway == server_id
fs.writeFile 'regions.csv', ([region.id, region.gateway, servers[region.gateway].next_hop].join(',') for i, region of regions when region.gateway?).join("\n"), (error)-> ip.push "route replace #{address} via #{process.env.RAILGUN_GATEWAY} table 101"
throw error if error else
process.exit() ip.push "route add #{address} advmss 1360 dev railgun#{servers[region.gateway].next_hop} src #{servers[server_id].host} realm #{region.gateway} table 101"
exec(ipforce, ip, iptables)
else
exec(ipforce, ip, iptables)
...@@ -12,10 +12,6 @@ ipset create -exist ports1 bitmap:port range 10000-32767 ...@@ -12,10 +12,6 @@ ipset create -exist ports1 bitmap:port range 10000-32767
ipset create -exist ports2 bitmap:port range 10000-32767 ipset create -exist ports2 bitmap:port range 10000-32767
ipset create -exist ports3 bitmap:port range 10000-32767 ipset create -exist ports3 bitmap:port range 10000-32767
ipset create -exist block_ip hash:ip ipset create -exist block_ip hash:ip
ipset create -exist region1 hash:net
ipset create -exist region2 hash:net
ipset create -exist region3 hash:net
ipset create -exist region4 hash:net
echo 'iptables...' echo 'iptables...'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment