Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
watchbot
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Fachschaft
watchbot
Commits
5dab0e1e
Commit
5dab0e1e
authored
1 year ago
by
Jakob Moser
Browse files
Options
Downloads
Patches
Plain Diff
Add watchdog
parent
ee9fdacd
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
watchdog.sh
+78
-0
78 additions, 0 deletions
watchdog.sh
with
78 additions
and
0 deletions
watchdog.sh
0 → 100755
+
78
−
0
View file @
5dab0e1e
#!/bin/bash
TRAEFIK
=
https://traefik.fachschaft.cl.uni-heidelberg.de
BASE_DIR
=
$(
dirname
$(
realpath
$0
))
LAST_KNOWN_DOWNTIME_FILE
=
"
${
BASE_DIR
}
/last_known_downtime"
LAST_KNOWN_RESTART_FILE
=
"
${
BASE_DIR
}
/last_known_restart"
# Return 0 (i.e. true) if the file $1 exists and was modified no more than $2 seconds ago.
# Return 1 (i.e. false) otherwise
younger_than
()
{
if
[[
!
-f
${
1
}
]]
then
return
1
else
FILE_CHANGE
=
$(
date
-r
${
1
}
+%s
)
NOW
=
$(
date
+%s
)
DIFFERENCE
=
$((${
NOW
}
-
${
FILE_CHANGE
}))
if
[[
${
DIFFERENCE
}
-le
${
2
}
]]
then
return
0
else
return
1
fi
fi
}
# Return 0 (i.e. true) if Traefik is currently down.
# Return 1 (i.e. false) if it is currently reachable.
currently_down
()
{
curl
${
TRAEFIK
}
>
/dev/null 2> /dev/null
if
[[
$?
-eq
7
]]
then
return
0
else
return
1
fi
}
# Return 0 (i.e. true) if Traefik was recently down, i.e. if the last
# modified timestamp of ${LAST_KNOWN_DOWNTIME_FILE} is not too far in the past.
# Return 1 (i.e. false) if it was not recently down.
recently_down
()
{
# If the last known downtime was before no more than 600 seconds
# (i.e. 10 minutes), we consider Traefik to have recently been down.
return
$(
younger_than
${
LAST_KNOWN_DOWNTIME_FILE
}
600
)
}
restart
()
{
touch
${
LAST_KNOWN_RESTART_FILE
}
"
${
BASE_DIR
}
/restart.sh"
}
recently_restarted
()
{
# If the last known restart was before no more than 36000 seconds
# (i.e. 10 hours), we consider Traefik to have recently been restarted.
return
$(
younger_than
${
LAST_KNOWN_RESTART_FILE
}
36000
)
}
if
currently_down
then
if
recently_down
then
if
recently_restarted
then
exit
0
else
echo
"
${
TRAEFIK
}
was unreachable in this and the previous check and hasn't been automatically restarted in a while."
echo
"Restarting..."
restart
fi
else
echo
"
${
TRAEFIK
}
was unreachable, but reachable in the previous check."
echo
"Noting this down for the future..."
touch
${
LAST_KNOWN_DOWNTIME_FILE
}
fi
fi
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment