blob: 57613364fad76f60af35d87776c20e133d182b1b (
plain)
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
81
82
83
84
85
86
87
88
89
90
91
92
|
#!/bin/sh /etc/rc.common
# Copyright (C) 2006-2015 OpenWrt.org
START=50
PROG=/usr/bin/postmaster
USE_PROCD=1
fix_hosts() {
# make sure localhost (without a dot) is in /etc/hosts
grep -q 'localhost$' /etc/hosts || echo '127.0.0.1 localhost' >> /etc/hosts
}
fix_perms() {
# for whatever reason, /dev/null gets wrong perms
chmod a+w /dev/null
}
cleanup() {
if [ -f "$1/postmaster.pid" ]; then
rm "$1/postmaster.pid"
fi
}
start_service() {
. /lib/functions/postgresql.sh
config_load "postgresql"
config_get pgdata config PGDATA
config_get pgopts config PGOPTS
user_exists postgres 5432 || user_add postgres 5432
group_exists postgres 5432 || group_add postgres 5432
[ "$_BOOT" = "1" ] &&
[ "$(procd_get_mountpoints $pgdata)" ] && return 0
fix_perms
fix_hosts
if [ ! -e "${pgdata}/PG_VERSION" ]; then
pg_init_data ${pgdata}
[ $? -gt 0 ] && return 1
fi
cleanup "${pgdata}"
mkdir -m 0755 -p /var/run/postgresql
chmod 0750 /var/run/postgresql
chown postgres:postgres /var/run/postgresql
procd_open_instance postmaster
procd_set_param user postgres
procd_set_param command $PROG
procd_append_param command -D "${pgdata}"
procd_append_param command -k "/var/run/postgresql"
[ -n "${pgopts}" ] && procd_append_param command -o "${pgopts}"
procd_set_param respawn retry=60
procd_add_jail postgresql log
procd_add_jail_mount /usr/lib/postgresql /usr/share/postgresql
procd_add_jail_mount_rw /var/run/postgresql "${pgdata}"
procd_add_jail_mount_rw /dev/shm
procd_set_param stderr 1
procd_set_param stdout 1
procd_close_instance
procd_open_instance uci_dbinit
procd_set_param user postgres
procd_set_param command /lib/functions/postgresql.sh init "${pgdata}"
procd_set_param stdout 1
procd_set_param stderr 1
procd_close_instance
}
boot() {
_BOOT=1 start
}
service_triggers() {
config_load "postgresql"
config_get pgdata config PGDATA
procd_add_restart_mount_trigger "${pgdata}"
}
stop_service() {
procd_send_signal "postgresql" postmaster SIGTERM
}
status_service() {
config_load "postgresql"
config_get pgdata config PGDATA
/usr/bin/pg_ctl status -U postgres -D "${pgdata}"
}
|