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