blob: 3b5e633e6efbea63330d8c9ff38ccf9023e8d489 (
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
|
#!/bin/sh
#
# $NetBSD: pgsql.sh,v 1.9 2002/04/05 16:23:23 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@"
if [ -f /etc/rc.subr ]
then
. /etc/rc.subr
fi
rcd_dir=`@DIRNAME@ $0`
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"
command_args="-D ${PGHOME}/data"
start_command_args="-w -s -l ${PGHOME}/errlog"
stop_command_args="-s -m fast"
initdb_cmd="pgsql_initdb"
start_precmd="pgsql_precmd"
start_cmd="pgsql_doit start"
restart_cmd="pgsql_doit restart"
stop_cmd="pgsql_doit stop"
pgsql_precmd()
{
if [ ! -f ${PGHOME}/data/base/1/PG_VERSION ]
then
$rcd_dir/pgsql initdb
fi
}
pgsql_initdb()
{
initdb="@PREFIX@/bin/initdb"
if [ ! -x ${initdb} ]
then
return
fi
if [ -f ${PGHOME}/data/base/1/PG_VERSION ]
then
@ECHO@ "The PostgreSQL template databases have already been initialized."
@ECHO@ "Skipping database initialization."
else
@ECHO@ "Initializing PostgreSQL databases."
@SU@ -m ${pgsql_user} -c "${initdb} ${command_args} ${flags}"
fi
}
pgsql_doit()
{
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
if [ ! -x ${ctl_command} ]
then
return
fi
case ${action} in
start) @ECHO@ "Starting ${name}." ;;
stop) @ECHO@ "Stopping ${name}." ;;
restart) @ECHO@ "Restarting ${name}." ;;
esac
@SU@ -m ${pgsql_user} -c "${ctl_command} ${action} ${command_args}"
}
if [ -f /etc/rc.subr ]
then
load_rc_config $name
run_rc_command "$1"
else
if [ -f /etc/rc.conf ]
then
. /etc/rc.conf
fi
case "$1" in
initdb)
eval ${initdb_cmd}
;;
restart)
eval ${restart_cmd}
;;
stop)
eval ${stop_cmd}
;;
*)
eval ${start_precmd}
eval ${start_cmd}
;;
esac
fi
|