2022-04-18 11:21:20 +08:00

77 lines
1.6 KiB
Bash
Executable File

#!/bin/bash
##################################################
# Mount dir #
# - /var/lib/gitea #
# - /var/log/gitea #
##################################################
set -euo pipefail
export LANG=en_US.UTF-8
trap Quit EXIT
PIDS=
GOT_SIGTERM=
function Print {
local file=/dev/null
[ '-f' = "$1" ] && file=$2 && shift && shift
date +"[%F %T] $*" | tee -a $file
}
function Quit {
while :; do
pkill -f gitea && Print killing gitea ... || break
sleep 1
done
Print Container stopped.
test -n "$GOT_SIGTERM"
}
function Usage {
Print 'This container should run with
**root user**
**/var/{lib,log}/gitea mounted from host**
'
}
function RestoreConf {
if [ -z "$(ls gitea/)" ]; then
Print Restore default config files and quit ...
tar zxf gitea.tgz
exit
fi
}
function ChangeOwner {
Print Change file owner ...
chown -R gitea.www-data gitea/ /var/log/gitea/
}
function StartProc {
Print Start gitea ...
su - gitea -c '
gitea web --config /var/lib/gitea/custom/conf/app.ini
' &>> /var/log/gitea/gitea.out &
PIDS="$PIDS $!"
}
function Main {
local pid=
cd /var/lib
Usage
RestoreConf
ChangeOwner
StartProc
trap "GOT_SIGTERM=1; Print Got SIGTERM ..." SIGTERM
while [ -z "$GOT_SIGTERM" ] && sleep 1; do
for pid in $PIDS; do
[ ! -e /proc/$pid ] && Print Unexpected error! && exit
done
done
}
# Start here
Main