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
f6613331
Commit
f6613331
authored
Oct 26, 2015
by
Vitaly Lipatov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
check_connectivity: rewrite channels control code
parent
560eccab
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
67 additions
and
11 deletions
+67
-11
check_connectivity.sh
router/check_connectivity.sh
+67
-11
No files found.
router/check_connectivity.sh
View file @
f6613331
...
...
@@ -4,7 +4,11 @@ cd $(dirname $0)
write_log
()
{
echo
"
$*
"
|
tee
-a
/var/log/check_connectivity.log | mail
-s
"Etersoft router state is changed"
vitaly.lipatov@gmail.com
if
[
-n
"
$FOREGROUND
"
]
;
then
echo
"
$*
"
else
echo
"
$*
"
|
tee
-a
/var/log/check_connectivity.log | mail
-s
"Etersoft router state is changed"
vitaly.lipatov@gmail.com
fi
}
fatal
()
...
...
@@ -94,9 +98,13 @@ apply_state()
esac
}
ALTSPEED
=
OLDALTSPEED
=
OLDAVERAGE
=
OLDMAINLOAD
=
OLDAVERAGE
=
0
OLDMAINLOAD
=
0
OLDTX
=
0
CURCOUNT
=
0
CURDISCOUNT
=
2
calc_distance
()
{
...
...
@@ -105,31 +113,72 @@ calc_distance()
echo
"
$DISTANCE
"
}
MAXAVERAGE
=
180
MAXTX
=
90
check_and_wait
()
{
# AVERAGE and MAINLOAD
# note: sleep 10 inside
eval
$(
./get_traffic.sh
)
# TODO: integrate?
DISTANCE
=
$(
calc_distance
"
$OLDMAINLOAD
"
"
$MAINLOAD
"
)
if
[
"
$DISTANCE
"
-ge
20
]
;
then
write_log
"
$(
date
)
set main procent to
$MAINLOAD
for hop route table"
./set_hop.sh
$MAINLOAD
OLDMAINLOAD
=
$MAINLOAD
# delay
if
[
"
$DISTANCE
"
-ge
15
]
;
then
CURCOUNT
=
$((
$CURCOUNT
+
1
))
else
CURCOUNT
=
0
fi
if
[
"
$CURCOUNT
"
-ge
5
]
;
then
CALCMAINLOAD
=
$((
(
$OLDMAINLOAD
+
$MAINLOAD
)/
2
))
write_log
"
$(
date
)
set main procent to
$CALCMAINLOAD
(step
$CURCOUNT
, target
$MAINLOAD
) for hop route table (TX=
$TX_INET
TX2=
$TX_INET2
)"
./set_hop.sh
$CALCMAINLOAD
if
[
"
$CALCMAINLOAD
"
=
"
$MAINLOAD
"
]
;
then
CURCOUNT
=
0
fi
OLDMAINLOAD
=
$CALCMAINLOAD
fi
if
[
"
$STATE
"
!=
"both"
]
||
[
"
$AVERAGE
"
-ge
170
]
;
then
# force alt speed when we work without reserve channel
if
[
"
$STATE
"
!=
"both"
]
;
then
ALTSPEED
=
1
CURDISCOUNT
=
0
else
ALTSPEED
=
0
# on both channels
# disable alt speed after timeout
if
[
"
$CURDISCOUNT
"
-gt
0
]
;
then
if
[
"
$CURDISCOUNT
"
=
1
]
;
then
ALTSPEED
=
0
fi
CURDISCOUNT
=
$((
$CURDISCOUNT
-
1
))
fi
# disable alt speed on heavy load or overload
if
[
"
$AVERAGE
"
-gt
$MAXAVERAGE
]
||
[
"
$TX_INET
"
-gt
$MAXTX
]
;
then
ALTSPEED
=
1
CURDISCOUNT
=
0
else
if
[
"
$ALTSPEED
"
=
1
]
&&
[
$CURDISCOUNT
=
0
]
;
then
#DISTANCE=$(calc_distance "$OLDAVERAGE" "$AVERAGE")
#if [ "$DISTANCE" -ge 15 ] ; then
CURDISCOUNT
=
$((
$CURDISCOUNT
+
10
))
# OLDAVERAGE=$AVERAGE
#fi
fi
fi
fi
if
[
"
$OLDALTSPEED
"
!=
"
$ALTSPEED
"
]
;
then
if
[
"
$ALTSPEED
"
=
1
]
;
then
write_log
"
$(
date
)
average
speed is too hi
$AVERAGE
, enable alt speed"
write_log
"
$(
date
)
average
trafic
$AVERAGE
>
$MAXAVERAGE
or TX_INET
$TX_INET
>
$MAXTX
, enable alt speed"
./transmission.sh
--alt-speed
else
write_log
"
$(
date
)
average
speed is normal
$AVERAGE
, disable alt speed"
write_log
"
$(
date
)
average
traffic
$AVERAGE
is normal
, disable alt speed"
./transmission.sh
--no-alt-speed
fi
OLDALTSPEED
=
"
$ALTSPEED
"
...
...
@@ -155,5 +204,12 @@ while true ; do
done
}
if
[
"
$1
"
=
"foreground"
]
;
then
FOREGROUND
=
1
write_log
"Running in foreground"
main_cycle
exit
fi
main_cycle &
echo
$!
>
/var/run/check_connectivity.pid
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