Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
etersoft-admin-essentials
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
etersoft
etersoft-admin-essentials
Commits
cdb700b5
Commit
cdb700b5
authored
Oct 04, 2015
by
Vitaly Lipatov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactoring check_connectivity script
parent
5eb57fee
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
63 additions
and
49 deletions
+63
-49
check_connectivity.sh
router/check_connectivity.sh
+62
-49
only_ekvant.sh
router/only_ekvant.sh
+1
-0
No files found.
router/check_connectivity.sh
View file @
cdb700b5
...
@@ -2,8 +2,20 @@
...
@@ -2,8 +2,20 @@
cd
$(
dirname
$0
)
cd
$(
dirname
$0
)
write_log
()
{
echo
"
$*
"
|
tee
-a
/var/log/check_connectivity.log | mail
-s
"Etersoft router state is changed"
vitaly.lipatov@gmail.com
}
fatal
()
{
write_log
"
$(
date
)
FATAL:
$@
"
exit
1
}
if
[
"
$1
"
=
"stop"
]
;
then
if
[
"
$1
"
=
"stop"
]
;
then
echo
"
$(
date
)
Watcher is stopped"
>>
/var/log/check_connectivity.log
write_log
"
$(
date
)
Watcher is stopped"
kill
$(
cat
/var/run/check_connectivity.pid
)
kill
$(
cat
/var/run/check_connectivity.pid
)
rm
-f
/var/run/check_connectivity.pid
rm
-f
/var/run/check_connectivity.pid
exit
exit
...
@@ -12,7 +24,7 @@ fi
...
@@ -12,7 +24,7 @@ fi
# ya.ru google.com
# ya.ru google.com
HOSTS
=
"93.158.134.3 173.194.71.139"
HOSTS
=
"93.158.134.3 173.194.71.139"
# return false if
both
failed
# return false if
all targets
failed
check_hosts
()
check_hosts
()
{
{
local
iface
=
"
$1
"
local
iface
=
"
$1
"
...
@@ -32,67 +44,68 @@ check_bird()
...
@@ -32,67 +44,68 @@ check_bird()
STATE
=
both
STATE
=
both
s
et_state
()
g
et_state
()
{
{
# Ekvant failed
SHEKVANT
=
if
!
check_hosts 212.176.192.225
;
then
SHPROMETEY
=
NEWSTATE
=
prometey
check_hosts 212.176.192.225
&&
SHEKVANT
=
ok
return
check_hosts 85.235.198.26
&&
SHPROMETEY
=
ok
fi
[
"
$SHEKVANT$SHPROMETEY
"
=
"okok"
]
&&
NEWSTATE
=
both
&&
return
# Prometey
[
"
$SHEKVANT$SHPROMETEY
"
=
""
]
&&
NEWSTATE
=
none
&&
return
if
!
check_hosts 85.235.198.26
;
then
[
"
$SHEKVANT
"
=
"ok"
]
&&
NEWSTATE
=
ekvant
&&
return
NEWSTATE
=
ekvant
[
"
$SHPROMETEY
"
=
"ok"
]
&&
NEWSTATE
=
prometey
&&
return
return
fatal
"No such state!"
fi
NEWSTATE
=
both
}
}
s
et_state_by_bgp
()
g
et_state_by_bgp
()
{
{
# check bgp only have both uplink works
[
"
$NEWSTATE
"
=
"both"
]
||
return
[
"
$NEWSTATE
"
=
"both"
]
||
return
local
SEKVANT
=
SBEKVANT
=
local
SPROMETEY
=
SBPROMETEY
=
check_bird bgpAS2854
&&
SEKVANT
=
ok
check_bird bgpAS2854
&&
SBEKVANT
=
ok
check_bird bgpAS35000
&&
SPROMETEY
=
ok
check_bird bgpAS35000
&&
SBPROMETEY
=
ok
[
"
$SEKVANT$SPROMETEY
"
=
"okok"
]
&&
return
[
"
$SBEKVANT$SBPROMETEY
"
=
"okok"
]
&&
return
[
"
$SEKVANT$SPROMETEY
"
=
""
]
&&
NEWSTATE
=
none
&&
return
[
"
$SBEKVANT$SBPROMETEY
"
=
""
]
&&
NEWSTATE
=
none
&&
return
[
"
$SEKVANT
"
=
"ok"
]
&&
NEWSTATE
=
ekvant
&&
return
[
"
$SBEKVANT
"
=
"ok"
]
&&
NEWSTATE
=
ekvant
&&
return
[
"
$SPROMETEY
"
=
"ok"
]
&&
NEWSTATE
=
prometey
&&
return
[
"
$SBPROMETEY
"
=
"ok"
]
&&
NEWSTATE
=
prometey
&&
return
fatal
"No such bgp state!"
}
apply_state
()
{
case
"
$1
"
in
prometey
)
./only_prometey.sh
;;
ekvant
)
./only_ekvant.sh
;;
both
)
./both_provs.sh
;;
none
)
write_log
"Sorry, no connection!"
;;
*
)
fatal
"Unknown state"
;;
esac
}
}
main_cycle
()
main_cycle
()
{
{
./both_provs.sh
./both_provs.sh
echo
"
$(
date
)
Start with both state"
>>
/var/log/check_connectivity.log
write_log
"
$(
date
)
Start with both state"
while
true
;
do
while
true
;
do
s
et_state
g
et_state
s
et_state_by_bgp
g
et_state_by_bgp
if
[
"
$STATE
"
!=
"
$NEWSTATE
"
]
;
then
if
[
"
$STATE
"
!=
"
$NEWSTATE
"
]
;
then
apply_state
"
$NEWSTATE
"
case
"
$NEWSTATE
"
in
write_log
"
$(
date
)
State changed to
$NEWSTATE
(Ekvant:
$SHEKVANT
-
$SBEKVANT
, Prometey:
$SHPROMETEY
-
$SBPROMETEY
)"
prometey
)
./only_prometey.sh
;;
ekvant
)
./only_ekvant.sh
;;
both
)
./both_provs.sh
;;
none
)
echo
"Sorry, no connection!"
>
&2
;;
*
)
echo
"Unknown state"
>
&2
exit
1
;;
esac
echo
"
$(
date
)
State changed to
$NEWSTATE
"
>>
/var/log/check_connectivity.log
STATE
=
$NEWSTATE
STATE
=
$NEWSTATE
fi
fi
sleep
7
sleep
7
...
...
router/only_ekvant.sh
View file @
cdb700b5
...
@@ -6,6 +6,7 @@ ip route replace default via 212.176.192.226
...
@@ -6,6 +6,7 @@ ip route replace default via 212.176.192.226
# Ekvant exports default to us, but we will repeat it
# Ekvant exports default to us, but we will repeat it
ip route replace default scope global table common via 212.176.192.226
ip route replace default scope global table common via 212.176.192.226
# TODO: enable shaper for torrent and our remote backup servers
# remove hops for torrent client
# remove hops for torrent client
ip rule del from 91.232.225.21 lookup hop
ip rule del from 91.232.225.21 lookup hop
ip rule del from 91.232.225.21 lookup hop
ip rule del from 91.232.225.21 lookup hop
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment