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 @@
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
echo
"
$(
date
)
Watcher is stopped"
>>
/var/log/check_connectivity.log
write_log
"
$(
date
)
Watcher is stopped"
kill
$(
cat
/var/run/check_connectivity.pid
)
rm
-f
/var/run/check_connectivity.pid
exit
...
...
@@ -12,7 +24,7 @@ fi
# ya.ru google.com
HOSTS
=
"93.158.134.3 173.194.71.139"
# return false if
both
failed
# return false if
all targets
failed
check_hosts
()
{
local
iface
=
"
$1
"
...
...
@@ -32,67 +44,68 @@ check_bird()
STATE
=
both
s
et_state
()
g
et_state
()
{
# Ekvant failed
if
!
check_hosts 212.176.192.225
;
then
NEWSTATE
=
prometey
return
fi
# Prometey
if
!
check_hosts 85.235.198.26
;
then
NEWSTATE
=
ekvant
return
fi
NEWSTATE
=
both
SHEKVANT
=
SHPROMETEY
=
check_hosts 212.176.192.225
&&
SHEKVANT
=
ok
check_hosts 85.235.198.26
&&
SHPROMETEY
=
ok
[
"
$SHEKVANT$SHPROMETEY
"
=
"okok"
]
&&
NEWSTATE
=
both
&&
return
[
"
$SHEKVANT$SHPROMETEY
"
=
""
]
&&
NEWSTATE
=
none
&&
return
[
"
$SHEKVANT
"
=
"ok"
]
&&
NEWSTATE
=
ekvant
&&
return
[
"
$SHPROMETEY
"
=
"ok"
]
&&
NEWSTATE
=
prometey
&&
return
fatal
"No such state!"
}
s
et_state_by_bgp
()
g
et_state_by_bgp
()
{
# check bgp only have both uplink works
[
"
$NEWSTATE
"
=
"both"
]
||
return
local
SEKVANT
=
local
SPROMETEY
=
check_bird bgpAS2854
&&
SEKVANT
=
ok
check_bird bgpAS35000
&&
SPROMETEY
=
ok
[
"
$SEKVANT$SPROMETEY
"
=
"okok"
]
&&
return
[
"
$SEKVANT$SPROMETEY
"
=
""
]
&&
NEWSTATE
=
none
&&
return
[
"
$SEKVANT
"
=
"ok"
]
&&
NEWSTATE
=
ekvant
&&
return
[
"
$SPROMETEY
"
=
"ok"
]
&&
NEWSTATE
=
prometey
&&
return
SBEKVANT
=
SBPROMETEY
=
check_bird bgpAS2854
&&
SBEKVANT
=
ok
check_bird bgpAS35000
&&
SBPROMETEY
=
ok
[
"
$SBEKVANT$SBPROMETEY
"
=
"okok"
]
&&
return
[
"
$SBEKVANT$SBPROMETEY
"
=
""
]
&&
NEWSTATE
=
none
&&
return
[
"
$SBEKVANT
"
=
"ok"
]
&&
NEWSTATE
=
ekvant
&&
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
()
{
./both_provs.sh
echo
"
$(
date
)
Start with both state"
>>
/var/log/check_connectivity.log
write_log
"
$(
date
)
Start with both state"
while
true
;
do
s
et_state
s
et_state_by_bgp
g
et_state
g
et_state_by_bgp
if
[
"
$STATE
"
!=
"
$NEWSTATE
"
]
;
then
case
"
$NEWSTATE
"
in
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
apply_state
"
$NEWSTATE
"
write_log
"
$(
date
)
State changed to
$NEWSTATE
(Ekvant:
$SHEKVANT
-
$SBEKVANT
, Prometey:
$SHPROMETEY
-
$SBPROMETEY
)"
STATE
=
$NEWSTATE
fi
sleep
7
...
...
router/only_ekvant.sh
View file @
cdb700b5
...
...
@@ -6,6 +6,7 @@ ip route replace default via 212.176.192.226
# Ekvant exports default to us, but we will repeat it
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
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