blob: 086721568c51e4c4cc8b8f27736b57dc5d797a87 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
#!@RCD_SCRIPTS_SHELL@
#
# $NetBSD: pgsql.sh,v 1.3 2011/01/10 14:50:56 adam 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
#
# 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
# See postmaster(1) for possible options.
if [ -f /etc/rc.subr ]; then
. /etc/rc.subr
fi
name="pgsql"
rcvar=${name}
command="@PREFIX@/bin/pg_ctl"
procname="@PREFIX@/bin/postgres"
pgsql_user="@PGUSER@"
pgsql_group="@PGGROUP@"
pgsql_home="@PGHOME@"
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
elif [ -f /etc/rc.conf ]; then
. /etc/rc.conf
fi
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
}
pgsql_initdb()
{
initdb="@PG_PREFIX@/bin/initdb"
if [ -d ${pgsql_home}/data/base ]; then
@ECHO@ "The PostgreSQL template databases have already been initialized."
@ECHO@ "Skipping database initialization."
else
@ECHO@ "Initializing PostgreSQL databases."
@MKDIR@ -p ${pgsql_home}
@CHOWN@ ${pgsql_user} ${pgsql_home}
@CHGRP@ ${pgsql_group} ${pgsql_home}
@CHMOD@ 0700 ${pgsql_home}
doit="@SU@ -m ${pgsql_user} -c '${initdb} -D ${pgsql_home}/data'"
eval $doit
fi
}
pgsql_start()
{
@ECHO@ "Starting ${name}."
doit="@SU@ -m ${pgsql_user} -c '${command} start ${command_args}'"
eval $doit
}
pgsql_restart()
{
@ECHO@ "Restarting ${name}."
doit="@SU@ -m ${pgsql_user} -c '${command} restart ${command_args}'"
eval $doit
}
pgsql_stop()
{
@ECHO@ "Stopping ${name}."
doit="@SU@ -m ${pgsql_user} -c '${command} stop ${command_args}'"
eval $doit
}
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
run_rc_command "$1"
else
pidfile="${pgsql_home}/data/postmaster.pid"
case "$1" in
initdb)
eval ${initdb_cmd}
;;
restart)
eval ${restart_precmd}
eval ${restart_cmd}
;;
stop)
if [ -r "${pidfile}" ]; then
eval ${stop_cmd}
fi
;;
reload)
eval ${reload_cmd}
;;
*)
eval ${start_precmd}
eval ${start_cmd}
;;
esac
fi
|