nom-nom-nix-gc/run-dev-server
2023-11-27 12:09:26 +01:00

40 lines
918 B
Bash
Executable file

#!/usr/bin/env bash
set -eau
dbname="nomnomdev"
port="12345"
dbdir="$(mktemp -d)"
cfgfile="${dbdir}/config.json"
trap 'rm -rf ${dbdir}' EXIT
initdb "$dbdir"
postgres -D "${dbdir}" -c unix_socket_directories="${dbdir}" -c listen_addresses= -c port="${port}" &
pgpid=$!
# Trick to help the "./psql" script to find the DB dir & co
cat <<EOF > "/tmp/nom-nom-dev-args"
export host="$dbdir"
export port="$port"
export dbname="$dbname"
export cfgfile="$cfgfile"
EOF
trap 'rm -rf ${dbdir} && rm /tmp/nom-nom-dev-args && kill ${pgpid}' EXIT
# Yeah, this is very meh. We need to wait for the server to be ready
#to receive requests to create the DB.
sleep 2
createdb -h "${dbdir}" -p "${port}" "${dbname}"
cat <<EOF > "${cfgfile}"
{
"url": "http://localhost:8001",
"db_host": "${dbdir}",
"db_port": ${port},
"db_name": "${dbname}"
}
EOF
cargo run --bin nom-nom-gc-server -- --bind "[::1]:8001" --config "${cfgfile}"