From 6fc1447fa652fd2a52935c9c5742733c51671a09 Mon Sep 17 00:00:00 2001 From: neil Date: Tue, 12 Apr 2016 23:18:22 +0800 Subject: [PATCH 1/4] add timeout for nc. --- le.sh | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/le.sh b/le.sh index 40772907..fd386226 100755 --- a/le.sh +++ b/le.sh @@ -618,7 +618,7 @@ _saveaccountconf() { _startserver() { content="$1" - + _debug "startserver: $$" nchelp="$(nc -h 2>&1)" if echo "$nchelp" | grep "\-q[ ,]" >/dev/null ; then @@ -646,13 +646,24 @@ _startserver() { fi if [[ "$?" != "0" ]] ; then _err "nc listen error." - return 1 + exit 1 fi # done } -_stopserver() { +_stopserver(){ pid="$1" + _debug "pid" "$pid" + if [[ -z "$pid" ]] ; then + return + fi + + if [[ "$(ps | grep "$pid" | grep "nc")" ]] ; then + _debug "Found nc process, kill it." + kill -s 9 $pid > /dev/null 2>&1 + fi + + _get "http://localhost:$Le_HTTPPort" >/dev/null 2>$1 } @@ -1184,9 +1195,13 @@ issue() { if [[ "$_currentRoot" == "no" ]] ; then _info "Standalone mode server" _startserver "$keyauthorization" & + if [[ "$?" != "0" ]] ; then + return 1 + fi serverproc="$!" sleep 2 _debug serverproc $serverproc + else if [[ -z "$wellknown_path" ]] ; then wellknown_path="$_currentRoot/.well-known/acme-challenge" @@ -1224,7 +1239,20 @@ issue() { return 1 fi + waittimes=0 + if [[ -z "$MAX_RETRY_TIMES" ]] ; then + MAX_RETRY_TIMES=30 + fi + while [[ "1" ]] ; do + let "waittimes+=1" + if [[ "$waittimes" -ge "$MAX_RETRY_TIMES" ]] ; then + _err "$d:Timeout" + _clearupwebbroot "$_currentRoot" "$removelevel" "$token" + _clearup + return 1 + fi + _debug "sleep 5 secs to verify" sleep 5 _debug "checking" @@ -1946,14 +1974,13 @@ _process() { STAGE="1" ;; --debug) - if [[ "$2" == "-"* ]] ; then + if [[ "$2" == "-"* ]] || [[ -z "$2" ]]; then DEBUG="1" else DEBUG="$2" shift - fi + fi ;; - --webroot|-w) wvalue="$2" if [[ -z "$_webroot" ]] ; then From dca09dedace304c083fc2e343ebdebdb967f3f79 Mon Sep 17 00:00:00 2001 From: neil Date: Tue, 12 Apr 2016 23:43:24 +0800 Subject: [PATCH 2/4] kill nc process --- le.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/le.sh b/le.sh index fd386226..d27735c0 100755 --- a/le.sh +++ b/le.sh @@ -658,11 +658,16 @@ _stopserver(){ return fi - if [[ "$(ps | grep "$pid" | grep "nc")" ]] ; then - _debug "Found nc process, kill it." + if [[ "$(ps | grep "$pid")" ]] ; then + _debug "Found proc process, kill it." kill -s 9 $pid > /dev/null 2>&1 fi + for ncid in $(ps | grep nc | cut -d " " -f 1) ; do + _debug "kill $ncid" + kill -s 9 $ncid > /dev/null 2>&1 + done + _get "http://localhost:$Le_HTTPPort" >/dev/null 2>$1 } From 770dc4b23023aa8bb35a21d24aef0609005a48d2 Mon Sep 17 00:00:00 2001 From: neil Date: Tue, 12 Apr 2016 23:47:09 +0800 Subject: [PATCH 3/4] expose the error --- le.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/le.sh b/le.sh index d27735c0..0881c3a8 100755 --- a/le.sh +++ b/le.sh @@ -660,12 +660,12 @@ _stopserver(){ if [[ "$(ps | grep "$pid")" ]] ; then _debug "Found proc process, kill it." - kill -s 9 $pid > /dev/null 2>&1 + kill -s 9 $pid > /dev/null fi for ncid in $(ps | grep nc | cut -d " " -f 1) ; do _debug "kill $ncid" - kill -s 9 $ncid > /dev/null 2>&1 + kill -s 9 $ncid > /dev/null done _get "http://localhost:$Le_HTTPPort" >/dev/null 2>$1 From 233e8a20853d3877e97fc4ae6e8ae703893bfc4e Mon Sep 17 00:00:00 2001 From: neil Date: Wed, 13 Apr 2016 00:24:55 +0800 Subject: [PATCH 4/4] kill nc --- le.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/le.sh b/le.sh index 0881c3a8..8c461fb8 100755 --- a/le.sh +++ b/le.sh @@ -663,7 +663,7 @@ _stopserver(){ kill -s 9 $pid > /dev/null fi - for ncid in $(ps | grep nc | cut -d " " -f 1) ; do + for ncid in $(echo $(ps | grep nc) | cut -d " " -f 1) ; do _debug "kill $ncid" kill -s 9 $ncid > /dev/null done