updated on Wed Jan 25 16:08:47 UTC 2012
[aur-mirror.git] / postgresql-testing / postgresql.rc
blob0fbe94036b683a6210325003ef0a8016c49fe7e2
1 #!/bin/bash
3 . /etc/rc.conf
4 . /etc/rc.d/functions
5 . /etc/conf.d/postgresql
7 # Default PGROOT if it wasn't defined in the conf.d file
8 PGROOT=${PGROOT:-/var/lib/postgres}
9 PG_CTL="/usr/bin/pg_ctl -D $PGROOT/data -l /var/log/postgresql.log -s -w"
11 postgres_init() {
12 # initialization
13 if [ ! -d $PGROOT/data ]; then
14 mkdir -p $PGROOT/data && chown -R postgres:postgres $PGROOT
15 su - postgres -c "/usr/bin/initdb $INITOPTS -D $PGROOT/data"
17 if [ ! -e /var/log/postgresql.log ]; then
18 touch /var/log/postgresql.log
19 chown postgres /var/log/postgresql.log
23 case "$1" in
24 start)
25 postgres_init
26 stat_busy "Starting PostgreSQL"
27 su - postgres -c \
28 "$PG_CTL start"
29 if [ $? -gt 0 ]; then
30 stat_fail
31 exit 1
32 else
33 add_daemon postgresql
34 stat_done
37 stop)
38 stat_busy "Stopping PostgreSQL"
39 su - postgres -c \
40 "$PG_CTL stop -m fast"
41 if [ $? -gt 0 ]; then
42 stat_fail
43 else
44 rm_daemon postgresql
45 stat_done
48 reload)
49 stat_busy "Reloading PostgreSQL"
50 su - postgres -c \
51 "$PG_CTL reload"
52 if [ $? -gt 0 ]; then
53 stat_fail
54 exit 1
55 else
56 stat_done
59 restart)
60 postgres_init
61 stat_busy "Restarting PostgreSQL"
62 su - postgres -c \
63 "$PG_CTL restart -m fast"
64 if [ $? -gt 0 ]; then
65 stat_fail
66 exit 1
67 else
68 add_daemon postgresql
69 stat_done
72 status)
73 stat_busy "Checking PostgreSQL status";
74 ck_status postgresql
77 echo "usage: $0 {start|stop|reload|restart|status}"
78 esac
79 exit 0