Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
H
hivemind
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
hive
hivemind
Commits
a54327ef
Commit
a54327ef
authored
6 years ago
by
roadscape
Browse files
Options
Downloads
Patches
Plain Diff
hivesync fixes, add sync-health check
parent
ae16952d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
hive/server/serve.py
+7
-0
7 additions, 0 deletions
hive/server/serve.py
scripts/entrypoint.sh
+1
-0
1 addition, 0 deletions
scripts/entrypoint.sh
scripts/hivesync.sh
+4
-3
4 additions, 3 deletions
scripts/hivesync.sh
with
12 additions
and
3 deletions
hive/server/serve.py
+
7
−
0
View file @
a54327ef
...
@@ -101,6 +101,12 @@ def run_server():
...
@@ -101,6 +101,12 @@ def run_server():
app
.
on_startup
.
append
(
init_db
)
app
.
on_startup
.
append
(
init_db
)
app
.
on_cleanup
.
append
(
close_db
)
app
.
on_cleanup
.
append
(
close_db
)
async
def
head_age
(
request
):
#pylint: disable=unused-argument
healthy_age
=
3600
# one hour
curr_age
=
(
await
hive_api
.
db_head_state
())[
'
db_head_age
'
]
status
=
500
if
curr_age
>
healthy_age
else
200
return
web
.
Response
(
status
=
status
,
text
=
str
(
curr_age
))
async
def
health
(
request
):
async
def
health
(
request
):
#pylint: disable=unused-argument
#pylint: disable=unused-argument
...
@@ -134,6 +140,7 @@ def run_server():
...
@@ -134,6 +140,7 @@ def run_server():
return
web
.
json_response
(
response
,
status
=
200
,
headers
=
{
'
Access-Control-Allow-Origin
'
:
'
*
'
})
return
web
.
json_response
(
response
,
status
=
200
,
headers
=
{
'
Access-Control-Allow-Origin
'
:
'
*
'
})
app
.
router
.
add_get
(
'
/.well-known/healthcheck.json
'
,
health
)
app
.
router
.
add_get
(
'
/.well-known/healthcheck.json
'
,
health
)
app
.
router
.
add_get
(
'
/head_age
'
,
head_age
)
app
.
router
.
add_get
(
'
/health
'
,
health
)
app
.
router
.
add_get
(
'
/health
'
,
health
)
app
.
router
.
add_post
(
'
/
'
,
jsonrpc_handler
)
app
.
router
.
add_post
(
'
/
'
,
jsonrpc_handler
)
...
...
This diff is collapsed.
Click to expand it.
scripts/entrypoint.sh
+
1
−
0
View file @
a54327ef
...
@@ -42,6 +42,7 @@ else
...
@@ -42,6 +42,7 @@ else
mkdir
-p
/etc/service/hivesync
mkdir
-p
/etc/service/hivesync
cp
/usr/local/bin/hivesync.sh /etc/service/hivesync/run
cp
/usr/local/bin/hivesync.sh /etc/service/hivesync/run
chmod
+x /etc/service/hivesync/run
chmod
+x /etc/service/hivesync/run
echo
hivemind: starting hivesync service
runsv /etc/service/hivesync
runsv /etc/service/hivesync
fi
fi
...
...
This diff is collapsed.
Click to expand it.
scripts/hivesync.sh
+
4
−
3
View file @
a54327ef
#!/bin/bash
#!/bin/bash
# if the indexer dies by itself, kill runsv causing the container to exit
# if the indexer dies by itself, kill runsv causing the container to exit
HIVESYNC_PID
=
`
pgrep
-f
sync
`
HIVESYNC_PID
=
`
pgrep
-f
'hive
sync
'
`
if
[[
!
$?
-eq
0
]]
;
then
if
[[
!
$?
-eq
0
]]
;
then
echo
NOTIFYALERT! hivemindsync has quit unexpectedly, killing container and starting a new instance..
echo
NOTIFYALERT! hivemindsync has quit unexpectedly, killing container and starting a new instance..
sleep
30
sleep
30
...
@@ -9,7 +9,8 @@ if [[ ! $? -eq 0 ]]; then
...
@@ -9,7 +9,8 @@ if [[ ! $? -eq 0 ]]; then
kill
-9
$RUN_SV_PID
kill
-9
$RUN_SV_PID
fi
fi
HTTP_CODE
=
`
curl
-I
-s
-o
/dev/null
-w
"%{http_code}"
http://127.0.0.1/health/
`
# NOTE: this API endpoint returns head age in seconds, and a 200 code if it's less than 3600
HTTP_CODE
=
`
curl
-I
-s
-o
/dev/null
-w
"%{http_code}"
http://127.0.0.1/head_age
`
# if we get a 200 then hive is synced, start syncing operation
# if we get a 200 then hive is synced, start syncing operation
if
[[
${
HTTP_CODE
}
-eq
200
]]
;
then
if
[[
${
HTTP_CODE
}
-eq
200
]]
;
then
...
@@ -44,4 +45,4 @@ if [[ ${HTTP_CODE} -eq 200 ]]; then
...
@@ -44,4 +45,4 @@ if [[ ${HTTP_CODE} -eq 200 ]]; then
fi
fi
# check every 60 seconds if synced
# check every 60 seconds if synced
sleep
60
sleep
60
\ No newline at end of file
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