Просмотр исходного кода

provide start/stop support for slony1

Ralf S. Engelschall 21 лет назад
Родитель
Сommit
daed7df5bf
2 измененных файлов с 47 добавлено и 2 удалено
  1. 11 0
      postgresql/postgresql.spec
  2. 36 2
      postgresql/rc.postgresql

+ 11 - 0
postgresql/postgresql.spec

@@ -418,6 +418,17 @@ AutoReqProv:  no
       rm -f $RPM_BUILD_ROOT%{l_prefix}/share/postgresql/xxid.v73.sql
       mv $RPM_BUILD_ROOT%{l_prefix}/share/postgresql/xxid.v74.sql \
          $RPM_BUILD_ROOT%{l_prefix}/share/postgresql/xxid.sql
+      ( echo "#   Slony-1 configuration for replication engine slon(1)"
+        echo "SLON_CLUSTER_NAME=\"example\""
+        echo "SLON_CONNECT_DBNAME=\"example\""
+        echo "SLON_CONNECT_USER=\"postgresql\""
+        echo "SLON_CONNECT_PASS=\"postgresql\""
+        echo "SLON_CONNECT_HOST=\"localhost\""
+        echo "SLON_SYNC_INTERVAL=\"10000\""
+        echo "SLON_SYNC_TIMEOUT=\"60000\""
+        echo "SLON_SYNC_GROUPSIZE=\"6\""
+        echo "SLON_SYNC_LOGLEVEL=\"1\""
+      ) >$RPM_BUILD_ROOT%{l_prefix}/etc/postgresql/slony1.conf
     ) || exit $?
 %endif
 

+ 36 - 2
postgresql/rc.postgresql

@@ -15,12 +15,32 @@
     postgresql_log_numfiles="10"
     postgresql_log_minsize="1M"
     postgresql_log_complevel="9"
+    postgresql_slony1="no"
     postgresql_pgpool="no"
 
 %common
     postgresql_opts="-i -h $postgresql_socket_inet -k $postgresql_socket_unix"
     postgresql_opts="$postgresql_opts $postgresql_flags"
     postgresql_log_file="@l_prefix@/var/postgresql/run/postgresql.log"
+    postgresql_slony1_pidfile="@l_prefix@/var/postgresql/run/slon.pid"
+    postgresql_slony1_start () {
+        ( . @l_prefix@/etc/postgresql/slony1.conf
+          nohup @l_prefix@/bin/slon \
+              -d "$SLON_SYNC_LOGLEVEL" -g "$SLON_SYNC_GROUPSIZE" \
+              -s "$SLON_SYNC_INTERVAL" -t "$SLON_SYNC_TIMEOUT" \
+              "$SLON_CLUSTER_NAME" \
+              user="$SLON_CONNECT_USER" password="$SLON_CONNECT_PASS" \
+              dbname="$SLON_CONNECT_DBNAME" host="$SLON_CONNECT_HOST"
+              </dev/null >/dev/null 2>&1 &
+          echo $! >$postgresql_slony1_pidfile
+        ) >/dev/null 2>&1
+    }
+    postgresql_slony1_stop () {
+        if [ -f $postgresql_slony1_pidfile ]; then
+            kill -TERM `cat $postgresql_slony1_pidfile`
+            rm -f $postgresql_slony1_pidfile
+        fi
+    }
 
 %status -u @l_rusr@ -o
     postgresql_usable="unknown"
@@ -35,18 +55,32 @@
     rcService postgresql enable yes || exit 0
     rcService postgresql active yes && exit 0
     @l_prefix@/bin/pg_ctl start -l $postgresql_log_file -D $postgresql_datadir -o "$postgresql_opts"
-    rcVarIsYes postgresql_pgpool && @l_prefix@/bin/pgpool
+    if rcVarIsYes postgresql_slony1; then
+        postgresql_slony1_start
+    fi
+    if rcVarIsYes postgresql_pgpool; then
+        @l_prefix@/bin/pgpool
+    fi
 
 %stop -p 400 -u @l_rusr@
     rcService postgresql enable yes || exit 0
     rcService postgresql active no  && exit 0
     @l_prefix@/bin/pg_ctl stop -l $postgresql_log_file -D $postgresql_datadir -m $postgresql_shut_mode
-    rcVarIsYes postgresql_pgpool && @l_prefix@/bin/pgpool stop
+    if rcVarIsYes postgresql_slony1; then
+        postgresql_slony1_stop
+    fi
+    if rcVarIsYes postgresql_pgpool; then
+        @l_prefix@/bin/pgpool stop
+    fi
 
 %restart -p 400 -u @l_rusr@
     rcService postgresql enable yes || exit 0
     rcService postgresql active no  && exit 0
     @l_prefix@/bin/pg_ctl restart -l $postgresql_log_file -D $postgresql_datadir -o "$postgresql_opts" -m $postgresql_shut_mode
+    if rcVarIsYes postgresql_slony1; then
+        postgresql_slony1_stop
+        postgresql_slony1_start
+    fi
     if rcVarIsYes postgresql_pgpool; then
         @l_prefix@/bin/pgpool stop
         @l_prefix@/bin/pgpool