Bashスクリプトのバックグラウンドタスク

Bashスクリプトのバックグラウンドタスク

イベントに応答する「true」のときにbashスクリプトを作成しようとしています。 (これはgitプッシュ通知のためのWebフックですが、まだ関連性は高くありません。)

ブロックしてから次のコールバックを待ってビルドを実行した後、再度ブロックすることができますが、ビルドの途中でコールバックを受け取れば見逃すので、次のように解決しようとしました。

# Build loop, run in the background (see "done &" at the bottom)
while true
do
    # If last build start is newer than last push do nothing.
    if [ last-build-start -nt last-push ]
    then
        echo "last-build-start newer than last-push. Doing nothing."
        sleep 3
        continue
    fi
    log "Build triggered $(date)"
    touch last-build-start
    ./build-all-branches.sh
    log "Done. Waiting for next trigger..."
done &

# Terminate above loop upon Ctrl+C
trap "trap - SIGTERM && kill -- -$$" SIGINT SIGTERM EXIT

# Listen for HTTP requests, do nothing but touch last-push
# to trigger a build in the build loop above.
while true
do
    # Wait for hook to be called
    echo -e "HTTP/1.1 200 OK\n\n $(date)" \
        | nc -l 8787 -q 1 > /dev/null

    # Trigger new build
    echo "Triggered... touching last-push"
    touch last-push
done

私が経験している問題は、ビルドループが常にトリガーされないことです。実行されますが、ビルドループの他のインスタンスが起動して高速に実行されるtouch last-pushのと同じです。touch last-build-start

上記のコードで誤って複数のビルドループを起動しましたか?スクリプトに別の愚かな間違いがありますか?

ベストアンサー1

おすすめ記事