diff --git a/debian/postgrest.default b/debian/postgrest.default index 33dab96cc..fe0141969 100644 --- a/debian/postgrest.default +++ b/debian/postgrest.default @@ -7,17 +7,26 @@ # database host #POSTGREST_DBHOST=localhost +# database host +#POSTGREST_DBPORT=5432 + # database to use -#POSTGREST_DBNAME= +#POSTGREST_DBNAME=app # database user -#POSTGREST_DBUSER=postgres +#POSTGREST_DBUSER=authenticator # database password #POSTGREST_DBPASS= # database pool -#POSTGREST_DBPOOL=10 +#POSTGREST_POOL=10 -# additional options -#POSTGREST_OPTS= +# jwt secret +#POSTGREST_JWT_SECRET=secret + +# default schema +#POSTGREST_SCHEMA=public + +# secure (use 1 to enable, empty string to disable) +#POSTGREST_SECURE= diff --git a/debian/postgrest.init.d b/debian/postgrest.init.d index 2227d8c07..a9091740e 100755 --- a/debian/postgrest.init.d +++ b/debian/postgrest.init.d @@ -13,31 +13,52 @@ if test -f /etc/default/postgrest; then . /etc/default/postgrest fi POSTGREST=/usr/local/bin/postgrest +CONNECTION_STRING="postgres://" +POSTGREST_OPTS="" POSTGREST_USER=${POSTGREST_USER:-postgrest} -POSTGREST_DBNAME=${POSTGREST_DBNAME:-postgres} -POSTGREST_DBUSER=${POSTGREST_DBUSER:-postgres} -if [ -n "$POSTGREST_DBHOST" ]; then - POSTGREST_OPTS="$POSTGREST_OPTS --db-host $POSTGREST_DBHOST" -fi -if [ -n "$POSTGREST_DBNAME" ]; then - POSTGREST_OPTS="$POSTGREST_OPTS --db-name $POSTGREST_DBNAME" -fi -if [ -n "$POSTGREST_DBUSER" ]; then - POSTGREST_OPTS="$POSTGREST_OPTS --db-user $POSTGREST_DBUSER" - POSTGREST_OPTS="$POSTGREST_OPTS --anonymous $POSTGREST_DBUSER" -fi +POSTGREST_PORT=${POSTGREST_PORT:-3000} +POSTGREST_DBUSER=${POSTGREST_DBUSER:-authenticator} +#POSTGREST_DBPASS=${POSTGREST_DBPASS:-authenticator} +POSTGREST_DBHOST=${POSTGREST_DBHOST:-localhost} +POSTGREST_DBPORT=${POSTGREST_DBPORT:-5432} +POSTGREST_DBNAME=${POSTGREST_DBNAME:-app} +POSTGREST_DBPOOL=${POSTGREST_DBPOOL:-10} +POSTGREST_ANON=${POSTGREST_ANON:-anonymous} +POSTGREST_JWT_SECRET=${POSTGREST_JWT_SECRET:-secret} +POSTGREST_SCHEMA=${POSTGREST_SCHEMA:-public} + +CONNECTION_STRING="$CONNECTION_STRING$POSTGREST_DBUSER" if [ -n "$POSTGREST_DBPASS" ]; then - POSTGREST_OPTS="$POSTGREST_OPTS --db-pass $POSTGREST_DBPASS" + CONNECTION_STRING="$CONNECTION_STRING:$POSTGREST_DBPASS" fi -if [ -n "$POSTGREST_DBPOOL" ]; then - POSTGREST_OPTS="$POSTGREST_OPTS --db-pool $POSTGREST_DBPOOL" +CONNECTION_STRING="$CONNECTION_STRING@$POSTGREST_DBHOST:$POSTGREST_DBPORT/$POSTGREST_DBNAME" + +if [ -n "$POSTGREST_PORT" ]; then + POSTGREST_OPTS="$POSTGREST_OPTS --port $POSTGREST_PORT" fi -POSTGREST_OPTS="$POSTGREST_OPTS --schema public" + +if [ -n "$POSTGREST_POOL" ]; then + POSTGREST_OPTS="$POSTGREST_OPTS --pool $POSTGREST_POOL" +fi +if [ -n "$POSTGREST_JWT_SECRET" ]; then + #export POSTGREST_JWT_SECRET="$POSTGREST_JWT_SECRET" + POSTGREST_OPTS="$POSTGREST_OPTS --jwt-secret $POSTGREST_JWT_SECRET" +fi +if [ -n "$POSTGREST_SCHEMA" ]; then + POSTGREST_OPTS="$POSTGREST_OPTS --schema $POSTGREST_SCHEMA" +fi +if [ -n "$POSTGREST_ANON" ]; then + POSTGREST_OPTS="$POSTGREST_OPTS --anonymous $POSTGREST_ANON" +fi + +#export CONNECTION_STRING="$CONNECTION_STRING" + +START_PARAMS="$CONNECTION_STRING $POSTGREST_OPTS" start() { log_daemon_msg "Starting PostgreSQL REST API daemon" "postgrest" || true - if start-stop-daemon --start --quiet --oknodo --chuid ${POSTGREST_USER} --startas /usr/local/bin/postgrest-wrapper --exec $POSTGREST -- $POSTGREST_OPTS; then + if start-stop-daemon --start --quiet --oknodo --chuid ${POSTGREST_USER} --startas /usr/local/bin/postgrest-wrapper --exec $POSTGREST -- $START_PARAMS; then log_end_msg 0 || true else log_end_msg 1 || true