From e980bbd883546296b82afeb6994defc2469fc6b7 Mon Sep 17 00:00:00 2001 From: Julien Malik Date: Mon, 1 Sep 2014 12:36:31 +0200 Subject: [PATCH] startup script now waits for service availability --- conf/init-script | 25 ++++++++++++++++++++++--- scripts/install | 9 +-------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/conf/init-script b/conf/init-script index 3215c9b..10fef40 100644 --- a/conf/init-script +++ b/conf/init-script @@ -68,6 +68,25 @@ do_start() # Add code here, if necessary, that waits for the process to be ready # to handle requests from services started subsequently which depend # on this one. As a last resort, sleep for some dime. + + ghost_http_request_result=1 + ghost_path=$(yunohost app setting ghostblog path) + count=0 + max_count=60 + while [ "$ghost_http_request_result" != "0" ] + do + [ "$VERBOSE" != no ] && log_action_cont_msg "." + + if [ "$count" -ge $max_count ]; then + [ "$VERBOSE" != no ] && log_action_cont_msg "Timeout" + return 3 + fi + + curl -kL -X GET http://localhost:2368${ghost_path} > /dev/null 2>&1 + ghost_http_request_result=$? + sleep 1 + count=$(expr $count + 1) + done } # @@ -114,11 +133,11 @@ do_stop() case "$1" in start) - [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME" + [ "$VERBOSE" != no ] && log_action_begin_msg "Starting $DESC" "$NAME" do_start case "$?" in - 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; - 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; + 0|1) [ "$VERBOSE" != no ] && log_action_end_msg 0 ;; + 2) [ "$VERBOSE" != no ] && log_action_end_msg 1 ;; esac ;; stop) diff --git a/scripts/install b/scripts/install index 5eb4531..fb97645 100644 --- a/scripts/install +++ b/scripts/install @@ -122,16 +122,9 @@ sudo service nginx reload sudo yunohost app ssowatconf echo "Registering admin..." -sleep 10 admin_name=$(sudo yunohost user list --json | python ../conf/user_getname.py $admin) admin_mail=$(sudo yunohost user list --json | python ../conf/user_getmail.py $admin) - -# first round initialize -curl -kL -X GET http://127.0.0.1:2368${path%/} -curl -kL -X GET http://127.0.0.1:2368${path%/} - -# setup admin details -curl -kL -X POST http://127.0.0.1:2368${path%/}/ghost/api/v0.1/authentication/setup/ \ +curl -kL -X POST http://localhost:2368${path%/}/ghost/api/v0.1/authentication/setup/ \ --data-urlencode "setup[0][name]=$admin_name" \ --data-urlencode "setup[0][email]=$admin_mail" \ --data-urlencode "setup[0][password]=$password" \