diff options
author | Chong.Lu@windriver.com <Chong.Lu@windriver.com> | 2014-04-22 15:07:25 +0800 |
---|---|---|
committer | Martin Jansa <Martin.Jansa@gmail.com> | 2014-05-03 20:45:02 +0200 |
commit | ee8a6c23712aa5f267b881e62f1cda3812f56bde (patch) | |
tree | bbed943265a973a8bab9f80cec2fa774d9d3a74c /meta-oe/recipes-support | |
parent | 846ab65cfed72c1cdba465e51ed40d3a9fb6b690 (diff) | |
download | meta-openembedded-ee8a6c23712aa5f267b881e62f1cda3812f56bde.tar.gz |
postgresql: add init script and DESCRIPTION
1. Add DESCRIPTION
2. Add init script for starting up the PostgreSQL server.
3. Disable krb5 by default
Signed-off-by: Chong Lu <Chong.Lu@windriver.com>
Signed-off-by: Martin Jansa <Martin.Jansa@gmail.com>
Diffstat (limited to 'meta-oe/recipes-support')
3 files changed, 303 insertions, 5 deletions
diff --git a/meta-oe/recipes-support/postgresql/files/postgresql-bashprofile b/meta-oe/recipes-support/postgresql/files/postgresql-bashprofile new file mode 100644 index 000000000..1c931f37f --- /dev/null +++ b/meta-oe/recipes-support/postgresql/files/postgresql-bashprofile | |||
@@ -0,0 +1,4 @@ | |||
1 | [ -f /etc/profile ] && source /etc/profile | ||
2 | |||
3 | PGDATA=/var/lib/postgresql/data | ||
4 | export PGDATA | ||
diff --git a/meta-oe/recipes-support/postgresql/files/postgresql.init b/meta-oe/recipes-support/postgresql/files/postgresql.init new file mode 100644 index 000000000..ab4647760 --- /dev/null +++ b/meta-oe/recipes-support/postgresql/files/postgresql.init | |||
@@ -0,0 +1,241 @@ | |||
1 | #!/bin/sh | ||
2 | # | ||
3 | # postgresql This is the init script for starting up the PostgreSQL | ||
4 | # server. | ||
5 | # | ||
6 | # chkconfig: - 64 36 | ||
7 | # description: PostgreSQL database server. | ||
8 | # processname: postmaster | ||
9 | # pidfile: /var/run/postmaster.PORT.pid | ||
10 | |||
11 | # This script is slightly unusual in that the name of the daemon (postmaster) | ||
12 | # is not the same as the name of the subsystem (postgresql) | ||
13 | |||
14 | # PGVERSION is the full package version, e.g., 8.4.0 | ||
15 | # Note: the specfile inserts the correct value during package build | ||
16 | PGVERSION=9.2.4 | ||
17 | # PGMAJORVERSION is major version, e.g., 8.4 (this should match PG_VERSION) | ||
18 | PGMAJORVERSION=`echo "$PGVERSION" | sed 's/^\([0-9]*\.[0-9]*\).*$/\1/'` | ||
19 | |||
20 | # Source function library. | ||
21 | . /etc/init.d/functions | ||
22 | |||
23 | # Find the name of the script | ||
24 | NAME=`basename $0` | ||
25 | if [ ${NAME:0:1} = "S" -o ${NAME:0:1} = "K" ] | ||
26 | then | ||
27 | NAME=${NAME:3} | ||
28 | fi | ||
29 | |||
30 | # For SELinux we need to use 'runuser' not 'su' | ||
31 | if [ -x /sbin/runuser ] | ||
32 | then | ||
33 | SU=runuser | ||
34 | else | ||
35 | SU=su | ||
36 | fi | ||
37 | |||
38 | |||
39 | # Set defaults for configuration variables | ||
40 | PGENGINE=/usr/bin | ||
41 | PGPORT=5432 | ||
42 | PGDATA=/var/lib/postgresql/data | ||
43 | PGLOG=/var/lib/postgresql/pgstartup.log | ||
44 | # Value to set as postmaster process's oom_adj | ||
45 | PG_OOM_ADJ=-17 | ||
46 | |||
47 | # Override defaults from /etc/sysconfig/postgresql if file is present | ||
48 | [ -f /etc/default/postgresql/${NAME} ] && . /etc/default/postgresql/${NAME} | ||
49 | |||
50 | export PGDATA | ||
51 | export PGPORT | ||
52 | |||
53 | lockfile="/var/lock/subsys/${NAME}" | ||
54 | pidfile="/var/run/postmaster.${PGPORT}.pid" | ||
55 | |||
56 | script_result=0 | ||
57 | |||
58 | start(){ | ||
59 | [ -x "$PGENGINE/postmaster" ] || exit 5 | ||
60 | |||
61 | PSQL_START=$"Starting ${NAME} service: " | ||
62 | |||
63 | # Make sure startup-time log file is valid | ||
64 | if [ ! -e "$PGLOG" -a ! -h "$PGLOG" ] | ||
65 | then | ||
66 | touch "$PGLOG" || exit 4 | ||
67 | chown postgres:postgres "$PGLOG" | ||
68 | chmod go-rwx "$PGLOG" | ||
69 | [ -x /sbin/restorecon ] && /sbin/restorecon "$PGLOG" | ||
70 | fi | ||
71 | |||
72 | # Check for the PGDATA structure | ||
73 | if [ -f "$PGDATA/PG_VERSION" ] && [ -d "$PGDATA/base" ] | ||
74 | then | ||
75 | # Check version of existing PGDATA | ||
76 | if [ x`cat "$PGDATA/PG_VERSION"` != x"$PGMAJORVERSION" ] | ||
77 | then | ||
78 | SYSDOCDIR="(Your System's documentation directory)" | ||
79 | if [ -d "/usr/doc/postgresql-$PGVERSION" ] | ||
80 | then | ||
81 | SYSDOCDIR=/usr/doc | ||
82 | fi | ||
83 | if [ -d "/usr/share/doc/postgresql-$PGVERSION" ] | ||
84 | then | ||
85 | SYSDOCDIR=/usr/share/doc | ||
86 | fi | ||
87 | if [ -d "/usr/doc/packages/postgresql-$PGVERSION" ] | ||
88 | then | ||
89 | SYSDOCDIR=/usr/doc/packages | ||
90 | fi | ||
91 | if [ -d "/usr/share/doc/packages/postgresql-$PGVERSION" ] | ||
92 | then | ||
93 | SYSDOCDIR=/usr/share/doc/packages | ||
94 | fi | ||
95 | echo | ||
96 | echo $"An old version of the database format was found." | ||
97 | echo $"You need to upgrade the data format before using PostgreSQL." | ||
98 | echo $"See $SYSDOCDIR/postgresql-$PGVERSION/README.rpm-dist for more information." | ||
99 | exit 1 | ||
100 | fi | ||
101 | else | ||
102 | # No existing PGDATA! Warn the user to initdb it. | ||
103 | echo | ||
104 | echo "$PGDATA is missing. Use \"service postgresql initdb\" to initialize the cluster first." | ||
105 | echo -n " [FAILED] " | ||
106 | echo | ||
107 | exit 1 | ||
108 | fi | ||
109 | |||
110 | echo -n "$PSQL_START" | ||
111 | test x"$PG_OOM_ADJ" != x && echo "$PG_OOM_ADJ" > /proc/self/oom_score_adj | ||
112 | $SU -l postgres -c "$PGENGINE/postmaster -p '$PGPORT' -D '$PGDATA' ${PGOPTS} &" >> "$PGLOG" 2>&1 < /dev/null | ||
113 | sleep 2 | ||
114 | pid=`head -n 1 "$PGDATA/postmaster.pid" 2>/dev/null` | ||
115 | if [ "x$pid" != x ] | ||
116 | then | ||
117 | echo -n " [ OK ]" | ||
118 | touch "$lockfile" | ||
119 | echo $pid > "$pidfile" | ||
120 | echo | ||
121 | else | ||
122 | echo -n " [FAILED]" | ||
123 | echo | ||
124 | script_result=1 | ||
125 | fi | ||
126 | } | ||
127 | |||
128 | stop(){ | ||
129 | echo -n $"Stopping ${NAME} service: " | ||
130 | if [ -e "$lockfile" ] | ||
131 | then | ||
132 | $SU -l postgres -c "$PGENGINE/pg_ctl stop -D '$PGDATA' -s -m fast" > /dev/null 2>&1 < /dev/null | ||
133 | ret=$? | ||
134 | if [ $ret -eq 0 ] | ||
135 | then | ||
136 | echo -n " [ OK ] " | ||
137 | rm -f "$pidfile" | ||
138 | rm -f "$lockfile" | ||
139 | else | ||
140 | echo -n " [FAILED] " | ||
141 | script_result=1 | ||
142 | fi | ||
143 | else | ||
144 | # not running; per LSB standards this is "ok" | ||
145 | echo -n " [ OK ] " | ||
146 | fi | ||
147 | echo | ||
148 | } | ||
149 | |||
150 | restart(){ | ||
151 | stop | ||
152 | start | ||
153 | } | ||
154 | |||
155 | condrestart(){ | ||
156 | [ -e "$lockfile" ] && restart || : | ||
157 | } | ||
158 | |||
159 | reload(){ | ||
160 | $SU -l postgres -c "$PGENGINE/pg_ctl reload -D '$PGDATA' -s" > /dev/null 2>&1 < /dev/null | ||
161 | } | ||
162 | |||
163 | initdb(){ | ||
164 | if [ -f "$PGDATA/PG_VERSION" ] | ||
165 | then | ||
166 | echo -n "Data directory is not empty!" | ||
167 | echo -n " [FAILED] " | ||
168 | echo | ||
169 | script_result=1 | ||
170 | else | ||
171 | echo -n $"Initializing database: " | ||
172 | if [ ! -e "$PGDATA" -a ! -h "$PGDATA" ] | ||
173 | then | ||
174 | mkdir -p "$PGDATA" || exit 1 | ||
175 | chown postgres:postgres "$PGDATA" | ||
176 | chmod go-rwx "$PGDATA" | ||
177 | fi | ||
178 | # Clean up SELinux tagging for PGDATA | ||
179 | [ -x /sbin/restorecon ] && /sbin/restorecon "$PGDATA" | ||
180 | |||
181 | # Make sure the startup-time log file is OK, too | ||
182 | if [ ! -e "$PGLOG" -a ! -h "$PGLOG" ] | ||
183 | then | ||
184 | touch "$PGLOG" || exit 1 | ||
185 | chown postgres:postgres "$PGLOG" | ||
186 | chmod go-rwx "$PGLOG" | ||
187 | [ -x /sbin/restorecon ] && /sbin/restorecon "$PGLOG" | ||
188 | fi | ||
189 | |||
190 | # Initialize the database | ||
191 | $SU -l postgres -c "$PGENGINE/initdb --pgdata='$PGDATA' --auth='ident'" >> "$PGLOG" 2>&1 < /dev/null | ||
192 | |||
193 | # Create directory for postmaster log | ||
194 | mkdir "$PGDATA/pg_log" | ||
195 | chown postgres:postgres "$PGDATA/pg_log" | ||
196 | chmod go-rwx "$PGDATA/pg_log" | ||
197 | |||
198 | if [ -f "$PGDATA/PG_VERSION" ] | ||
199 | then | ||
200 | echo -n " [ OK ] " | ||
201 | else | ||
202 | echo -n " [FAILED] " | ||
203 | script_result=1 | ||
204 | fi | ||
205 | echo | ||
206 | fi | ||
207 | } | ||
208 | |||
209 | # See how we were called. | ||
210 | case "$1" in | ||
211 | start) | ||
212 | start | ||
213 | ;; | ||
214 | stop) | ||
215 | stop | ||
216 | ;; | ||
217 | status) | ||
218 | status postmaster | ||
219 | script_result=$? | ||
220 | ;; | ||
221 | restart) | ||
222 | restart | ||
223 | ;; | ||
224 | condrestart|try-restart) | ||
225 | condrestart | ||
226 | ;; | ||
227 | reload) | ||
228 | reload | ||
229 | ;; | ||
230 | force-reload) | ||
231 | restart | ||
232 | ;; | ||
233 | initdb) | ||
234 | initdb | ||
235 | ;; | ||
236 | *) | ||
237 | echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|initdb}" | ||
238 | exit 2 | ||
239 | esac | ||
240 | |||
241 | exit $script_result | ||
diff --git a/meta-oe/recipes-support/postgresql/postgresql.inc b/meta-oe/recipes-support/postgresql/postgresql.inc index 5f2088e99..db425e765 100644 --- a/meta-oe/recipes-support/postgresql/postgresql.inc +++ b/meta-oe/recipes-support/postgresql/postgresql.inc | |||
@@ -1,4 +1,22 @@ | |||
1 | DESCRIPTION = "PostgreSQL is a powerful, open source relational database system." | 1 | SUMMARY = "PostgreSQL is a powerful, open source relational database system." |
2 | DESCRIPTION = "\ | ||
3 | PostgreSQL is an advanced Object-Relational database management system \ | ||
4 | (DBMS) that supports almost all SQL constructs (including \ | ||
5 | transactions, subselects and user-defined types and functions). The \ | ||
6 | postgresql package includes the client programs and libraries that \ | ||
7 | you'll need to access a PostgreSQL DBMS server. These PostgreSQL \ | ||
8 | client programs are programs that directly manipulate the internal \ | ||
9 | structure of PostgreSQL databases on a PostgreSQL server. These client \ | ||
10 | programs can be located on the same machine with the PostgreSQL \ | ||
11 | server, or may be on a remote machine which accesses a PostgreSQL \ | ||
12 | server over a network connection. This package contains the docs \ | ||
13 | in HTML for the whole package, as well as command-line utilities for \ | ||
14 | managing PostgreSQL databases on a PostgreSQL server. \ | ||
15 | \ | ||
16 | If you want to manipulate a PostgreSQL database on a local or remote \ | ||
17 | PostgreSQL server, you need this package. You also need to install \ | ||
18 | this package if you're installing the postgresql-server package. \ | ||
19 | " | ||
2 | HOMEPAGE = "http://www.postgresql.com" | 20 | HOMEPAGE = "http://www.postgresql.com" |
3 | LICENSE = "BSD" | 21 | LICENSE = "BSD" |
4 | DEPENDS = "zlib readline tzcode-native" | 22 | DEPENDS = "zlib readline tzcode-native" |
@@ -8,23 +26,58 @@ ARM_INSTRUCTION_SET = "arm" | |||
8 | 26 | ||
9 | #WARNING: this recipe assumes you have the timezone compiler present in /usr/sbin/zic | 27 | #WARNING: this recipe assumes you have the timezone compiler present in /usr/sbin/zic |
10 | 28 | ||
11 | SRC_URI = "http://ftp.postgresql.org/pub/source/v${PV}/${P}.tar.bz2" | 29 | SRC_URI = "http://ftp.postgresql.org/pub/source/v${PV}/${P}.tar.bz2 \ |
30 | file://postgresql.init \ | ||
31 | file://postgresql-bashprofile \ | ||
32 | " | ||
12 | 33 | ||
13 | LEAD_SONAME = "libpq.so" | 34 | LEAD_SONAME = "libpq.so" |
14 | 35 | ||
15 | # LDFLAGS for shared libraries | 36 | # LDFLAGS for shared libraries |
16 | export LDFLAGS_SL = "${LDFLAGS}" | 37 | export LDFLAGS_SL = "${LDFLAGS}" |
17 | 38 | ||
18 | inherit autotools pkgconfig | 39 | inherit autotools pkgconfig useradd |
19 | 40 | ||
20 | EXTRA_OECONF = "--disable-rpath" | 41 | EXTRA_OECONF += "--enable-thread-safety --disable-rpath \ |
21 | EXTRA_OECONF_sh4 = "--disable-spinlocks --disable-rpath" | 42 | --datadir=${datadir}/${BPN} \ |
43 | --sysconfdir=${sysconfdir}/${BPN} \ | ||
44 | --without-krb5 \ | ||
45 | " | ||
46 | EXTRA_OECONF_sh4 += "--disable-spinlocks" | ||
22 | EXTRA_OECONF_aarch64 += "--disable-spinlocks" | 47 | EXTRA_OECONF_aarch64 += "--disable-spinlocks" |
23 | 48 | ||
24 | do_compile_append() { | 49 | do_compile_append() { |
25 | cp /usr/sbin/zic ${S}/src/timezone/ | 50 | cp /usr/sbin/zic ${S}/src/timezone/ |
26 | } | 51 | } |
27 | 52 | ||
53 | # server needs to configure user and group | ||
54 | usernum = "28" | ||
55 | groupnum = "28" | ||
56 | USERADD_PACKAGES = "${PN}" | ||
57 | USERADD_PARAM_${PN} = "-M -g postgres -o -r -d ${localstatedir}/lib/${BPN} \ | ||
58 | -s /bin/bash -c 'PostgreSQL Server' -u ${usernum} postgres" | ||
59 | GROUPADD_PARAM_${PN} = "-g ${groupnum} -o -r postgres" | ||
60 | |||
61 | INITSCRIPT_PACKAGES = "${PN}" | ||
62 | INITSCRIPT_NAME = "${BPN}-server" | ||
63 | INITSCRIPT_PARAMS = "start 64 . stop 36 0 1 2 3 4 5 6 ." | ||
64 | |||
65 | do_install_append() { | ||
66 | # install dirs and server init | ||
67 | install -d ${D}${sysconfdir}/init.d | ||
68 | install -m 0755 ${WORKDIR}/${BPN}.init \ | ||
69 | ${D}${sysconfdir}/init.d/${BPN}-server | ||
70 | sed -i -e "s/^PGVERSION=.*$/PGVERSION=${PV}/g" \ | ||
71 | ${D}${sysconfdir}/init.d/${BPN}-server | ||
72 | install -d -m 700 ${D}${localstatedir}/lib/${BPN}/data | ||
73 | install -d -m 700 ${D}${localstatedir}/lib/${BPN}/backups | ||
74 | install -m 644 ${WORKDIR}/${BPN}-bashprofile \ | ||
75 | ${D}${localstatedir}/lib/${BPN}/.bash_profile | ||
76 | chown -R postgres:postgres ${D}${localstatedir}/lib/${BPN} | ||
77 | # multiple server config directory | ||
78 | install -d -m 700 ${D}${sysconfdir}/default/${BPN} | ||
79 | } | ||
80 | |||
28 | SSTATE_SCAN_FILES += "Makefile.global" | 81 | SSTATE_SCAN_FILES += "Makefile.global" |
29 | 82 | ||
30 | PACKAGES =+ "${PN}-client ${PN}-server-dev ${PN}-timezone \ | 83 | PACKAGES =+ "${PN}-client ${PN}-server-dev ${PN}-timezone \ |