|
1 | 1 | #!/bin/bash |
2 | 2 |
|
| 3 | +####################################################### |
| 4 | +# taken from https://github.com/grtjn/mlvagrant/blob/master/opt/vagrant/setup-ml-master.sh |
| 5 | +# |
| 6 | +# restart_check(baseline_timestamp, caller_lineno) |
| 7 | +# |
| 8 | +# Use the timestamp service to detect a server restart, given a |
| 9 | +# a baseline timestamp. Use N_RETRY and RETRY_INTERVAL to tune |
| 10 | +# the test length. Include authentication in the curl command |
| 11 | +# so the function works whether or not security is initialized. |
| 12 | +# $1 : The baseline timestamp |
| 13 | +# $2 : Invokers LINENO, for improved error reporting |
| 14 | +# Returns 0 if restart is detected, exits with an error if not. |
| 15 | +# |
| 16 | +function restart_check { |
| 17 | + echo "Restart check for localhost..." |
| 18 | + LAST_START=`$AUTH_CURL --max-time 1 -s "http://localhost:8001/admin/v1/timestamp"` |
| 19 | + for i in `seq 1 ${N_RETRY}`; do |
| 20 | + # continue as long as timestamp didn't change, or no output was returned |
| 21 | + if [ "$1" == "$LAST_START" ] || [ "$LAST_START" == "" ]; then |
| 22 | + sleep ${RETRY_INTERVAL} |
| 23 | + echo "Retrying..." |
| 24 | + LAST_START=`$AUTH_CURL --max-time 1 -s "http://localhost:8001/admin/v1/timestamp"` |
| 25 | + else |
| 26 | + return 0 |
| 27 | + fi |
| 28 | + done |
| 29 | + echo "ERROR: Line $2: Failed to restart localhost" |
| 30 | + exit 1 |
| 31 | +} |
| 32 | + |
3 | 33 | sudo /etc/init.d/MarkLogic start |
4 | 34 | sleep 30 |
5 | 35 | curl -X POST -d "" http://localhost:8001/admin/v1/init |
6 | 36 | sleep 30 |
7 | | -curl -X POST -H "Content-type: application/x-www-form-urlencoded" \ |
| 37 | + |
| 38 | +TIMESTAMP=`curl -X POST \ |
| 39 | + -H "Content-type: application/x-www-form-urlencoded" \ |
8 | 40 | --data "admin-username=admin" \ |
9 | 41 | --data "admin-password=admin" \ |
10 | 42 | --data "realm=public" \ |
11 | | - "http://localhost:8001/admin/v1/instance-admin" |
12 | | -sleep 30 |
| 43 | + "http://localhost:8001/admin/v1/instance-admin" \ |
| 44 | + | grep "last-startup" \ |
| 45 | + | sed 's%^.*<last-startup.*>\(.*\)</last-startup>.*$%\1%'` |
| 46 | + if [ "$TIMESTAMP" == "" ]; then |
| 47 | + echo "ERROR: Failed to get instance-admin timestamp." >&2 |
| 48 | + exit 1 |
| 49 | + fi |
| 50 | + |
| 51 | +restart_check $TIMESTAMP $LINENO |
0 commit comments