From f82491f864d34e1557f9b2d7414a7a1cecaf497a Mon Sep 17 00:00:00 2001 From: Avi Date: Tue, 14 Nov 2017 03:07:55 -0600 Subject: [PATCH 1/2] Wait for ombi to complete startup before reporting success (#8) --- update_ombi.sh | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/update_ombi.sh b/update_ombi.sh index f522830..9cc7dec 100644 --- a/update_ombi.sh +++ b/update_ombi.sh @@ -38,6 +38,7 @@ defaultinstalldir="/opt/Ombi" ## User and Group Ombi runs as ## defaultuser="ombi" defaultgroup="nogroup" +defaulturl="http://127.0.0.1:5000" ## Level of verbosity ## ## By default, none ## @@ -50,7 +51,7 @@ declare -i verbosity=-1 ############################################ name="update_ombi" -version="1.0.12" +version="1.0.13" while [ $# -gt 0 ]; do case "$1" in @@ -123,7 +124,8 @@ if [ -e $ombiservicefile ]; then installdir=$(grep -Po '(?<=WorkingDirectory=)(\S|(?<=\\)\s)+' <<< "$ombiservice") user=$(grep -Po '(?<=User=)(\w+)' <<< "$ombiservice") group=$(grep -Po '(?<=Group=)(\w+)' <<< "$ombiservice") - .log 6 "Parsing complete: InstallDir: $installdir, User: $user, Group: $group" + url=$(grep -Po '(?<=\-\-host )(.+)$' <<< "$ombiservice") + .log 6 "Parsing complete: InstallDir: $installdir, User: $user, Group: $group, URL: $url" fi if [ -z ${installdir+x} ]; then @@ -138,6 +140,11 @@ if [ -z ${group+x} ]; then .log 5 "Group not parsed...setting to default: $defaultgroup" group="$defaultgroup" fi +if [ -z ${url+x} ]; then + .log 5 "URL not parsed...setting to default: $defaulturl" + url="$defaulturl" +fi + .log 6 "Downloading Ombi update..." declare -i i=1 @@ -181,7 +188,7 @@ do done tempdir=$(mktemp -d) file="$tempdir/ombi_$version.tar.gz" -wget --quiet -O $file "https://ci.appveyor.com/api/buildjobs/$jobId/artifacts/linux.tar.gz" +wget --quiet --show-progress -O $file "https://ci.appveyor.com/api/buildjobs/$jobId/artifacts/linux.tar.gz" .log 6 "Version $version downloaded...checking file size..." if [ $(wc -c < $file) != $size ]; then .log 3 "Downloaded file size does not match expected file size...bailing!" @@ -194,7 +201,7 @@ if [ "`systemctl is-active $ombiservicename`" == "active" ]; then running=1 .log 6 "Ombi is active...attempting to stop..." declare -i i=1 - j=5 + declare -i j=5 while [ $i -le $j ] do if [ $scriptuser = "root" ]; then @@ -231,7 +238,7 @@ chown -R $user:$group $installdir if [ $running -eq 1 ]; then .log 6 "Ownership set...starting Ombi..." declare -i i=1 - j=5 + declare -i j=5 while [ $i -le $j ] do if [ $scriptuser = "root" ]; then @@ -250,7 +257,27 @@ if [ $running -eq 1 ]; then i+=1 continue elif [ "`systemctl is-active $ombiservicename`" == "active" ]; then - .log 6 "Ombi started...cleaning up..." + .log 6 "Ombi started...waiting for confirmation..." + declare -i k=1 + declare -i l=5 + while [ $k -le $l ] + do + sleep 5 + curl -sIL $url > /dev/null 2>&1 + if [ $? -ne 0 ]; then + if [ $k -lt $l ]; then + .log 4 "Ombi startup not confirmed...waiting 5 seconds...[attempt $k of $l]" + else + .log 2 "Ombi startup not confirmed...[attempt $k of $l]...bailing!" + exit 4 + fi + k+=1 + continue + else + .log 6 "Ombi startup confirmed...cleaning up..." + break + fi + done break else .log 1 "Unknown error...bailing!" From bbe3cf89f8776e09c3195651ce842cb0e3db3819 Mon Sep 17 00:00:00 2001 From: Avi Date: Tue, 14 Nov 2017 03:39:34 -0600 Subject: [PATCH 2/2] Timestamps and elapsed time (#9) * Timestamps and elapsed time Generate timestamps for logging Report elapsed time after script completion. --- update_ombi.sh | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/update_ombi.sh b/update_ombi.sh index 9cc7dec..9fd9eff 100644 --- a/update_ombi.sh +++ b/update_ombi.sh @@ -51,7 +51,8 @@ declare -i verbosity=-1 ############################################ name="update_ombi" -version="1.0.13" +version="1.0.14" +SECONDS=0 while [ $# -gt 0 ]; do case "$1" in @@ -80,11 +81,11 @@ function .log () { shift if [[ $verbosity =~ ^-?[0-8]$ ]]; then if [ $verbosity -ge $LEVEL ]; then - echo "[${LOG_LEVELS[$LEVEL]}]" "$@" + echo "[$(date '+%H:%M:%S')] [${LOG_LEVELS[$LEVEL]}]" "$@" fi fi if [ $verbosity -eq 8 ] || [ $LEVEL -ne 8 ]; then - echo "[${LOG_LEVELS[$LEVEL]}]" "$@" >> $logfile + echo "[$(date '+%Y-%m-%d %H:%M:%S %Z' -u)] [${LOG_LEVELS[$LEVEL]}]" "$@" >> $logfile fi } @@ -290,4 +291,20 @@ fi .log 6 "Cleaning up..." rm -rf "$tempdir"/* "$tempdir" -.log 6 "Update complete" +declare -i elapsedtime=$SECONDS +if [ $elapsedtime -ge 60 ]; then + minutes=$(($elapsedtime / 60)) +fi +seconds=$(($elapsedtime % 60)) +if [ $minutes -ge 2 ]; then + duration="$minutes minutes" +elif [ $minutes -eq 1 ]; then + duration="$minutes minute" +fi +if [ $seconds -ge 2 ]; then + duration+=" $seconds seconds" +elif [ $seconds -eq 1 ]; then + duration+=" $seconds second" +fi +duration="${duration// / }" +.log 6 "Update complete...elapsed time $duration..." \ No newline at end of file