summaryrefslogtreecommitdiff
path: root/databases/postgresql83-server/files/pgsql.sh
diff options
context:
space:
mode:
Diffstat (limited to 'databases/postgresql83-server/files/pgsql.sh')
-rw-r--r--databases/postgresql83-server/files/pgsql.sh120
1 files changed, 51 insertions, 69 deletions
diff --git a/databases/postgresql83-server/files/pgsql.sh b/databases/postgresql83-server/files/pgsql.sh
index e49dfd2e035..dfe2b4e1a0b 100644
--- a/databases/postgresql83-server/files/pgsql.sh
+++ b/databases/postgresql83-server/files/pgsql.sh
@@ -1,6 +1,6 @@
#!@RCD_SCRIPTS_SHELL@
#
-# $NetBSD: pgsql.sh,v 1.2 2008/11/11 13:50:50 joerg Exp $
+# $NetBSD: pgsql.sh,v 1.3 2010/12/19 09:53:54 adam Exp $
#
# PostgreSQL database rc.d control script
#
@@ -12,28 +12,32 @@
#
# pgsql=YES
#
-# The following variables are optional:
-#
+# Optionally, "pgsql_flags" contains options for the PostgreSQL postmaster, e.g.
# pgsql_flags="-i" # allows TCP/IP connections
# pgsql_flags="-i -l" # enables SSL connections
# pgsql_home="/path/to/home" # path to pgsql database directory
-#
-# "pgsql_flags" contains options for the PostgreSQL postmaster. See
-# postmaster(1) for possible options.
+# See postmaster(1) for possible options.
if [ -f /etc/rc.subr ]; then
. /etc/rc.subr
fi
name="pgsql"
-rcvar=$name
+rcvar=${name}
+command="@PREFIX@/bin/pg_ctl"
+procname="@PREFIX@/bin/postgres"
pgsql_user="@PGUSER@"
pgsql_group="@PGGROUP@"
-eval pgsql_home="~$pgsql_user"
+pgsql_home="@PGHOME@"
-command="@PG_PREFIX@/bin/postmaster"
-ctl_command="@PG_PREFIX@/bin/pg_ctl"
-extra_commands="initdb"
+extra_commands="initdb reload"
+initdb_cmd="pgsql_initdb"
+start_precmd="pgsql_precmd"
+start_cmd="pgsql_start"
+restart_precmd="pgsql_precmd"
+restart_cmd="pgsql_restart"
+stop_cmd="pgsql_stop"
+reload_cmd="pgsql_reload"
if [ -f /etc/rc.subr -a -d /etc/rc.d -a -f /etc/rc.d/DAEMON ]; then
load_rc_config $name
@@ -41,21 +45,14 @@ elif [ -f /etc/rc.conf ]; then
. /etc/rc.conf
fi
-pidfile="${pgsql_home}/data/postmaster.pid"
-common_args="-D ${pgsql_home}/data -m fast"
-start_command_args="-w -s -l ${pgsql_home}/errlog"
-stop_command_args="-s"
-
-initdb_cmd="pgsql_initdb"
-start_precmd="pgsql_precmd"
-start_cmd="pgsql_doit start"
-restart_cmd="pgsql_doit restart"
-stop_cmd="pgsql_doit stop"
-
-ulimit -n 4096
+command_args="-w -s -D ${pgsql_home}/data -m fast -l ${pgsql_home}/errlog"
+if [ -n "${pgsql_flags}" ]; then
+ command_args="${command_args} -o \\\"${pgsql_flags}\\\""
+fi
pgsql_precmd()
{
+ ulimit -n 4096
if [ ! -d ${pgsql_home}/data/base ]; then
pgsql_initdb
fi
@@ -63,13 +60,6 @@ pgsql_precmd()
pgsql_initdb()
{
- initdb="@PG_PREFIX@/bin/initdb"
-
- cd /
-
- if [ ! -x ${initdb} ]; then
- return 1
- fi
if [ -d ${pgsql_home}/data/base ]; then
@ECHO@ "The PostgreSQL template databases have already been initialized."
@ECHO@ "Skipping database initialization."
@@ -78,67 +68,59 @@ pgsql_initdb()
@MKDIR@ -p ${pgsql_home}
@CHOWN@ ${pgsql_user} ${pgsql_home}
@CHGRP@ ${pgsql_group} ${pgsql_home}
- @CHMOD@ 0750 ${pgsql_home}
- common_args_without_m=$(echo "${common_args}" |\
- sed -e 's/-m [a-z]*//')
- eval doit_command=\"${initdb} ${common_args_without_m} ${flags}\"
- doit="@SU@ -m ${pgsql_user} -c '${doit_command}'"
+ @CHMOD@ 0700 ${pgsql_home}
+ doit="@SU@ -m ${pgsql_user} -c '${command} init ${command_args}'"
eval $doit
fi
}
-pgsql_doit()
+pgsql_start()
{
- action=$1
-
- cd /
-
- case ${action} in
- start|restart)
- if [ -n "${pgsql_flags}" ]; then
- start_command_args="${start_command_args} -o \\\"${pgsql_flags}\\\""
- fi
- command_args="${common_args} ${start_command_args} ${command_args}"
- ;;
- stop)
- command_args="${common_args} ${stop_command_args} ${command_args}"
- ;;
- *)
- command_args="${common_args} ${command_args}"
- ;;
- esac
+ @ECHO@ "Starting ${name}."
+ doit="@SU@ -m ${pgsql_user} -c '${command} start ${command_args}'"
+ eval $doit
+}
- if [ ! -x ${ctl_command} ]; then
- return
- fi
+pgsql_restart()
+{
+ @ECHO@ "Restarting ${name}."
+ doit="@SU@ -m ${pgsql_user} -c '${command} restart ${command_args}'"
+ eval $doit
+}
- case ${action} in
- start) @ECHO@ "Starting ${name}." ;;
- stop) @ECHO@ "Stopping ${name}." ;;
- restart) @ECHO@ "Restarting ${name}." ;;
- esac
+pgsql_stop()
+{
+ @ECHO@ "Stopping ${name}."
+ doit="@SU@ -m ${pgsql_user} -c '${command} stop ${command_args}'"
+ eval $doit
+}
- eval doit_command=\"${ctl_command} ${action} ${command_args}\"
- doit="@SU@ -m ${pgsql_user} -c '${doit_command}'"
+pgsql_reload()
+{
+ @ECHO@ "Reloading ${name}."
+ doit="@SU@ -m ${pgsql_user} -c '${command} reload ${command_args}'"
eval $doit
}
if [ -f /etc/rc.subr -a -d /etc/rc.d -a -f /etc/rc.d/DAEMON ]; then
- load_rc_config $name
run_rc_command "$1"
else
- if [ -f /etc/rc.conf ]; then
- . /etc/rc.conf
- fi
+ pidfile="${pgsql_home}/data/postmaster.pid"
case "$1" in
initdb)
eval ${initdb_cmd}
;;
restart)
+ eval ${restart_precmd}
eval ${restart_cmd}
;;
stop)
- eval ${stop_cmd}
+ if [ -r "${pidfile}" ]; then
+ eval ${stop_cmd}
+ fi
+ ;;
+ reload)
+ eval ${reload_cmd}
;;
*)
eval ${start_precmd}