1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2006 OpenWrt.org
5 EXTRA_COMMANDS
="status reload"
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
14 if [ ! -e /bin
/su
]; then
15 echo "The su command is requred to run postgres"
19 if [ ! -d ${pgdata} ]; then
20 echo "Create the data directory (${pgdata}) and try again"
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
28 # for whatever reason, /dev/null gets wrong perms
31 if [ -f ${pgdata}/postmaster.pid
]; then
32 rm ${pgdata}/postmaster.pid
35 config_get pgopts config PGOPTS
36 if [ -n "${pgopts}" ]; then
39 /bin
/su
${pguser} -c "/usr/bin/postmaster -D '${pgdata}' &" >> ${pglog} 2>&1
44 if [ -f "${pgdata}/postmaster.pid" ]; then
49 if [ ${cnt} -eq 30 ]; then
50 echo "Postgres failed to start. See ${pglog} for details"
62 echo "stopping postgres..."
63 /bin
/su
${pguser} -c "${pgctl} stop -D '${pgdata}' -s -m fast"
65 if [ -f ${pgdata}/postmaster.pid ]; then
66 rm ${pgdata}/postmaster.pid
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
78 /bin/su ${pguser} -c "/usr/bin/postmaster -D '${pgdata}' &" >> ${pglog} 2>&1
84 echo "reloading postgres...
"
85 /bin/su ${pguser} -c "${pgctl} reload -D '${pgdata}' -s"
90 echo "status postgres..."
91 /bin
/su
${pguser} -c "${pgctl} status -D '${pgdata}'"