Annotation of pkgsrc/databases/postgresql14-server/files/pgsql.sh, revision 1.3

1.1       adam        1: #!@RCD_SCRIPTS_SHELL@
                      2: #
1.3     ! adam        3: # $NetBSD: pgsql.sh,v 1.3 2023/12/14 11:46:43 adam Exp $
1.1       adam        4: #
                      5: # PostgreSQL database rc.d control script
                      6: #
                      7: # PROVIDE: pgsql
                      8: # REQUIRE: DAEMON
                      9: # KEYWORD: shutdown
                     10: #
                     11: # You will need to set some variables in /etc/rc.conf to start PostgreSQL:
                     12: #
                     13: # pgsql=YES
                     14: #
                     15: # Optionally, "pgsql_flags" contains options for the PostgreSQL postmaster, e.g.
                     16: #      pgsql_flags="-i"                # allows TCP/IP connections
                     17: #      pgsql_flags="-i -l"             # enables SSL connections
                     18: #      pgsql_home="/path/to/home"      # path to pgsql database directory
                     19: # See postmaster(1) for possible options.
                     20: 
1.3     ! adam       21: if [ -f @SYSCONFBASE@/rc.subr ]; then
        !            22:   . @SYSCONFBASE@/rc.subr
1.1       adam       23: fi
                     24: 
                     25: name="pgsql"
                     26: rcvar=${name}
                     27: command="@PREFIX@/bin/pg_ctl"
                     28: procname="@PREFIX@/bin/postgres"
                     29: : ${pgsql_user:=@PGUSER@}
                     30: : ${pgsql_group:=@PGGROUP@}
                     31: : ${pgsql_home:=@PGHOME@}
                     32: 
1.2       martin     33: pgsql_nfiles=4096
1.1       adam       34: extra_commands="initdb reload"
                     35: initdb_cmd="pgsql_initdb"
                     36: start_precmd="pgsql_precmd"
                     37: start_cmd="pgsql_start"
                     38: restart_precmd="pgsql_precmd"
                     39: restart_cmd="pgsql_restart"
                     40: stop_cmd="pgsql_stop"
                     41: reload_cmd="pgsql_reload"
                     42: 
1.3     ! adam       43: if [ -f @SYSCONFBASE@/rc.subr ] && \
        !            44:    [ -d @SYSCONFBASE@/rc.d ] && \
        !            45:    [ -f @SYSCONFBASE@/rc.d/DAEMON ]; then
1.1       adam       46:        load_rc_config $name
1.3     ! adam       47: elif [ -f @SYSCONFBASE@/rc.conf ]; then
        !            48:        . @SYSCONFBASE@/rc.conf
1.1       adam       49: fi
                     50: 
                     51: cd /
                     52: 
                     53: command_args="-w -s -D ${pgsql_home}/data -m fast -l ${pgsql_home}/errlog"
1.2       martin     54: command_args_daemon="${command_args}"
1.1       adam       55: if [ -n "${pgsql_flags}" ]; then
1.2       martin     56:        command_args_daemon="${command_args} -o \"${pgsql_flags}\""
1.1       adam       57: fi
                     58: 
                     59: pgsql_precmd()
                     60: {
1.2       martin     61:        ulimit -n ${pgsql_nfiles}
1.1       adam       62:        if [ ! -d ${pgsql_home}/data/base ]; then
                     63:                pgsql_initdb
                     64:        fi
                     65: }
                     66: 
                     67: pgsql_initdb()
                     68: {
                     69:        if [ -d ${pgsql_home}/data/base ]; then
                     70:                @ECHO@ "The PostgreSQL template databases have already been initialized."
                     71:                @ECHO@ "Skipping database initialization."
                     72:        else
                     73:                @ECHO@ "Initializing PostgreSQL databases."
                     74:                @MKDIR@ -p ${pgsql_home}
                     75:                @CHOWN@ ${pgsql_user} ${pgsql_home}
                     76:                @CHGRP@ ${pgsql_group} ${pgsql_home}
                     77:                @CHMOD@ 0700 ${pgsql_home}
1.2       martin     78:                @SU@ -m ${pgsql_user} -c "${command} init ${command_args}"
1.1       adam       79:        fi
                     80: }
                     81: 
                     82: pgsql_start()
                     83: {
                     84:        @ECHO@ "Starting ${name}."
1.2       martin     85:        @SU@ -m ${pgsql_user} -c "${command} start ${command_args_daemon}"
1.1       adam       86: }
                     87: 
                     88: pgsql_restart()
                     89: {
                     90:        @ECHO@ "Restarting ${name}."
1.2       martin     91:        @SU@ -m ${pgsql_user} -c "${command} restart ${command_args_daemon}"
1.1       adam       92: }
                     93: 
                     94: pgsql_stop()
                     95: {
                     96:        @ECHO@ "Stopping ${name}."
1.2       martin     97:        @SU@ -m ${pgsql_user} -c "${command} stop ${command_args}"
1.1       adam       98: }
                     99: 
                    100: pgsql_reload()
                    101: {
                    102:        @ECHO@ "Reloading ${name}."
1.2       martin    103:        @SU@ -m ${pgsql_user} -c "${command} reload ${command_args_daemon}"
1.1       adam      104: }
                    105: 
1.3     ! adam      106: if [ -f @SYSCONFBASE@/rc.subr ] && \
        !           107:    [ -d @SYSCONFBASE@/rc.d ] && \
        !           108:    [ -f @SYSCONFBASE@/rc.d/DAEMON ]; then
1.1       adam      109:        run_rc_command "$1"
                    110: else
                    111:        pidfile="${pgsql_home}/data/postmaster.pid"
                    112:        case "$1" in
                    113:        initdb)
                    114:                eval ${initdb_cmd}
                    115:                ;;
                    116:        restart)
                    117:                eval ${restart_precmd}
                    118:                eval ${restart_cmd}
                    119:                ;;
                    120:        stop)
                    121:                if [ -r "${pidfile}" ]; then
                    122:                        eval ${stop_cmd}
                    123:                fi
                    124:                ;;
                    125:        reload)
                    126:                eval ${reload_cmd}
                    127:                ;;
                    128:        *)
                    129:                eval ${start_precmd}
                    130:                eval ${start_cmd}
                    131:                ;;
                    132:        esac
                    133: fi

CVSweb <webmaster@jp.NetBSD.org>