|
1 #!@l_prefix@/bin/openpkg rc |
|
2 ## |
|
3 ## rc.postgresql -- Run-Commands |
|
4 ## |
|
5 |
|
6 %config |
|
7 postgresql_enable="$openpkg_rc_def" |
|
8 postgresql_flags="" |
|
9 postgresql_datadir="@l_prefix@/var/postgresql/db" |
|
10 postgresql_rundir="@l_prefix@/var/postgresql/run" |
|
11 postgresql_shut_mode="fast" |
|
12 postgresql_socket_inet="127.0.0.1" |
|
13 postgresql_socket_unix="@l_prefix@/var/postgresql/run" |
|
14 postgresql_log_prolog="true" |
|
15 postgresql_log_epilog="true" |
|
16 postgresql_log_numfiles="10" |
|
17 postgresql_log_minsize="1M" |
|
18 postgresql_log_complevel="9" |
|
19 postgresql_slony1="no" |
|
20 |
|
21 %common |
|
22 postgresql_opts="-h $postgresql_socket_inet -k $postgresql_socket_unix" |
|
23 postgresql_opts="$postgresql_opts $postgresql_flags" |
|
24 postgresql_logfile="$postgresql_rundir/postgresql.log" |
|
25 postgresql_pidfile="$postgresql_datadir/postgresql.pid" |
|
26 postgresql_slony1_pidfile="$postgresql_rundir/slon.pid" |
|
27 postgresql_slony1_start () { |
|
28 ( . @l_prefix@/etc/postgresql/slony1.conf |
|
29 nohup @l_prefix@/bin/slon \ |
|
30 -d "$SLON_SYNC_LOGLEVEL" -g "$SLON_SYNC_GROUPSIZE" \ |
|
31 -s "$SLON_SYNC_INTERVAL" -t "$SLON_SYNC_TIMEOUT" \ |
|
32 "$SLON_CLUSTER_NAME" \ |
|
33 user="$SLON_CONNECT_USER" password="$SLON_CONNECT_PASS" \ |
|
34 dbname="$SLON_CONNECT_DBNAME" host="$SLON_CONNECT_HOST" |
|
35 </dev/null >/dev/null 2>&1 & |
|
36 echo $! >$postgresql_slony1_pidfile |
|
37 ) >/dev/null 2>&1 |
|
38 } |
|
39 postgresql_slony1_stop () { |
|
40 if [ -f $postgresql_slony1_pidfile ]; then |
|
41 kill -TERM `cat $postgresql_slony1_pidfile` |
|
42 rm -f $postgresql_slony1_pidfile |
|
43 fi |
|
44 } |
|
45 postgresql_ctl () { |
|
46 if [ -s $postgresql_pidfile ]; then |
|
47 kill -0 `head -1 $postgresql_pidfile` >/dev/null 2>&1 |
|
48 if [ $? -ne 0 ]; then |
|
49 rm -f $postgresql_pidfile >/dev/null 2>&1 || true |
|
50 rm -f $postgresql_rundir/.s* >/dev/null 2>&1 || true |
|
51 fi |
|
52 fi |
|
53 cmd="$1"; shift |
|
54 @l_prefix@/bin/pg_ctl $cmd \ |
|
55 -l $postgresql_logfile \ |
|
56 -D $postgresql_datadir \ |
|
57 ${1+"$@"} |
|
58 } |
|
59 |
|
60 %status -u @l_rusr@ -o |
|
61 postgresql_usable="unknown" |
|
62 postgresql_active="no" |
|
63 rcService postgresql enable yes && \ |
|
64 postgresql_ctl status >/dev/null && \ |
|
65 postgresql_active="yes" |
|
66 echo "postgresql_enable=\"$postgresql_enable\"" |
|
67 echo "postgresql_usable=\"$postgresql_usable\"" |
|
68 echo "postgresql_active=\"$postgresql_active\"" |
|
69 |
|
70 %start -p 400 -u @l_rusr@ |
|
71 rcService postgresql enable yes || exit 0 |
|
72 rcService postgresql active yes && exit 0 |
|
73 postgresql_ctl start -o "$postgresql_opts" |
|
74 if rcVarIsYes postgresql_slony1; then |
|
75 postgresql_slony1_start |
|
76 fi |
|
77 |
|
78 %stop -p 600 -u @l_rusr@ |
|
79 rcService postgresql enable yes || exit 0 |
|
80 rcService postgresql active no && exit 0 |
|
81 postgresql_ctl stop -m "$postgresql_shut_mode" |
|
82 if rcVarIsYes postgresql_slony1; then |
|
83 postgresql_slony1_stop |
|
84 fi |
|
85 |
|
86 %restart -p 400 -u @l_rusr@ |
|
87 rcService postgresql enable yes || exit 0 |
|
88 rcService postgresql active no && exit 0 |
|
89 postgresql_ctl restart -o "$postgresql_opts" -m "$postgresql_shut_mode" |
|
90 if rcVarIsYes postgresql_slony1; then |
|
91 postgresql_slony1_stop |
|
92 postgresql_slony1_start |
|
93 fi |
|
94 |
|
95 %reload -p 400 -u @l_rusr@ |
|
96 rcService postgresql enable yes || exit 0 |
|
97 rcService postgresql active no && exit 0 |
|
98 postgresql_ctl reload |
|
99 |
|
100 %daily -u @l_rusr@ |
|
101 rcService postgresql enable yes || exit 0 |
|
102 shtool rotate -f \ |
|
103 -n ${postgresql_log_numfiles} -s ${postgresql_log_minsize} -d -c \ |
|
104 -z ${postgresql_log_complevel} -m 600 -o @l_rusr@ -g @l_rgrp@ \ |
|
105 -P "$postgresql_log_prolog" \ |
|
106 -E "$postgresql_log_epilog" \ |
|
107 $postgresql_logfile |
|
108 |