|
@@ -1,93 +1,73 @@
|
1
|
1
|
#!/bin/sh /etc/rc.common
|
2
|
|
-# Copyright (C) 2006 OpenWrt.org
|
|
2
|
+# Copyright (C) 2006-2015 OpenWrt.org
|
3
|
3
|
START=50
|
4
|
4
|
|
5
|
|
-EXTRA_COMMANDS="status reload"
|
|
5
|
+PROG=/usr/bin/postmaster
|
6
|
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
|
|
7
|
+USE_PROCD=1
|
12
|
8
|
|
13
|
|
-start() {
|
14
|
|
- if [ ! -e /usr/bin/su ]; then
|
15
|
|
- echo "The su command is requred to run postgres"
|
16
|
|
- exit 1
|
17
|
|
- fi
|
|
9
|
+EXTRA_COMMANDS="status"
|
|
10
|
+EXTRA_HELP=" status Show current status of the PostgreSQL server"
|
18
|
11
|
|
19
|
|
- if [ ! -d ${pgdata} ]; then
|
20
|
|
- echo "Create the data directory (${pgdata}) and try again"
|
21
|
|
- exit 1
|
22
|
|
- fi
|
|
12
|
+fix_hosts() {
|
|
13
|
+ # make sure localhost (without a dot) is in /etc/hosts
|
|
14
|
+ grep -q 'localhost$' /etc/hosts || echo '127.0.0.1 localhost' >> /etc/hosts
|
|
15
|
+}
|
23
|
16
|
|
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
|
|
17
|
+fix_perms() {
|
|
18
|
+ # for whatever reason, /dev/null gets wrong perms
|
|
19
|
+ chmod a+w /dev/null
|
|
20
|
+}
|
27
|
21
|
|
28
|
|
- # for whatever reason, /dev/null gets wrong perms
|
29
|
|
- chmod a+w /dev/null
|
|
22
|
+cleanup() {
|
|
23
|
+ if [ -f "$1/postmaster.pid" ]; then
|
|
24
|
+ rm "$1/postmaster.pid"
|
|
25
|
+ fi
|
|
26
|
+}
|
30
|
27
|
|
31
|
|
- if [ -f ${pgdata}/postmaster.pid ]; then
|
32
|
|
- rm ${pgdata}/postmaster.pid
|
33
|
|
- fi
|
|
28
|
+start_service() {
|
|
29
|
+ config_load "postgresql"
|
|
30
|
+ config_get pgdata config PGDATA
|
|
31
|
+ config_get pguser config PGUSER
|
|
32
|
+ config_get pgctl config PG_CTL
|
|
33
|
+ config_get pgopts config PGOPTS
|
34
|
34
|
|
35
|
|
- config_get pgopts config PGOPTS
|
36
|
|
- if [ -n "${pgopts}" ]; then
|
37
|
|
- pgopts="-o ${pgopts}"
|
38
|
|
- fi
|
39
|
|
- /usr/bin/su ${pguser} -c "/usr/bin/postmaster -D '${pgdata}' &" >> ${pglog} 2>&1
|
|
35
|
+ user_exists postgres 5432 || user_add postgres 5432
|
|
36
|
+ group_exists postgres 5432 || group_add postgres 5432
|
40
|
37
|
|
41
|
|
- while :
|
42
|
|
- do
|
43
|
|
- cnt=$((${cnt} + 1))
|
44
|
|
- if [ -f "${pgdata}/postmaster.pid" ]; then
|
45
|
|
- ret=0
|
46
|
|
- break
|
47
|
|
- fi
|
|
38
|
+ if [ ! -d "${pgdata}" ]; then
|
|
39
|
+ echo "Create the data directory (${pgdata}) and try again"
|
|
40
|
+ return 1
|
|
41
|
+ fi
|
48
|
42
|
|
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
|
|
43
|
+ fix_perms
|
|
44
|
+ fix_hosts
|
56
|
45
|
|
57
|
|
- echo "ok"
|
58
|
|
- return ${ret}
|
59
|
|
-}
|
|
46
|
+ procd_open_instance
|
60
|
47
|
|
61
|
|
-stop() {
|
62
|
|
- echo "stopping postgres..."
|
63
|
|
- /usr/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
|
|
-}
|
|
48
|
+ procd_set_param user ${pguser}
|
|
49
|
+ procd_set_param command $PROG
|
|
50
|
+ procd_append_param command -D "${pgdata}"
|
|
51
|
+ [ -n "${pgopts}" ] && procd_append_param command -o "${pgopts}"
|
71
|
52
|
|
72
|
|
-restart() {
|
73
|
|
- echo "restarting postgres..."
|
74
|
|
- /usr/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
|
|
- /usr/bin/su ${pguser} -c "/usr/bin/postmaster -D '${pgdata}' &" >> ${pglog} 2>&1
|
79
|
|
- echo "ok"
|
80
|
|
- return $?
|
|
53
|
+ procd_set_param respawn retry=60
|
|
54
|
+ procd_close_instance
|
81
|
55
|
}
|
82
|
56
|
|
83
|
|
-reload() {
|
84
|
|
- echo "reloading postgres..."
|
85
|
|
- /usr/bin/su ${pguser} -c "${pgctl} reload -D '${pgdata}' -s"
|
86
|
|
- echo "ok"
|
|
57
|
+reload_service() {
|
|
58
|
+ config_load "postgresql"
|
|
59
|
+ config_get pgdata config PGDATA
|
|
60
|
+ config_get pguser config PGUSER
|
|
61
|
+ config_get pgctl config PG_CTL
|
|
62
|
+ ${pgctl} reload -U ${pguser} -D '${pgdata}' -s
|
87
|
63
|
}
|
88
|
64
|
|
89
|
65
|
status() {
|
90
|
|
- echo "status postgres..."
|
91
|
|
- /usr/bin/su ${pguser} -c "${pgctl} status -D '${pgdata}'"
|
92
|
|
- echo "ok"
|
|
66
|
+ config_load "postgresql"
|
|
67
|
+ config_get pgdata config PGDATA
|
|
68
|
+ config_get pguser config PGUSER
|
|
69
|
+ config_get pgctl config PG_CTL
|
|
70
|
+ echo "status postgres..."
|
|
71
|
+ ${pgctl} status -U ${pguser} -D '${pgdata}'
|
|
72
|
+ echo "ok"
|
93
|
73
|
}
|