forgejo-runner-lib.sh -> forgejo-lib.sh

take stop_daemon from forgejo-runner.sh
take retry from forgejo.sh
This commit is contained in:
Earl Warren 2023-12-17 22:18:19 +01:00
parent 9d5363f5f7
commit 03cebf0f41
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00
3 changed files with 40 additions and 38 deletions

View file

@ -1,10 +1,49 @@
#!/bin/bash #!/bin/bash
# SPDX-License-Identifier: MIT # SPDX-License-Identifier: MIT
set -ex set -e
export DEBIAN_FRONTEND=noninteractive export DEBIAN_FRONTEND=noninteractive
: ${RETRY_DELAYS:=1 1 5 5 15 30}
function retry() {
local tmp=/tmp
rm -f $tmp/retry.out
success=false
for delay in $RETRY_DELAYS ; do
if "$@" >> $tmp/retry.out 2>&1 ; then
success=true
break
fi
cat $tmp/retry.out
echo waiting $delay
sleep $delay
done
if test $success = false ; then
cat $tmp/retry.out
return 1
fi
}
function stop_daemon() {
local daemon=$1
local dir=${2:-.}
if test -f $dir/$daemon-pid ; then
local pid=$(cat $dir/$daemon-pid)
kill -TERM $pid
pidwait $pid || true
for delay in 1 1 2 2 5 5 ; do
if ! test -f $dir/$daemon-pid ; then
break
fi
sleep $delay
done
! test -f $dir/$daemon-pid
fi
}
function dependency_go() { function dependency_go() {
go_version="1.21.4.linux-amd64" # Set the desired Go version here go_version="1.21.4.linux-amd64" # Set the desired Go version here

View file

@ -69,24 +69,6 @@ function setup() {
run run
} }
function stop_daemon() {
local daemon=$1
local DIR=.
if test -f $DIR/$daemon-pid ; then
local pid=$(cat $DIR/$daemon-pid)
kill -TERM $pid
pidwait $pid || true
for delay in 1 1 2 2 5 5 ; do
if ! test -f $DIR/$daemon-pid ; then
break
fi
sleep $delay
done
! test -f $DIR/$daemon-pid
fi
}
function teardown() { function teardown() {
stop_daemon forgejo-runner stop_daemon forgejo-runner
rm -fr $(cat forgejo-runner-home) rm -fr $(cat forgejo-runner-home)

View file

@ -6,25 +6,6 @@ set -e
DIR=/tmp DIR=/tmp
if ${VERBOSE:-false}; then set -x; fi if ${VERBOSE:-false}; then set -x; fi
: ${CONTAINER:=forgejo} : ${CONTAINER:=forgejo}
: ${RETRY_DELAYS:=1 1 5 5 15 30}
function retry() {
rm -f $DIR/retry.out
success=false
for delay in $RETRY_DELAYS ; do
if "$@" >> $DIR/retry.out 2>&1 ; then
success=true
break
fi
cat $DIR/retry.out
echo waiting $delay
sleep $delay
done
if test $success = false ; then
cat $DIR/retry.out
return 1
fi
}
function run() { function run() {
local image="$1" local image="$1"