updated on Thu Jan 19 12:17:07 UTC 2012
[aur-mirror.git] / postgresql-beta / postgresql.rc
blobea5727c300597ba7e561730a8548823e2eb14e37
1 #!/bin/bash
3 . /etc/rc.conf
4 . /etc/rc.d/functions
5 . /etc/conf.d/postgresql
7 case "$1" in
8 start)
9 stat_busy "Starting PostgreSQL"
10 # initialization
11 if [ ! `egrep '^postgres:' /etc/group` ]; then
12 stat_busy "Adding postgres group"
13 groupadd -g 88 postgres
14 stat_done
16 if [ ! `egrep '^postgres:' /etc/passwd` ]; then
17 stat_busy "Adding postgres user"
18 useradd -u 88 -g postgres -d $PGROOT -s /bin/bash postgres
19 [ -d $PGROOT ] && chown -R postgres.postgres $PGROOT
20 stat_done
22 if [ ! -d $PGROOT ]; then
23 mkdir -p $PGROOT/data && chown postgres.postgres $PGROOT/data
24 su - postgres -c "/usr/bin/initdb -D $PGROOT/data --locale $LOCALE"
26 if [ ! -e /var/log/postgresql.log ]; then
27 touch /var/log/postgresql.log
28 chown postgres /var/log/postgresql.log
30 # start the process
31 su - postgres -c \
32 "/usr/bin/pg_ctl -D $PGROOT/data -l /var/log/postgresql.log -W start"
33 if [ $? -gt 0 ]; then
34 stat_fail
35 else
36 add_daemon postgresql
37 stat_done
40 stop)
41 stat_busy "Stopping PostgreSQL"
42 su - postgres -c \
43 "/usr/bin/pg_ctl -D $PGROOT/data -l /var/log/postgresql.log -w stop"
44 if [ $? -gt 0 ]; then
45 stat_fail
46 else
47 rm_daemon postgresql
48 stat_done
51 restart)
52 $0 stop
53 sleep 3
54 $0 start
57 echo "usage: $0 {start|stop|restart}"
58 esac
59 exit 0