diff databases/postgresql/postgresql @ 1169:194681a6d42d

databases/postgresql: initial import, closes #2411
author David Demelier <markand@malikania.fr>
date Thu, 10 Oct 2019 13:47:08 +0200
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/databases/postgresql/postgresql	Thu Oct 10 13:47:08 2019 +0200
@@ -0,0 +1,97 @@
+#!/bin/busybox sh
+#
+# /etc/rc.d/postgresql -- run control script for postgresql
+#
+# Copyright (c) 2019 David Demelier <markand@malikania.fr>
+#
+# Permission to use, copy, modify, and/or distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+#
+
+if [ -f /etc/rc.conf ]; then
+	. /etc/rc.conf
+fi
+
+: ${POSTGRESQL_PID:=/var/run/postgresql/postgresql.pid}
+: ${POSTGRESQL_USER:=postgresql}
+: ${POSTGRESQL_GROUP:=postgresql}
+: ${POSTGRESQL_DIR:=/var/db/postgresql}
+: ${POSTGRESQL_CMD:=/bin/postgres}
+: ${POSTGRESQL_ARGS:=-D ${POSTGRESQL_DIR}}
+
+postgresql_start()
+{
+	mkdir -p $(dirname $POSTGRESQL_PID)
+
+	if [ -s $POSTGRESQL_PID ]; then
+		echo "postgresql is already running with pid: $(cat $POSTGRESQL_PID)"
+	else
+		echo "Starting postgresql: $POSTGRESQL_CMD $POSTGRESQL_ARGS"
+		start-stop-daemon \
+			-Sbmvp $POSTGRESQL_PID \
+			-c $POSTGRESQL_USER:$POSTGRESQL_GROUP \
+			-x $POSTGRESQL_CMD -- $POSTGRESQL_ARGS
+	fi
+}
+
+postgresql_init()
+{
+	mkdir -p $POSTGRESQL_DIR
+	chown $POSTGRESQL_USER:$POSTGRESQL_GROUP $POSTGRESQL_DIR
+	busybox su $POSTGRESQL_USER -lp -c "pg_ctl -D $POSTGRESQL_DIR initdb"
+}
+
+postgresql_status()
+{
+	if [ -s $POSTGRESQL_PID ]; then
+		echo "postgresql is running with pid: $(cat $POSTGRESQL_PID)"
+	else
+		echo "postgresql is not running"
+	fi
+}
+
+postgresql_stop()
+{
+	if [ -s $POSTGRESQL_PID ]; then
+		echo "Stopping postgresql."
+		start-stop-daemon -Kqp $POSTGRESQL_PID
+		rm -f $POSTGRESQL_PID
+	fi
+}
+
+postgresql_restart()
+{
+	postgresql_stop
+	sleep 3
+	postgresql_start
+}
+
+case $1 in
+init)
+	postgresql_init
+	;;
+start)
+	postgresql_start
+	;;
+status)
+	postgresql_status
+	;;
+stop)
+	postgresql_stop
+	;;
+restart)
+	postgresql_restart
+	;;
+*)
+	echo "usage: $(basename $0) init|restart|start|status|stop"
+	;;
+esac