Avoid database starting when other devshell is already running, allow devshell in non-root folders

This commit is contained in:
xenia 2023-08-11 17:07:09 +02:00
parent bf1d61f733
commit d5b58e8df3

View File

@ -1,3 +1,9 @@
cd "$(git rev-parse --show-toplevel)"
# Check for lock
[ -f matabas-db/dev-lock ]
IS_OWNER=$? # non-zero is owner
set -e set -e
export PGPORT=2137 export PGPORT=2137
@ -8,11 +14,15 @@ log() {
printf "\e[1m\e[38;5;87m==>\e[0m\e[1m %s%s\e[0m\n" "$1" "${2:-.}" printf "\e[1m\e[38;5;87m==>\e[0m\e[1m %s%s\e[0m\n" "$1" "${2:-.}"
} }
# Only trapped if owner
exitHook() { exitHook() {
cd "$(git rev-parse --show-toplevel)"
log "Stoppar brevekorren" log "Stoppar brevekorren"
pg_ctl stop --pgdata=./matabas-db pg_ctl stop --pgdata=./matabas-db
rm -f matabas-db/dev-lock
} }
setupDb() {
log "Letar efter existerande brevekorresmapp" log "Letar efter existerande brevekorresmapp"
[ -d ./matabas-db ] || { [ -d ./matabas-db ] || {
log "Finns ej, skapar brevekorresmapp (./matabas-db)" log "Finns ej, skapar brevekorresmapp (./matabas-db)"
@ -27,6 +37,8 @@ log "Letar efter existerande brevekorresmapp"
log "Startar brevekorren" log "Startar brevekorren"
pg_ctl start --pgdata=./matabas-db --log=./matabas-db/matabas.log --options="-p $PGPORT -k /tmp" pg_ctl start --pgdata=./matabas-db --log=./matabas-db/matabas.log --options="-p $PGPORT -k /tmp"
log "Låser databasen"
:> matabas-db/dev-lock
trap exitHook EXIT trap exitHook EXIT
log "Skapar matabas" log "Skapar matabas"
@ -34,6 +46,7 @@ createdb -h localhost -p "$PGPORT" matabas 2>>./matabas-db/matabas.log || log "M
log "Ställer in schema.sql" log "Ställer in schema.sql"
psql -h localhost -p "$PGPORT" "$PBDATABASE" < schema.sql psql -h localhost -p "$PGPORT" "$PBDATABASE" < schema.sql
}
P="$PWD" P="$PWD"
clean() { clean() {
@ -45,6 +58,14 @@ build() {
source "$P/buildScripts/build.sh" source "$P/buildScripts/build.sh"
} }
if [ "$IS_OWNER" -ne 0 ] ; then
setupDb
else
log "Startar som icke-ägare, startar ej databasen"
fi
log "Redo" "!" log "Redo" "!"
set +e set +e
cd - >/dev/null 2>&1