mirror of
https://code.forgejo.org/actions/setup-forgejo.git
synced 2024-11-27 08:40:57 -05:00
forgejo-runner-lib.sh -> forgejo-lib.sh
take stop_daemon from forgejo-runner.sh take retry from forgejo.sh
This commit is contained in:
parent
9d5363f5f7
commit
03cebf0f41
3 changed files with 40 additions and 38 deletions
|
@ -1,10 +1,49 @@
|
|||
#!/bin/bash
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
set -ex
|
||||
set -e
|
||||
|
||||
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() {
|
||||
go_version="1.21.4.linux-amd64" # Set the desired Go version here
|
||||
|
|
@ -69,24 +69,6 @@ function setup() {
|
|||
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() {
|
||||
stop_daemon forgejo-runner
|
||||
rm -fr $(cat forgejo-runner-home)
|
||||
|
|
19
forgejo.sh
19
forgejo.sh
|
@ -6,25 +6,6 @@ set -e
|
|||
DIR=/tmp
|
||||
if ${VERBOSE:-false}; then set -x; fi
|
||||
: ${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() {
|
||||
local image="$1"
|
||||
|
|
Loading…
Reference in a new issue