From 2461666aca3716d22194596504e8e321eef9c131 Mon Sep 17 00:00:00 2001 From: Earl Warren Date: Tue, 4 Jun 2024 13:04:05 +0200 Subject: [PATCH] lib: use the WORK_PATH base instead of forgejo for the daemon Instead of hardcoding "forgejo" as the base for the daemon to store the PID and the logs, use the base of the WORK_PATH so that a given work path can run a dedicated forgejo instance by the same name. --- actions/actions.sh | 2 +- lib/lib.sh | 48 +++++++++++++++++++++++++++++++--------------- packages/alpine.sh | 2 +- 3 files changed, 35 insertions(+), 17 deletions(-) diff --git a/actions/actions.sh b/actions/actions.sh index dd38510..ac114de 100755 --- a/actions/actions.sh +++ b/actions/actions.sh @@ -74,7 +74,7 @@ function actions_setup() { function actions_teardown() { forgejo-curl.sh logout forgejo-runner.sh teardown - stop_daemon forgejo + stop_forgejo } function actions_runner_version() { diff --git a/lib/lib.sh b/lib/lib.sh index 8930e44..0c4c843 100644 --- a/lib/lib.sh +++ b/lib/lib.sh @@ -141,9 +141,12 @@ function download() { } function cleanup_logs() { - local work_path=$DIR/forgejo-work-path + local config=$1 - rm -f $DIR/*.log + local base=$(work_path_base $config) + local work_path=$DIR/$base + + rm -f $DIR/$base*.log rm -f $work_path/log/*.log } @@ -151,21 +154,30 @@ function clobber() { rm -fr /tmp/forgejo-end-to-end } +function stop_forgejo() { + local config=$1 + + stop_daemon $(work_path_base $config) +} + function start_forgejo() { local version=$1 + local config=$2 download $version - start_forgejo_daemon $version $DIR_BINARIES/forgejo-$version + start_forgejo_daemon $version $DIR_BINARIES/forgejo-$version $config } function start_forgejo_daemon() { local version=$1 local binary=$2 + local config=$3 - local work_path=$DIR/forgejo-work-path - daemon --chdir=$DIR --unsafe --env="TERM=$TERM" --env="HOME=$HOME" --env="PATH=$PATH" --pidfile=$DIR/forgejo-pid --errlog=$DIR/forgejo-err.log --output=$DIR/forgejo-out.log -- $binary --config $work_path/app.ini --work-path $work_path + local base=$(work_path_base $config) + local work_path=$DIR/$base + daemon --chdir=$DIR --unsafe --env="TERM=$TERM" --env="HOME=$HOME" --env="PATH=$PATH" --pidfile=$DIR/$base-pid --errlog=$DIR/$base-err.log --output=$DIR/$base-out.log -- $binary --config $work_path/app.ini --work-path $work_path if ! retry grep --no-messages --quiet 'Starting server on' $work_path/log/forgejo.log ; then - grep '' $DIR/*.log + grep '' $DIR/$base*.log grep '' $work_path/log/*.log 2> /dev/null return 1 fi @@ -245,14 +257,18 @@ function start() { start_forgejo $version } +function work_path_base() { + local config="$1" + if test -z "$config" ; then + echo forgejo-work-path + else + sed -n -e 's/^WORK_PATH *= *\(.*\)/\1/p' < $config + fi +} + function reset_forgejo() { local config=$1 - local work_path_base=$(sed -n -e 's/^WORK_PATH *= *\(.*\)/\1/p' < $config) - if test -z "$work_path_base" ; then - echo "no line found starting with WORK_PATH = in the file $config" - return 1 - fi - local work_path=$DIR/$work_path_base + local work_path=$DIR/$(work_path_base $config) rm -fr $work_path mkdir -p $work_path sed -e "s/\${IP}/$IP/g" \ @@ -303,11 +319,13 @@ function stop_daemon() { } function stop() { - stop_daemon forgejo + local config="$1" + + stop_forgejo $config stop_daemon minio stop_daemon garage - cleanup_logs + cleanup_logs $config } function show_logs() { @@ -315,7 +333,7 @@ function show_logs() { cd $DIR set +e grep --with-filename --text '' *.log - grep --with-filename --text '' forgejo-work-path/log/*.log + grep --with-filename --text '' */log/*.log grep --with-filename --text '' *.out ) } diff --git a/packages/alpine.sh b/packages/alpine.sh index b3e5b5d..ae82913 100644 --- a/packages/alpine.sh +++ b/packages/alpine.sh @@ -3,7 +3,7 @@ function test_packages_alpine_version() { local alpine_version=$1 forgejo_version=$2 - stop_daemon forgejo + stop_forgejo reset_forgejo $PACKAGES_DIR/alpine-app.ini start_forgejo $forgejo_version