postgresql/rc.postgresql

changeset 300
382048971a24
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/postgresql/rc.postgresql	Mon Nov 22 16:54:26 2010 +0100
     1.3 @@ -0,0 +1,108 @@
     1.4 +#!@l_prefix@/bin/openpkg rc
     1.5 +##
     1.6 +##  rc.postgresql -- Run-Commands
     1.7 +##
     1.8 +
     1.9 +%config
    1.10 +    postgresql_enable="$openpkg_rc_def"
    1.11 +    postgresql_flags=""
    1.12 +    postgresql_datadir="@l_prefix@/var/postgresql/db"
    1.13 +    postgresql_rundir="@l_prefix@/var/postgresql/run"
    1.14 +    postgresql_shut_mode="fast"
    1.15 +    postgresql_socket_inet="127.0.0.1"
    1.16 +    postgresql_socket_unix="@l_prefix@/var/postgresql/run"
    1.17 +    postgresql_log_prolog="true"
    1.18 +    postgresql_log_epilog="true"
    1.19 +    postgresql_log_numfiles="10"
    1.20 +    postgresql_log_minsize="1M"
    1.21 +    postgresql_log_complevel="9"
    1.22 +    postgresql_slony1="no"
    1.23 +
    1.24 +%common
    1.25 +    postgresql_opts="-h $postgresql_socket_inet -k $postgresql_socket_unix"
    1.26 +    postgresql_opts="$postgresql_opts $postgresql_flags"
    1.27 +    postgresql_logfile="$postgresql_rundir/postgresql.log"
    1.28 +    postgresql_pidfile="$postgresql_datadir/postgresql.pid"
    1.29 +    postgresql_slony1_pidfile="$postgresql_rundir/slon.pid"
    1.30 +    postgresql_slony1_start () {
    1.31 +        ( . @l_prefix@/etc/postgresql/slony1.conf
    1.32 +          nohup @l_prefix@/bin/slon \
    1.33 +              -d "$SLON_SYNC_LOGLEVEL" -g "$SLON_SYNC_GROUPSIZE" \
    1.34 +              -s "$SLON_SYNC_INTERVAL" -t "$SLON_SYNC_TIMEOUT" \
    1.35 +              "$SLON_CLUSTER_NAME" \
    1.36 +              user="$SLON_CONNECT_USER" password="$SLON_CONNECT_PASS" \
    1.37 +              dbname="$SLON_CONNECT_DBNAME" host="$SLON_CONNECT_HOST"
    1.38 +              </dev/null >/dev/null 2>&1 &
    1.39 +          echo $! >$postgresql_slony1_pidfile
    1.40 +        ) >/dev/null 2>&1
    1.41 +    }
    1.42 +    postgresql_slony1_stop () {
    1.43 +        if [ -f $postgresql_slony1_pidfile ]; then
    1.44 +            kill -TERM `cat $postgresql_slony1_pidfile`
    1.45 +            rm -f $postgresql_slony1_pidfile
    1.46 +        fi
    1.47 +    }
    1.48 +    postgresql_ctl () {
    1.49 +        if [ -s $postgresql_pidfile ]; then
    1.50 +            kill -0 `head -1 $postgresql_pidfile` >/dev/null 2>&1
    1.51 +            if [ $? -ne 0 ]; then
    1.52 +                rm -f $postgresql_pidfile    >/dev/null 2>&1 || true
    1.53 +                rm -f $postgresql_rundir/.s* >/dev/null 2>&1 || true
    1.54 +            fi
    1.55 +        fi
    1.56 +        cmd="$1"; shift
    1.57 +        @l_prefix@/bin/pg_ctl $cmd \
    1.58 +            -l $postgresql_logfile \
    1.59 +            -D $postgresql_datadir \
    1.60 +            ${1+"$@"}
    1.61 +    }
    1.62 +
    1.63 +%status -u @l_rusr@ -o
    1.64 +    postgresql_usable="unknown"
    1.65 +    postgresql_active="no"
    1.66 +    rcService postgresql enable yes && \
    1.67 +        postgresql_ctl status >/dev/null && \
    1.68 +        postgresql_active="yes"
    1.69 +    echo "postgresql_enable=\"$postgresql_enable\""
    1.70 +    echo "postgresql_usable=\"$postgresql_usable\""
    1.71 +    echo "postgresql_active=\"$postgresql_active\""
    1.72 +
    1.73 +%start -p 400 -u @l_rusr@
    1.74 +    rcService postgresql enable yes || exit 0
    1.75 +    rcService postgresql active yes && exit 0
    1.76 +    postgresql_ctl start -o "$postgresql_opts"
    1.77 +    if rcVarIsYes postgresql_slony1; then
    1.78 +        postgresql_slony1_start
    1.79 +    fi
    1.80 +
    1.81 +%stop -p 600 -u @l_rusr@
    1.82 +    rcService postgresql enable yes || exit 0
    1.83 +    rcService postgresql active no  && exit 0
    1.84 +    postgresql_ctl stop -m "$postgresql_shut_mode"
    1.85 +    if rcVarIsYes postgresql_slony1; then
    1.86 +        postgresql_slony1_stop
    1.87 +    fi
    1.88 +
    1.89 +%restart -p 400 -u @l_rusr@
    1.90 +    rcService postgresql enable yes || exit 0
    1.91 +    rcService postgresql active no  && exit 0
    1.92 +    postgresql_ctl restart -o "$postgresql_opts" -m "$postgresql_shut_mode"
    1.93 +    if rcVarIsYes postgresql_slony1; then
    1.94 +        postgresql_slony1_stop
    1.95 +        postgresql_slony1_start
    1.96 +    fi
    1.97 +
    1.98 +%reload -p 400 -u @l_rusr@
    1.99 +    rcService postgresql enable yes || exit 0
   1.100 +    rcService postgresql active no  && exit 0
   1.101 +    postgresql_ctl reload
   1.102 +
   1.103 +%daily -u @l_rusr@
   1.104 +    rcService postgresql enable yes || exit 0
   1.105 +    shtool rotate -f \
   1.106 +        -n ${postgresql_log_numfiles} -s ${postgresql_log_minsize} -d -c \
   1.107 +        -z ${postgresql_log_complevel} -m 600 -o @l_rusr@ -g @l_rgrp@ \
   1.108 +        -P "$postgresql_log_prolog" \
   1.109 +        -E "$postgresql_log_epilog" \
   1.110 +        $postgresql_logfile
   1.111 +

mercurial