Import databases/postgresql95-server version 9.5.0_1
[dports.git] / databases / postgresql95-server / files / postgresql.in
1 #!/bin/sh
2
3 # $FreeBSD: head/databases/postgresql95-server/files/postgresql.in 340872 2014-01-24 00:14:07Z mat $
4 #
5 # PROVIDE: postgresql
6 # REQUIRE: LOGIN
7 # KEYWORD: shutdown
8 #
9 # Add the following line to /etc/rc.conf to enable PostgreSQL:
10 #
11 #  postgresql_enable="YES"
12 #  # optional
13 #  postgresql_data="%%PREFIX%%/%%PG_USER%%/data"
14 #  postgresql_flags="-w -s -m fast"
15 #  postgresql_initdb_flags="--encoding=utf-8 --lc-collate=C"
16 #  postgresql_class="default"
17 #  postgresql_profiles=""
18 #
19 # See %%PREFIX%%/share/doc/postgresql/README-server for more info
20 #
21 # This scripts takes one of the following commands:
22 #
23 #   start stop restart reload status initdb
24 #
25 # For postmaster startup options, edit ${postgresql_data}/postgresql.conf
26
27 command=%%PREFIX%%/bin/pg_ctl
28
29 . /etc/rc.subr
30
31 load_rc_config postgresql
32
33 # set defaults
34 postgresql_enable=${postgresql_enable:-"NO"}
35 postgresql_flags=${postgresql_flags:-"-w -s -m fast"}
36 postgresql_user=${postgresql_user:-"%%PG_USER%%"}
37 eval postgresql_data=${postgresql_data:-"~${postgresql_user}/data"}
38 postgresql_class=${postgresql_class:-"default"}
39 postgresql_initdb_flags=${postgresql_initdb_flags:-"--encoding=utf-8 --lc-collate=C"}
40
41 name=postgresql
42 rcvar=postgresql_enable
43 extra_commands="reload initdb"
44
45 start_cmd="postgresql_command start"
46 stop_cmd="postgresql_command stop"
47 restart_cmd="postgresql_command restart"
48 reload_cmd="postgresql_command reload"
49 status_cmd="postgresql_command status"
50
51 initdb_cmd="postgresql_initdb"
52
53 if [ -n "$2" ]; then
54         profile="$2"
55         if [ "x${postgresql_profiles}" != "x" ]; then
56                 eval postgresql_data="\${postgresql_${profile}_data:-}"
57                 if [ "x${postgresql_data}" = "x" ]; then
58                         echo "You must define a data directory (postgresql_${profile}_data)"
59                         exit 1
60                 fi
61                 eval postgresql_enable="\${postgresql_${profile}_enable:-${postgresql_enable}}
62                 eval postgresql_data="\${postgresql_${profile}_data:-${postgresql_data}}
63                 eval postgresql_flags="\${postgresql_${profile}_flags:-${postgresql_flags}}"
64                 eval postgresql_initdb_flags="\${postgresql_${profile}_initdb_flags:-${postgresql_initdb_flags}}"
65         fi
66 else
67         if [ "x${postgresql_profiles}" != "x" -a "x$1" != "x" ]; then
68                 for profile in ${postgresql_profiles}; do
69                         eval _enable="\${postgresql_${profile}_enable}"
70                         case "x${_enable:-${postgresql_enable}}" in
71                         x|x[Nn][Oo]|x[Nn][Oo][Nn][Ee])
72                                 continue
73                                 ;;
74                         x[Yy][Ee][Ss])
75                                 ;;
76                         *)
77                                 if test -z "$_enable"; then
78                                         _var=postgresql_enable
79                                 else
80                                         _var=postgresql_"${profile}"_enable
81                                 fi
82                                 echo "Bad value" \
83                                         "'${_enable:-${postgresql_enable}}'" \
84                                         "for ${_var}. " \
85                                         "Profile ${profile} skipped."
86                                 continue
87                                 ;;
88                         esac
89                         echo "===> postgresql profile: ${profile}"
90                         %%PREFIX%%/etc/rc.d/postgresql $1 ${profile}
91                         retcode="$?"
92                         if [ "0${retcode}" -ne 0 ]; then
93                                 failed="${profile} (${retcode}) ${failed:-}"
94                         else
95                                 success="${profile} ${success:-}"
96                         fi
97                 done
98                 exit 0
99         fi
100 fi
101
102 command_args="-D ${postgresql_data} ${postgresql_flags}"
103
104 postgresql_command()
105 {
106     su -l ${postgresql_user} -c "exec ${command} ${command_args} ${rc_arg}"
107 }
108
109 postgresql_initdb()
110 {
111     su -l -c ${postgresql_class} ${postgresql_user} -c "exec %%PREFIX%%/bin/initdb ${postgresql_initdb_flags} -D ${postgresql_data}"
112 }
113
114 run_rc_command "$1"