diff --git a/luci-app-zapret/htdocs/luci-static/resources/view/zapret/tools.js b/luci-app-zapret/htdocs/luci-static/resources/view/zapret/tools.js index 90d86f9..c73532e 100644 --- a/luci-app-zapret/htdocs/luci-static/resources/view/zapret/tools.js +++ b/luci-app-zapret/htdocs/luci-static/resources/view/zapret/tools.js @@ -809,11 +809,23 @@ return baseclass.extend({ { ticks += 1; try { + if (retCode < 0) { + let rc = await fs.exec('/bin/cat', [ rcFile ], null); + if (rc.code != 0) { + fixLogEnd(); + resolve(callback.call(ctx, 542, 'ERROR: cannot read file "' + rcFile + '"')); + return; + } + if (rc.stdout) { + retCode = parseInt(rc.stdout.trim(), 10); + } + } let res = await fs.exec('/bin/cat', [ logFile ], null); if (res.code != 0) { if (ticks > 1) { console.log('ERROR: execAndRead: '+JSON.stringify(opt_list)); - resolve(callback.call(ctx, 541, 'ERROR: Failed on read process log: code = ' + res.code)); + fixLogEnd(); + resolve(callback.call(ctx, 546, 'ERROR: Failed on read process log: code = ' + res.code)); return; } setTimeout(epoll, 500); @@ -831,17 +843,6 @@ return baseclass.extend({ appendLog(log, ''); lastLen = res.stdout.length; } - if (retCode < 0) { - let rc = await fs.exec('/bin/cat', [ rcFile ], null); - if (rc.code != 0) { - fixLogEnd(); - resolve(callback.call(ctx, 545, 'ERROR: cannot read file "' + rcFile + '"')); - return; - } - if (rc.stdout) { - retCode = parseInt(rc.stdout.trim(), 10); - } - } if (retCode >= 0) { fixLogEnd(); if (retCode == 0 && res.stdout) { diff --git a/zapret/script-exec.sh b/zapret/script-exec.sh index 80b0831..f174469 100755 --- a/zapret/script-exec.sh +++ b/zapret/script-exec.sh @@ -1,13 +1,18 @@ #!/bin/sh # Copyright (c) 2024 remittor -awk -V PID_FILE=/tmp/zapret-script-exec.pid -[ -f $PID_FILE ] && exit 70 +if [ -f $PID_FILE ]; then + echo "ERROR: file $PID_FILE already exists!" | awk 'NR==1' + exit 70 +fi LOG_FILE=$1 RC_FILE=$1.rc SH_FILE=$2 shift 2 -[ ! -f $SH_FILE ] && exit 71 +if [ ! -f $SH_FILE ]; then + echo "ERROR: script $SH_FILE not found!" | awk 'NR==1' + exit 71 +fi : > $LOG_FILE : > $RC_FILE start-stop-daemon -S -b -p $PID_FILE -x /bin/sh -- -c ' @@ -17,7 +22,13 @@ start-stop-daemon -S -b -p $PID_FILE -x /bin/sh -- -c ' shift 3 sh $SH_FILE "$@" > $LOG_FILE 2>&1 RET_CODE=$? - sleep 1 + wc -l $LOG_FILE >/dev/null echo $RET_CODE > $RC_FILE ' sh $LOG_FILE $RC_FILE $SH_FILE "$@" +RET_CODE=$? +if [ $RET_CODE != 0 ]; then + echo "ERROR: script $SH_FILE not executed! ret_code = $RET_CODE" | awk 'NR==1' + exit $RET_CODE +fi +echo "Script $SH_FILE running..." | awk 'NR==1' exit 0