summaryrefslogtreecommitdiff
path: root/databases
diff options
context:
space:
mode:
authorjlam <jlam@pkgsrc.org>2002-04-04 05:21:50 +0000
committerjlam <jlam@pkgsrc.org>2002-04-04 05:21:50 +0000
commit159f541497a7f24091b899968fb02f2e5c765a50 (patch)
tree6f41b2305a48bafc2e19ff302c23580ded59f778 /databases
parente5b54ba7a875fd08eb9860f74153460d46cbacb8 (diff)
downloadpkgsrc-159f541497a7f24091b899968fb02f2e5c765a50.tar.gz
Fix bug in in "/etc/rc.d/pgsql stop": we need to use "fast" mode rather
than "smart" mode so that the the database will always cleanly shutdown. Previously, postgres would wait for clients to disconnect before stopping the database process, which sometimes resulted in unclean shutdowns. Problem noted by Curt Sampson <cjs@cynic.net> in private email. I also convert this to use /etc/rc.subr if it is present.
Diffstat (limited to 'databases')
-rw-r--r--databases/postgresql-server/files/pgsql.sh150
1 files changed, 74 insertions, 76 deletions
diff --git a/databases/postgresql-server/files/pgsql.sh b/databases/postgresql-server/files/pgsql.sh
index be054a1eb0c..58891e2f269 100644
--- a/databases/postgresql-server/files/pgsql.sh
+++ b/databases/postgresql-server/files/pgsql.sh
@@ -1,63 +1,54 @@
#!/bin/sh
#
-# $NetBSD: pgsql.sh,v 1.6 2001/11/26 20:38:31 jlam Exp $
+# $NetBSD: pgsql.sh,v 1.7 2002/04/04 05:21:50 jlam Exp $
#
# PostgreSQL database rc.d control script
#
# PROVIDE: pgsql
# REQUIRE: DAEMON
# KEYWORD: shutdown
+#
+# You will need to set some variables in /etc/rc.conf to start PostgreSQL:
+#
+# pgsql=YES
+# pgsql_flags="-i" # allows TCP/IP connections
+# pgsql_flags="-i -l" # enables SSL connections (TCP/IP required)
+#
+# "pgsql_flags" contains options for the PostgreSQL postmaster. See
+# postmaster(1) for possible options.
PGHOME="@PGHOME@"
-name="pgsql"
-rcvar=$name
-pgsql_user="@PGUSER@"
-command="@PREFIX@/bin/pg_ctl"
-command_args="-s -D ${PGHOME}/data -l ${PGHOME}/errlog"
-
-# pgsql_flags contains options for the PostgreSQL postmaster.
-# See postmaster(1) for possible options.
-#
-#pgsql_flags="-i" # allows TCP/IP connections
-#pgsql_flags="-i -l" # enables SSL connections (TCP/IP required)
-
-# set defaults
-if [ -r /etc/rc.conf ]
+if [ -f /etc/rc.subr ]
then
- . /etc/rc.conf
-else
- eval ${rcvar}=YES
+ . /etc/rc.subr
fi
-# $flags from environment overrides $pgsql_flags
-if [ -n "${flags}" ]
-then
- eval ${rcvar}_flags="${flags}"
-fi
+rcd_dir=`@DIRNAME@ $0`
-pgsql_doit()
-{
- action=$1
- if [ -n "${pgsql_flags}" ]
- then
- command_args="${command_args} -o \"${pgsql_flags}\""
- fi
+name="pgsql"
+rcvar=$name
+pgsql_user="@PGUSER@"
+command="@PREFIX@/bin/postmaster"
+ctl_command="@PREFIX@/bin/pg_ctl"
+pidfile="${PGHOME}/data/postmaster.pid"
+extra_commands="initdb"
- case ${action} in
- start) pgsql_start_precmd; echo "Starting ${name}." ;;
- stop) echo "Stopping ${name}." ;;
- restart) echo "Restarting ${name}." ;;
- esac
+command_args="-D ${PGHOME}/data"
+start_command_args="-w -s -l ${PGHOME}/errlog"
+stop_command_args="-s -m fast"
- @SU@ -m ${pgsql_user} -c "${command} ${command_args} ${action}"
-}
+initdb_cmd="pgsql_initdb"
+start_precmd="pgsql_precmd"
+start_cmd="pgsql_doit start"
+restart_cmd="pgsql_doit restart"
+stop_cmd="pgsql_doit stop"
-pgsql_start_precmd()
+pgsql_precmd()
{
if [ ! -f ${PGHOME}/data/base/1/PG_VERSION ]
then
- $0 forceinitdb
+ $rcd_dir/pgsql initdb
fi
}
@@ -65,51 +56,58 @@ pgsql_initdb()
{
if [ -f ${PGHOME}/data/base/1/PG_VERSION ]
then
- echo "The PostgreSQL template databases have already been initialized."
- echo "Skipping database initialization."
+ @ECHO@ "The PostgreSQL template databases have already been initialized."
+ @ECHO@ "Skipping database initialization."
else
- echo "Initializing PostgreSQL databases."
- @SU@ -m ${pgsql_user} -c "@PREFIX@/bin/initdb -D ${PGHOME}/data $flags"
+ @ECHO@ "Initializing PostgreSQL databases."
+ @SU@ -m ${pgsql_user} -c "@PREFIX@/bin/initdb ${command_args} ${flags}"
fi
}
-checkyesno()
+pgsql_doit()
{
- eval _value=\$${1}
- case $_value in
- [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1) return 0 ;;
- [Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0) return 1 ;;
- *)
- echo "\$${1} is not set properly."
- return 1
+ action=$1
+
+ case ${action} in
+ start|restart)
+ command_args="${command_args} ${start_command_args}"
+ if [ -n "${pgsql_flags}" ]
+ then
+ command_args="${command_args} -o \"${pgsql_flags}\""
+ fi
+ ;;
+ stop)
+ command_args="${command_args} ${stop_command_args}"
;;
esac
-}
-# force commands are always executed
-cmd=${1:-start}
-case ${cmd} in
-force*)
- cmd=${cmd#force}
- eval ${rcvar}=YES
- ;;
-esac
+ case ${action} in
+ start) @ECHO@ "Starting ${name}." ;;
+ stop) @ECHO@ "Stopping ${name}." ;;
+ restart) @ECHO@ "Restarting ${name}." ;;
+ esac
-if checkyesno ${rcvar}
+ @SU@ -m ${pgsql_user} -c "${ctl_command} ${action} ${command_args}"
+}
+
+if [ -f /etc/rc.subr ]
then
- if [ -x ${command} ]
- then
- case ${cmd} in
- initdb)
- ${rcvar}_${cmd}
- ;;
- restart|start|stop|status)
- ${rcvar}_doit ${cmd}
- ;;
- *)
- echo 1>&2 "Usage: $0 [initdb|restart|start|stop|status]"
- exit 1
- ;;
- esac
- fi
+ load_rc_config $name
+ run_rc_command "$1"
+else
+ case "$1" in
+ initdb)
+ eval ${initdb_cmd}
+ ;;
+ restart)
+ eval ${restart_cmd}
+ ;;
+ stop)
+ eval ${stop_cmd}
+ ;;
+ *)
+ eval ${start_precmd}
+ eval ${start_cmd}
+ ;;
+ esac
fi