databases/postgresql/postgresql

Fri, 15 Nov 2019 20:05:00 +0100

author
David Demelier <markand@malikania.fr>
date
Fri, 15 Nov 2019 20:05:00 +0100
changeset 1207
c9592a9a949b
parent 1169
194681a6d42d
permissions
-rw-r--r--

python/python2: add DEPRECATED tag

#!/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

mercurial