From b56ab47f841573a223dbdeb69782a2b9adbefdf3 Mon Sep 17 00:00:00 2001 From: Max Khon Date: Wed, 24 Jun 2015 18:07:30 +0600 Subject: [PATCH] Debian init script for postgrest. --- debian/postgrest-wrapper | 8 +++++ debian/postgrest.default | 23 ++++++++++++ debian/postgrest.init.d | 78 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 109 insertions(+) create mode 100755 debian/postgrest-wrapper create mode 100644 debian/postgrest.default create mode 100755 debian/postgrest.init.d diff --git a/debian/postgrest-wrapper b/debian/postgrest-wrapper new file mode 100755 index 000000000..4abdf5a41 --- /dev/null +++ b/debian/postgrest-wrapper @@ -0,0 +1,8 @@ +#!/bin/sh +d=$(dirname $0) +if [ -f /etc/default/postgrest ]; then + . /etc/default/postgrest +fi +POSTGREST_LOG=${POSTGREST_LOG:-/var/log/postgrest/postgrest.log} + +exec $d/postgrest "$@" >>$POSTGREST_LOG 2>&1 & diff --git a/debian/postgrest.default b/debian/postgrest.default new file mode 100644 index 000000000..33dab96cc --- /dev/null +++ b/debian/postgrest.default @@ -0,0 +1,23 @@ +# run service as +#POSTGREST_USER=postgrest + +# log file +#POSTGREST_LOG=/var/log/postgrest/postgrest.log + +# database host +#POSTGREST_DBHOST=localhost + +# database to use +#POSTGREST_DBNAME= + +# database user +#POSTGREST_DBUSER=postgres + +# database password +#POSTGREST_DBPASS= + +# database pool +#POSTGREST_DBPOOL=10 + +# additional options +#POSTGREST_OPTS= diff --git a/debian/postgrest.init.d b/debian/postgrest.init.d new file mode 100755 index 000000000..6e7897fcd --- /dev/null +++ b/debian/postgrest.init.d @@ -0,0 +1,78 @@ +#!/bin/sh +### BEGIN INIT INFO +# Provides: postgrest +# Required-Start: $local_fs $network postgresql +# Required-Stop: $local_fs $network +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Description: PostgreSQL REST API daemon +### END INIT INFO + +. /lib/lsb/init-functions +if test -f /etc/default/postgrest; then + . /etc/default/postgrest +fi +POSTGREST=/usr/local/bin/postgrest +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 +if [ -n "$POSTGREST_DBPASS" ]; then + POSTGREST_OPTS="$POSTGREST_OPTS --db-pass $POSTGREST_DBPASS" +fi +if [ -n "$POSTGREST_DBPOOL" ]; then + POSTGREST_OPTS="$POSTGREST_OPTS --db-pool $POSTGREST_DBPOOL" +fi +POSTGREST_OPTS="$POSTGREST_OPTS --v1schema public" + +start() +{ + log_daemon_msg "Starting PostgreSQL REST API daemon" "postgrest" || true + if start-stop-daemon --start --quiet --oknodo --chuid postgrest --startas /usr/local/bin/postgrest-wrapper --exec $POSTGREST -- $POSTGREST_OPTS; then + log_end_msg 0 || true + else + log_end_msg 1 || true + fi +} + +stop() +{ + log_daemon_msg "Stopping PostgreSQL REST API daemon" "postgrest" || true + if start-stop-daemon --stop --quiet --oknodo --exec $POSTGREST; then + log_end_msg 0 || true + else + log_end_msg 1 || true + fi +} + +status() +{ + status_of_proc $POSTGREST postgrest && exit 0 || exit $? +} + +case "$1" in +start) + start + ;; +stop) + stop + ;; +restart) + stop + start + ;; +status) + status + ;; +*) + echo "Usage: $0 {start|stop|restart|status}" +esac