#!/usr/bin/env zsh set -eu die() { echo "$0: $*" 1>&2 ; false; } root_dir="$(dirname $(dirname "$0:A"))" pid_file="$root_dir/tmp/cockroach.pid" log_file="$root_dir/tmp/cockroachdb.log" mkdir -p "$root_dir/tmp" [[ -f "$pid_file" ]] && kill -9 $(cat "$pid_file") || true rm -f "$pid_file" if ! (( ${+commands[cockroach]} )); then die 'the `cockroach` toolchain is not installed. See https://www.cockroachlabs.com/docs/stable/install-cockroachdb.html' fi cockroach start-single-node \ --insecure --store=type=mem,size=0.25 --advertise-addr=localhost \ --spatial-libs="$(geos-config --includes)" \ --pid-file "$pid_file" \ &> "$log_file" & until [[ -f "$pid_file" ]]; do sleep 1 done cat "$root_dir/setup.sql" | cockroach sql --insecure --host=localhost:26257 > /dev/null echo "CockroachDB started. PID: $(cat "$pid_file"). log: $log_file"