forked from jasonish/evebox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pgctl.sh
executable file
·80 lines (63 loc) · 1005 Bytes
/
pgctl.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#! /bin/sh
POSTGRES=postgres
PSQL=psql
INITDB=initdb
PGCTL=pg_ctl
CREATEDB=createdb
PGVERSION=$(${POSTGRES} --version | sed -n 's/[^0-9]*\([0-9]\.[0-9]\).*/\1/p')
PGHOST=127.0.0.1
PGPORT=8432
PGDATA=./data/pgdata${PGVERSION}
PGDATABASE=evebox
PGUSER=evebox
export PGHOST PGPORT PGDATABASE PGUSER
init() {
initdb --auth-local=trust --auth-host=trust --username=${PGUSER} \
--encoding=UTF8 ${PGDATA}
start
${CREATEDB} ${PGDATABASE}
${PSQL} -c 'CREATE EXTENSION "uuid-ossp"'
${PSQL} -c 'CREATE EXTENSION "pgcrypto"'
stop
}
start() {
${PGCTL} -D ${PGDATA} -l postgres.log -w start -o "-k /tmp"
}
stop() {
${PGCTL} -D ${PGDATA} -w -m fast stop
}
case "$1" in
init)
init
;;
reinit)
stop
rm -rf ${PGDATA}
init
start
;;
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
dump)
pg_dump --data-only
;;
restore)
shift
pg_restore "$@"
;;
env)
exec "$@"
;;
psql)
shift
${PSQL} ${PGDATABSE} "$@"
;;
esac