Annotation of pkgsrc/databases/postgresql17-server/files/pgsql.sh, revision 1.1

1.1     ! adam        1: #!@RCD_SCRIPTS_SHELL@
        !             2: #
        !             3: # $NetBSD: pgsql.sh,v 1.4 2024/09/16 12:09:59 adam Exp $
        !             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: 
        !            21: if [ -f @SYSCONFBASE@/rc.subr ]; then
        !            22:   . @SYSCONFBASE@/rc.subr
        !            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: 
        !            33: pgsql_nfiles=4096
        !            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: 
        !            43: if [ -f @SYSCONFBASE@/rc.subr -a -d @SYSCONFBASE@/rc.d -a -f @SYSCONFBASE@/rc.d/DAEMON ]; then
        !            44:        load_rc_config $name
        !            45: elif [ -f @SYSCONFBASE@/rc.conf ]; then
        !            46:        . @SYSCONFBASE@/rc.conf
        !            47: fi
        !            48: 
        !            49: cd /
        !            50: 
        !            51: command_args="-w -s -D ${pgsql_home}/data -m fast -l ${pgsql_home}/errlog"
        !            52: command_args_daemon="${command_args}"
        !            53: if [ -n "${pgsql_flags}" ]; then
        !            54:        command_args_daemon="${command_args} -o \"${pgsql_flags}\""
        !            55: fi
        !            56: 
        !            57: pgsql_precmd()
        !            58: {
        !            59:        ulimit -n ${pgsql_nfiles}
        !            60:        if [ ! -d ${pgsql_home}/data/base ]; then
        !            61:                pgsql_initdb
        !            62:        fi
        !            63: }
        !            64: 
        !            65: pgsql_initdb()
        !            66: {
        !            67:        if [ -d ${pgsql_home}/data/base ]; then
        !            68:                @ECHO@ "The PostgreSQL template databases have already been initialized."
        !            69:                @ECHO@ "Skipping database initialization."
        !            70:        else
        !            71:                @ECHO@ "Initializing PostgreSQL databases."
        !            72:                @MKDIR@ -p ${pgsql_home}
        !            73:                @CHOWN@ ${pgsql_user} ${pgsql_home}
        !            74:                @CHGRP@ ${pgsql_group} ${pgsql_home}
        !            75:                @CHMOD@ 0700 ${pgsql_home}
        !            76:                @SU@ -m ${pgsql_user} -c "${command} init ${command_args}"
        !            77:        fi
        !            78: }
        !            79: 
        !            80: pgsql_start()
        !            81: {
        !            82:        @ECHO@ "Starting ${name}."
        !            83:        @SU@ -m ${pgsql_user} -c "${command} start ${command_args_daemon}"
        !            84: }
        !            85: 
        !            86: pgsql_restart()
        !            87: {
        !            88:        @ECHO@ "Restarting ${name}."
        !            89:        @SU@ -m ${pgsql_user} -c "${command} restart ${command_args_daemon}"
        !            90: }
        !            91: 
        !            92: pgsql_stop()
        !            93: {
        !            94:        @ECHO@ "Stopping ${name}."
        !            95:        @SU@ -m ${pgsql_user} -c "${command} stop ${command_args}"
        !            96: }
        !            97: 
        !            98: pgsql_reload()
        !            99: {
        !           100:        @ECHO@ "Reloading ${name}."
        !           101:        @SU@ -m ${pgsql_user} -c "${command} reload ${command_args_daemon}"
        !           102: }
        !           103: 
        !           104: if [ -f @SYSCONFBASE@/rc.subr -a -d @SYSCONFBASE@/rc.d -a -f @SYSCONFBASE@/rc.d/DAEMON ]; then
        !           105:        run_rc_command "$1"
        !           106: else
        !           107:        pidfile="${pgsql_home}/data/postmaster.pid"
        !           108:        case "$1" in
        !           109:        initdb)
        !           110:                eval ${initdb_cmd}
        !           111:                ;;
        !           112:        restart)
        !           113:                eval ${restart_precmd}
        !           114:                eval ${restart_cmd}
        !           115:                ;;
        !           116:        stop)
        !           117:                if [ -r "${pidfile}" ]; then
        !           118:                        eval ${stop_cmd}
        !           119:                fi
        !           120:                ;;
        !           121:        reload)
        !           122:                eval ${reload_cmd}
        !           123:                ;;
        !           124:        *)
        !           125:                eval ${start_precmd}
        !           126:                eval ${start_cmd}
        !           127:                ;;
        !           128:        esac
        !           129: fi

CVSweb <webmaster@jp.NetBSD.org>