[package] update mdnsresponder to 214.3.2 (#8083)
[openwrt/svn-archive/archive.git] / libs / postgresql / files / postgresql.init
1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2006 OpenWrt.org
3 START=50
4
5 EXTRA_COMMANDS="status reload"
6
7 config_load "postgresql"
8 config_get pgdata config PGDATA
9 config_get pguser config PGUSER
10 config_get pgctl config PG_CTL
11 config_get pglog config PGLOG
12
13 start() {
14 if [ ! -e /bin/su ]; then
15 echo "The su command is requred to run postgres"
16 exit 1
17 fi
18
19 if [ ! -d ${pgdata} ]; then
20 echo "Create the data directory (${pgdata}) and try again"
21 exit 1
22 fi
23
24 echo "starting postgres..."
25 # make sure localhost (without a dot) is in /etc/hosts
26 grep -q 'localhost$' /etc/hosts || echo '127.0.0.1 localhost' >> /etc/hosts
27
28 # for whatever reason, /dev/null gets wrong perms
29 chmod a+w /dev/null
30
31 if [ -f ${pgdata}/postmaster.pid ]; then
32 rm ${pgdata}/postmaster.pid
33 fi
34
35 config_get pgopts config PGOPTS
36 if [ -n "${pgopts}" ]; then
37 pgopts="-o ${pgopts}"
38 fi
39 /bin/su ${pguser} -c "/usr/bin/postmaster -D '${pgdata}' &" >> ${pglog} 2>&1
40
41 while :
42 do
43 cnt=$((${cnt} + 1))
44 if [ -f "${pgdata}/postmaster.pid" ]; then
45 ret=0
46 break
47 fi
48
49 if [ ${cnt} -eq 30 ]; then
50 echo "Postgres failed to start. See ${pglog} for details"
51 ret=1
52 break
53 fi
54 sleep 1
55 done
56
57 echo "ok"
58 return ${ret}
59 }
60
61 stop() {
62 echo "stopping postgres..."
63 /bin/su ${pguser} -c "${pgctl} stop -D '${pgdata}' -s -m fast"
64 ret=$?
65 if [ -f ${pgdata}/postmaster.pid ]; then
66 rm ${pgdata}/postmaster.pid
67 fi
68 echo "ok"
69 return ${ret}
70 }
71
72 restart() {
73 echo "restarting postgres..."
74 /bin/su ${pguser} -c "${pgctl} stop -D '${pgdata}' -s -m fast -w"
75 if [ -f ${pgdata}/postmaster.pid ]; then
76 rm ${pgdata}/postmaster.pid
77 fi
78 /bin/su ${pguser} -c "/usr/bin/postmaster -D '${pgdata}' &" >> ${pglog} 2>&1
79 echo "ok"
80 return $?
81 }
82
83 reload() {
84 echo "reloading postgres..."
85 /bin/su ${pguser} -c "${pgctl} reload -D '${pgdata}' -s"
86 echo "ok"
87 }
88
89 status() {
90 echo "status postgres..."
91 /bin/su ${pguser} -c "${pgctl} status -D '${pgdata}'"
92 echo "ok"
93 }