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.
This commit is contained in:
Earl Warren 2024-06-04 13:04:05 +02:00
parent 4a19e9c90b
commit 2461666aca
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00
3 changed files with 35 additions and 17 deletions

View file

@ -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
)
}