Skip to content

Commit

Permalink
let db-bootstrap check sync endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
linl33 committed Jul 25, 2017
1 parent 346bb49 commit 0cc27d5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ Same as [sync-endpoint-containers](https://github.com/jbeorse/sync-endpoint-cont
3. Navigate to `https://127.0.0.1:40000` and create a user, see the [LDAP](#ldap) section below for detail
4. Sync endpoint is now running at `http://127.0.0.1`

Sometimes the Sync endpoint service is started before the database service, when this happens remove the stack and recreate it.

## Clean up

1. Remove the stack with, `docker stack rm syncldap`
Expand Down
20 changes: 16 additions & 4 deletions db-bootstrap/bootstrap.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh -eu
#!/bin/sh -u

set -o pipefail

Expand All @@ -10,9 +10,9 @@ if [ ${DB_BOOTSTRAP} != true ]; then
exit 0
fi;

# sleep 5 seconds to wait for db service to be created
# sleep 10 seconds to wait for db service to be created
# TODO: test for it in a loop instead
sleep 5
sleep 10

STACK_NAME=$(docker ps -f "ID=${HOSTNAME}" --format '{{ .Names }}' | grep -oE '^[^_]*')
DB_VAR=$(docker service inspect -f "{{if eq \"${STACK_NAME}_db\" .Spec.Name}}{{.Spec.TaskTemplate.ContainerSpec.Image}}{{end}}" $(docker service ls -q) | grep -oE '^[^:]*')
Expand Down Expand Up @@ -53,6 +53,18 @@ esac

echo "Done"

# TODO ping Sync after db bootstrap done
echo "Checking Sync endpoint"

# Wait 5 seconds for a 200 from Sync
timeout -t 5 sh -c 'while ! echo -ne "GET / HTTP/1.1\nHost: sync\n\n" | nc -w 1 sync 8080 | grep -q "HTTP/1.1 200"; do echo '\''waiting for Sync'\''; sleep 1; done'

if [ $? -eq 143 ]; then
echo "Timeout"
echo "Killing Sync endpoint"
# let Docker restart the container
docker kill $(docker ps -f "label=com.docker.swarm.service.name=${STACK_NAME}_sync" --format '{{.ID}}')
fi;

echo "Exit"

exit 0
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ services:
- "80:8080"
env_file:
- sync.env
# uncomment these after uncomment the ones below in the root level configs
# uncomment these after uncommenting the ones below in the root level configs
# configs:
# - org.opendatakit.sync.ldapcert
# - org.opendatakit.aggregate.logging.properties
Expand Down

0 comments on commit 0cc27d5

Please sign in to comment.