Co-authored-by: Harrison Carter hcarter@thegoodpenguin.co.uk Signed-off-by: Pawel Zalewski pzalewski@thegoodpenguin.co.uk --- ...gument-order-to-qsort_r-to-match-pos.patch | 45 ++ ...change-defines-from-freebsd-to-cheri.patch | 57 +++ ...n-bypass-autoconf-2.69-version-check.patch | 30 ++ recipes-dbs/postgresql/postgresql-morello.inc | 400 ++++++++++++++++++ .../postgresql/postgresql-morello_9.6.bb | 155 +++++++ recipes-dbs/postgresql/postgresql/pg_config | 15 + .../postgresql/postgresql/postgres-bench | 16 + .../postgresql/postgresql/postgres-test | 49 +++ .../postgresql/postgresql/postgresql-init | 64 +++ .../postgresql/postgresql-init.service | 19 + .../postgresql/postgresql-morello.init | 193 +++++++++ .../postgresql/postgresql-morello.service | 29 ++ .../postgresql/postgresql/postgresql-profile | 4 + .../postgresql/postgresql/postgresql-setup | 73 ++++ .../postgresql/postgresql/postgresql.pam | 4 + .../postgresql/postgresql/test-schedule | 1 + recipes-dbs/postgresql/postgresql_%.bbappend | 7 + 17 files changed, 1161 insertions(+) create mode 100644 recipes-dbs/postgresql/cheri-patches/0001-port.h-change-argument-order-to-qsort_r-to-match-pos.patch create mode 100644 recipes-dbs/postgresql/cheri-patches/0002-qsort-change-defines-from-freebsd-to-cheri.patch create mode 100644 recipes-dbs/postgresql/files/0003-configure.in-bypass-autoconf-2.69-version-check.patch create mode 100644 recipes-dbs/postgresql/postgresql-morello.inc create mode 100644 recipes-dbs/postgresql/postgresql-morello_9.6.bb create mode 100755 recipes-dbs/postgresql/postgresql/pg_config create mode 100644 recipes-dbs/postgresql/postgresql/postgres-bench create mode 100644 recipes-dbs/postgresql/postgresql/postgres-test create mode 100644 recipes-dbs/postgresql/postgresql/postgresql-init create mode 100644 recipes-dbs/postgresql/postgresql/postgresql-init.service create mode 100644 recipes-dbs/postgresql/postgresql/postgresql-morello.init create mode 100644 recipes-dbs/postgresql/postgresql/postgresql-morello.service create mode 100644 recipes-dbs/postgresql/postgresql/postgresql-profile create mode 100644 recipes-dbs/postgresql/postgresql/postgresql-setup create mode 100644 recipes-dbs/postgresql/postgresql/postgresql.pam create mode 100644 recipes-dbs/postgresql/postgresql/test-schedule create mode 100644 recipes-dbs/postgresql/postgresql_%.bbappend
diff --git a/recipes-dbs/postgresql/cheri-patches/0001-port.h-change-argument-order-to-qsort_r-to-match-pos.patch b/recipes-dbs/postgresql/cheri-patches/0001-port.h-change-argument-order-to-qsort_r-to-match-pos.patch new file mode 100644 index 0000000..a88b780 --- /dev/null +++ b/recipes-dbs/postgresql/cheri-patches/0001-port.h-change-argument-order-to-qsort_r-to-match-pos.patch @@ -0,0 +1,45 @@ +From daa2184cb2d3df09e1911402e768685ff456cc1f Mon Sep 17 00:00:00 2001 +From: Pawel Zalewski pzalewski@thegoodpenguin.co.uk +Date: Fri, 10 Nov 2023 14:12:37 +0000 +Subject: [PATCH] port.h: change argument order to qsort_r to match posix + +The original codebase is aimed at FreeBSD OS. + +Signed-off-by: Pawel Zalewski pzalewski@thegoodpenguin.co.uk + +--- + src/include/port.h | 8 ++++---- + 1 file changed, 4 insertions(+), 4 deletions(-) + +diff --git a/src/include/port.h b/src/include/port.h +index 10c8ba1194..bddb510e8a 100644 +--- a/src/include/port.h ++++ b/src/include/port.h +@@ -440,7 +440,7 @@ extern void pg_qsort(void *base, size_t nel, size_t elsize, + /* Use ifdef FreeBSD and not __CHERI_PURE_CAPABILITY__ so that we use the same code path for MIPS and CHERI */ + #ifdef __FreeBSD__ + /* Postgres qsort_arg is broken for capabilities so we replace it with qsort_r but that uses a different parameter order for cmp */ +-typedef int (*qsort_arg_comparator) (void *arg, const void *a, const void *b); ++typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); + /* + * XXXAR: the postgres version of qsort_arg does not work with capabilities (swap + * is broken) so we have to make sure to use the libc function qsort_r instead +@@ -448,15 +448,15 @@ typedef int (*qsort_arg_comparator) (void *arg, const void *a, const void *b); + static inline void + qsort_arg(void *a, size_t n, size_t es, qsort_arg_comparator cmp, void *arg) + { +- qsort_r(a, n, es, arg, cmp); ++ qsort_r(a, n, es, cmp, arg); + } + // NOTE: FreeBSD and Linux qsort_r are completely incompatible due to different argument order + // Generating a non-obvious function name avoids stupid errors like in tsrank.c where the function is then called wrongly + + #define QSORT_ARG_COMPARATOR_FUNC(name, a, b) \ +- int _##name##_freebsd_cmp(void *arg, const void *a, const void *b) ++ int _##name##_freebsd_cmp(const void *a, const void *b, void *arg) + #define QSORT_ARG_COMPARATOR_PTR(name) &_##name##_freebsd_cmp +-#define CALL_QSORT_ARG_COMPARATOR(name, a, b, arg) _##name##_freebsd_cmp(arg, a, b) ++#define CALL_QSORT_ARG_COMPARATOR(name, a, b, arg) _##name##_freebsd_cmp(a, b, arg) + #else + /* #warning "Using postgres qsort" */ + #define qsort(a,b,c,d) pg_qsort(a,b,c,d) diff --git a/recipes-dbs/postgresql/cheri-patches/0002-qsort-change-defines-from-freebsd-to-cheri.patch b/recipes-dbs/postgresql/cheri-patches/0002-qsort-change-defines-from-freebsd-to-cheri.patch new file mode 100644 index 0000000..0267382 --- /dev/null +++ b/recipes-dbs/postgresql/cheri-patches/0002-qsort-change-defines-from-freebsd-to-cheri.patch @@ -0,0 +1,57 @@ +From d7c33a58cd02ae15ebdcc6585f568f5f3d8914bd Mon Sep 17 00:00:00 2001 +From: Pawel Zalewski pzalewski@thegoodpenguin.co.uk +Date: Thu, 11 May 2023 15:37:01 +0100 +Subject: [PATCH] qsort: change defines from freebsd to cheri + +This is not FreeBSD OS, so the pre-processor will not do what it should +and the postgres qsrot will be used. + +Lets fix it without due care. + +Signed-off-by: Pawel Zalewski pzalewski@thegoodpenguin.co.uk + +--- + src/include/port.h | 2 +- + src/port/qsort.c | 2 +- + src/port/qsort_arg.c | 2 +- + 3 files changed, 3 insertions(+), 3 deletions(-) + +diff --git a/src/include/port.h b/src/include/port.h +index bddb510e8a..27e7dad9c2 100644 +--- a/src/include/port.h ++++ b/src/include/port.h +@@ -438,7 +438,7 @@ extern void pg_qsort(void *base, size_t nel, size_t elsize, + int (*cmp) (const void *, const void *)); + + /* Use ifdef FreeBSD and not __CHERI_PURE_CAPABILITY__ so that we use the same code path for MIPS and CHERI */ +-#ifdef __FreeBSD__ ++#ifdef __CHERI_PURE_CAPABILITY__ + /* Postgres qsort_arg is broken for capabilities so we replace it with qsort_r but that uses a different parameter order for cmp */ + typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); + /* +diff --git a/src/port/qsort.c b/src/port/qsort.c +index 8a75ff492e..50af3ebb02 100644 +--- a/src/port/qsort.c ++++ b/src/port/qsort.c +@@ -46,7 +46,7 @@ + + #include "c.h" + +-#ifdef __FreeBSD__ ++#ifdef __CHERI_PURE_CAPABILITY__ + /* + * XXXAR: the postgres version of qsort does not work with capabilities (swap + * is broken) so we have to make sure to use the libc version +diff --git a/src/port/qsort_arg.c b/src/port/qsort_arg.c +index 90bbf16541..fb1d5fc6ff 100644 +--- a/src/port/qsort_arg.c ++++ b/src/port/qsort_arg.c +@@ -46,7 +46,7 @@ + + #include "c.h" + +-#ifndef __FreeBSD__ ++#ifndef __CHERI_PURE_CAPABILITY__ + #warning "using postgres custom qsort_arg function" + + static char *med3(char *a, char *b, char *c, diff --git a/recipes-dbs/postgresql/files/0003-configure.in-bypass-autoconf-2.69-version-check.patch b/recipes-dbs/postgresql/files/0003-configure.in-bypass-autoconf-2.69-version-check.patch new file mode 100644 index 0000000..d845b95 --- /dev/null +++ b/recipes-dbs/postgresql/files/0003-configure.in-bypass-autoconf-2.69-version-check.patch @@ -0,0 +1,30 @@ +From 632f02e741878b3e3d3b156cf33595c5f8329e27 Mon Sep 17 00:00:00 2001 +From: Yi Fan Yu yifan.yu@windriver.com +Date: Fri, 5 Feb 2021 17:15:42 -0500 +Subject: [PATCH] configure.ac: bypass autoconf 2.69 version check + +for upgrade to autoconf 2.71 + +Upstream-Status: Inappropriate [disable feature] + +Signed-off-by: Yi Fan Yu yifan.yu@windriver.com + +--- + configure.in | 4 ---- + 1 file changed, 4 deletions(-) + +diff --git a/configure.in b/configure.in +index c669ff2a21..ff1b326eb7 100644 +--- a/configure.in ++++ b/configure.in +@@ -19,10 +19,6 @@ m4_pattern_forbid(^PGAC_)dnl to catch undefined macros + + AC_INIT([PostgreSQL], [9.6.14], [pgsql-bugs@postgresql.org]) + +-m4_if(m4_defn([m4_PACKAGE_VERSION]), [2.69], [], [m4_fatal([Autoconf version 2.69 is required. +-Untested combinations of 'autoconf' and PostgreSQL versions are not +-recommended. You can remove the check from 'configure.in' but it is then +-your responsibility whether the result works or not.])]) + AC_COPYRIGHT([Copyright (c) 1996-2016, PostgreSQL Global Development Group]) + AC_CONFIG_SRCDIR([src/backend/access/common/heaptuple.c]) + AC_CONFIG_AUX_DIR(config) diff --git a/recipes-dbs/postgresql/postgresql-morello.inc b/recipes-dbs/postgresql/postgresql-morello.inc new file mode 100644 index 0000000..e4bccbe --- /dev/null +++ b/recipes-dbs/postgresql/postgresql-morello.inc @@ -0,0 +1,400 @@ +inherit autotools pkgconfig perlnative python3native python3targetconfig +inherit useradd update-rc.d systemd gettext cpan-base pure-cap-kheaders purecap-sysroot purecap-useradd +inherit perl-hacks + +MORELLO_SRC = "meta-openembedded/meta-oe/recipes-dbs/postgresql/postgresql_14.5" +MORELLO_SRC += "meta-cloud-services/meta-openstack/recipes-dbs/postgresql/*" + +SUMMARY = "PostgreSQL is a powerful, open source relational database system" +DESCRIPTION = "\ + PostgreSQL is an advanced Object-Relational database management system \ + (DBMS) that supports almost all SQL constructs (including \ + transactions, subselects and user-defined types and functions). The \ + postgresql package includes the client programs and libraries that \ + you'll need to access a PostgreSQL DBMS server. These PostgreSQL \ + client programs are programs that directly manipulate the internal \ + structure of PostgreSQL databases on a PostgreSQL server. These client \ + programs can be located on the same machine with the PostgreSQL \ + server, or may be on a remote machine which accesses a PostgreSQL \ + server over a network connection. This package contains the docs \ + in HTML for the whole package, as well as command-line utilities for \ + managing PostgreSQL databases on a PostgreSQL server. \ + \ + If you want to manipulate a PostgreSQL database on a local or remote \ + PostgreSQL server, you need this package. You also need to install \ + this package if you're installing the postgresql-server package. \ + \ +" +HOMEPAGE = "http://www.postgresql.com" +LICENSE = "0BSD" + +DEPENDS += "readline-morello zlib-morello openssl-morello util-linux-morello tcl-morello" +DEPENDS += "libnsl2 tzcode-native" + +TOOLCHAIN = "${MORELLO_TOOLCHAIN}" + +BPN_POSTGRESQL="postgresql" + +ARM_INSTRUCTION_SET = "arm" + +# used for hacking +MORELLO = "-morello" + +FILESEXTRAPATHS:prepend := "${THISDIR}/files:${THISDIR}/postgresql:" + +S = "${WORKDIR}/postgresql-${PV}" + +LEAD_SONAME = "libpq.so" + +# LDFLAGS for shared libraries +export LDFLAGS_SL = "${LDFLAGS}" + +CFLAGS += "-I${STAGING_DIR_HOST}/usr/include/${PYTHON_DIR} -I${STAGING_INCDIR}/tcl8.6 -Wno-unused-function -pipe -msoft-float -integrated-as -O0 -g" +CLAGS += "-Wno-deprecated-declarations -Wno-compound-token-split-by-macro" +LDFLAGS += "-pthread" + +SYSTEMD_SERVICE:${PN} = "postgresql.service" +SYSTEMD_AUTO_ENABLE:${PN} = "disable" + +pkg_postinst:${PN} () { + if ${@bb.utils.contains('DISTRO_FEATURES', 'systemd sysvinit', 'true', 'false', d)}; then + if [ -n "$D" ]; then + OPTS="--root=$D" + fi + systemctl $OPTS mask postgresql-server.service + fi +} + +PACKAGECONFIG ??= " \ + ${@bb.utils.filter('DISTRO_FEATURES', 'pam systemd', d)} \ + openssl uuid tcl perl zlib \ +" + +EXTRA_OECONF += "--enable-thread-safety \ + --datadir=${datadir}/${BPN_POSTGRESQL} \ + --sysconfdir=${sysconfdir}/${BPN_POSTGRESQL} \ + --enable-debug \ + --without-systemd \ +" + +CFLAGS += "-DUSE_ASSERT_CHECKING" + +PACKAGES_DYNAMIC += "^${PN}-plperl \ + ^${PN}-pltcl \ + ^${PN}-plpython \ +" + +python populate_packages:prepend() { + + def fill_more(name): + if name is None or name.strip() == "": + return + + fpack=d.getVar('PACKAGES', False) or "" + fpack="${PN}-" + name + " " + fpack + d.setVar('PACKAGES', fpack) + + conf=(d.getVar('PACKAGECONFIG') or "").split() + pack=d.getVar('PACKAGES', False) or "" + bb.debug(1, "PACKAGECONFIG=%s" % conf) + bb.debug(1, "PACKAGES1=%s" % pack ) + + if "perl" in conf : + fill_more("plperl") + + if "tcl" in conf: + fill_more("pltcl") + + if "python" in conf: + fill_more("plpython") + + pack=d.getVar('PACKAGES') or "" + bb.debug(1, "PACKAGES2=%s" % pack) + +} + +# This will make native perl use target settings (for include dirs etc.) +# there is no perl in purecap, so yet another hack: hardcode the version and target +export PERLCONFIGTARGET = "${@is_target(d)}" +export PERL_ARCHLIB = "${STAGING_LIBDIR_HACK}${PERL_OWN_DIR}/perl5/${@get_perl_version(d)}/${@get_perl_arch(d)}" + +do_configure() { + + # do_configure + autotools_do_configure + + # do_configure:append + # workaround perl package related bugs + sed -i -e "s:-L/usr/local/lib:-L=/usr/local/lib:g" \ + ${B}/src/Makefile.global + LIBPNA="${STAGING_LIBDIR_NATIVE}/perl-native" + LIBNA="${STAGING_LIBDIR_NATIVE}" + BLIBNA="${STAGING_BASE_LIBDIR_NATIVE}" + sed -i -e "/^perl_archlibexp/s:${LIBPNA}:${STAGING_LIBDIR_HACK}:g" \ + ${B}/src/Makefile.global + sed -i -e "/^perl_privlibexp/s:/usr/lib:${STAGING_LIBDIR_HACK}:g" \ + ${B}/src/Makefile.global + # remove the rpath, replace with correct lib path + sed -i \ + -e "/^perl_embed_ldflags/s:-Wl,-rpath,${LIBNA}::g" \ + -e "/^perl_embed_ldflags/s:-Wl,-rpath,${BLIBNA}::g" \ + -e "/^perl_embed_ldflags/s:-Wl,-rpath-link,${LIBNA}::g" \ + -e "/^perl_embed_ldflags/s:-Wl,-rpath-link,${BLIBNA}::g" \ + -e "/^perl_embed_ldflags/s:${LIBPNA}:${STAGING_LIBDIR_HACK}:g" \ + -e "/^perl_embed_ldflags/s:${LIBNA}:${STAGING_LIBDIR_HACK}:g" \ + -e "/^perl_embed_ldflags/s:${BLIBNA}:${STAGING_BASELIBDIR_HACK}:g" \ + -e "/^TCLSH/s:=.*:= /usr/bin/tclsh:g" \ + ${B}/src/Makefile.global + + if ${@bb.utils.contains('PACKAGECONFIG', 'perl', 'true', 'false', d)}; then + # workaround perl package's libperl.so problem + # we are using perlnative so this perl should have same version + perl_version=`perl -v 2>/dev/null | \ + sed -n 's/This is perl.*v[a-z ]*([0-9].[0-9][0-9.]*).*$/\1/p'` + if [ ! -h "${STAGING_LIBDIR_HACK}/perl/$perl_version/CORE/libperl.so" -a \ + ! -h "${STAGING_LIBDIR_HACK}/libperl.so" ]; then + ln -sf ../../../libperl.so.5 \ + ${STAGING_LIBDIR_HACK}/perl/$perl_version/CORE/libperl.so + fi + fi +} + +do_compile:append() { + oe_runmake -C contrib all +} + +# server needs to configure user and group +usernum = "28" +groupnum = "28" +USERADD_PACKAGES = "${PN}" +USERADD_PARAM:${PN} = "-M -g postgres -o -r -d ${localstatedir}/lib/${BPN_POSTGRESQL} \ + -s /bin/sh -c 'PostgreSQL Server' -u ${usernum} postgres" +GROUPADD_PARAM:${PN} = "-g ${groupnum} -o -r postgres" + +INITSCRIPT_PACKAGES = "${PN}" +INITSCRIPT_NAME = "${BPN}-server" +INITSCRIPT_PARAMS = "start 64 . stop 36 0 1 2 3 4 5 6 ." + +do_install() { + + install_dir="${D}" + + install -d ${install_dir} + oe_runmake DESTDIR=${install_dir} install + + # install contrib + oe_runmake DESTDIR=${install_dir} -C contrib install + # install tutorial + install -d -m 0755 ${install_dir}${libdir}/${BPN_POSTGRESQL}/tutorial + install ${B}/src/tutorial/* ${install_dir}${libdir}/${BPN_POSTGRESQL}/tutorial + + # install COPYRIGHT README HISTORY + install -d -m 0755 ${install_dir}${docdir}/${BPN_POSTGRESQL} + for i in ${B}/COPYRIGHT ${B}/README ${B}/HISTORY ${B}/doc/KNOWN_BUGS ${B}/doc/MISSING_FEATURES ${B}/doc/README* ${B}/doc/bug.template; do + [ -f $i ] && install $i ${install_dir}${docdir}/${BPN_POSTGRESQL} + done + + # install dirs and server init + install -d ${install_dir}${sysconfdir}/init.d + install -m 0755 ${WORKDIR}/postgresql-morello.init ${install_dir}${sysconfdir}/init.d/${BPN}-server + sed -i -e "s/^PGVERSION=.*$/PGVERSION=${PVBASE}/g" ${install_dir}${sysconfdir}/init.d/${BPN}-server + install -m 0755 ${WORKDIR}/postgresql-setup ${install_dir}${bindir}/${BPN}-setup + + install -d -m 700 ${install_dir}${localstatedir}/lib/${BPN_POSTGRESQL}/data + install -d -m 700 ${install_dir}${localstatedir}/lib/${BPN_POSTGRESQL}/backups + install -m 644 ${WORKDIR}/postgresql-profile ${install_dir}${localstatedir}/lib/${BPN_POSTGRESQL}/.profile + + chown -R postgres:postgres ${install_dir}${localstatedir}/lib/${BPN_POSTGRESQL} + + # multiple server config directory + install -d -m 700 ${install_dir}${sysconfdir}/default/${BPN_POSTGRESQL} + + if ${@bb.utils.contains('DISTRO_FEATURES', 'pam', 'true', 'false', d)}; then + install -d ${install_dir}${sysconfdir}/pam.d + install -m 644 ${WORKDIR}/postgresql.pam ${install_dir}${sysconfdir}/pam.d/postgresql + fi + + # Remove the build path + if [ -f ${install_dir}${libdir}/${BPN_POSTGRESQL}/pgxs/src/Makefile.global ]; then + sed -i -e 's#${RECIPE_SYSROOT}##g' \ + -e 's#${RECIPE_SYSROOT_NATIVE}##g' \ + -e 's#${WORKDIR}##g' \ + -e 's#${TMPDIR}##g' \ + ${install_dir}${libdir}/${BPN_POSTGRESQL}/pgxs/src/Makefile.global + fi + + install -d ${install_dir}${libdir}/${BPN_POSTGRESQL}/pgxs/src/test/regress + cp -rf ${S}/src/test/regress ${install_dir}${libdir}/${BPN_POSTGRESQL}/pgxs/src/test +} + +do_install:append() { + # we need a fake pg_config as some lib configs will try to run pg_config... + # probably could do with a native flavour + + install -d ${D}${bindir}/pgconfig + install -m 755 ${WORKDIR}/pg_config ${D}${bindir}/pgconfig/pg_config +} + +SSTATE_SCAN_FILES += "Makefile.global" +SSTATE_SCAN_FILES:remove = "*_config" + +PACKAGES =+ "${PN}-client ${PN}-server-dev ${PN}-timezone \ + libecpg${MORELLO}compat libecpg${MORELLO}-compat-dev \ + libecpg${MORELLO} libecpg${MORELLO}-dev libecpg${MORELLO}-staticdev libecpg${MORELLO}-doc \ + libpq${MORELLO} libpq${MORELLO}-dev libpq${MORELLO}-staticdev \ + libpgtypes${MORELLO} libpgtypes${MORELLO}-staticdev libpgtypes${MORELLO}-dev \ + ${PN}-contrib \ +" + +RPROVIDES:${PN}-dbg += "libecpg${MORELLO}-compat-dbg \ + libecpg${MORELLO}-dbg \ + libpq${MORELLO}-dbg \ + libpgtypes${MORELLO}-dbg \ + ${PN}-contrib-dbg \ + ${PN}-pltcl-dbg \ + ${PN}-plpython-dbg \ + ${PN}-plperl-dbg \ + " + +FILES:${PN} += "${sysconfdir}/${BPN_POSTGRESQL} ${libdir} ${bindir}/pg_config_fake \ + ${sysconfdir}/init.d/${BPN}-server \ + ${localstatedir}/lib/${BPN_POSTGRESQL}/data ${localstatedir}/lib/${BPN_POSTGRESQL}/backups \ + ${localstatedir}/lib/${BPN_POSTGRESQL}/.profile ${sysconfdir}/default/${BPN_POSTGRESQL} \ + ${libdir}/${BPN_POSTGRESQL}/dict_snowball.so ${libdir}/${BPN_POSTGRESQL}/plpgsql.so \ + ${libdir}/${BPN_POSTGRESQL}/euc2004_sjis2004.so \ + ${libdir}/${BPN_POSTGRESQL}/libpqwalreceiver.so \ + ${libdir}/${BPN_POSTGRESQL}/*_and_*.so \ + ${@'${sysconfdir}/pam.d/postgresql-morello' \ + if 'pam' == d.getVar('enable_pam') \ + else ''} \ + ${datadir} \ +" + +FILES:${PN}-client = "${bindir}/clusterdb \ + ${bindir}/createdb \ + ${bindir}/createuser \ + ${bindir}/dropdb \ + ${bindir}/dropuser \ + ${bindir}/pg_dump \ + ${bindir}/pg_dumpall \ + ${bindir}/pg_restore \ + ${bindir}/psql \ + ${bindir}/reindexdb \ + ${bindir}/vacuumdb \ + ${bindir}/vacuumlo \ + ${datadir}/${BPN_POSTGRESQL}/psqlrc.sample \ +" +FILES:${PN}-client-doc = "${mandir}/man1/clusterdb.* \ + ${mandir}/man1/createdb.* ${mandir}/man1/createlang.* \ + ${mandir}/man1/createuser.* ${mandir}/man1/dropdb.* \ + ${mandir}/man1/droplang.* ${mandir}/man1/dropuser.* \ + ${mandir}/man1/pg_dump.* ${mandir}/man1/pg_dumpall.* \ + ${mandir}/man1/pg_restore.* ${mandir}/man1/psql.* \ + ${mandir}/man1/reindexdb.* ${mandir}/man1/vacuumdb.* \ + ${mandir}/man7/* \ +" +FILES:${PN}-doc += "${docdir}/${BPN_POSTGRESQL}/html ${libdir}/${BPN_POSTGRESQL}/tutorial/ \ + ${mandir}/man1/initdb.* ${mandir}/man1/pg_controldata.* \ + ${mandir}/man1/pg_ctl.* ${mandir}/man1/pg_resetxlog.* \ + ${mandir}/man1/postgres.* ${mandir}/man1/postmaster.* \ + ${mandir} ${docdir} \ +" +FILES:${PN}-timezone = "${datadir}/${BPN_POSTGRESQL}/timezone \ + ${datadir}/${BPN_POSTGRESQL}/timezonesets \ +" + +FILES:${PN}-server-dev = "${includedir}/${BPN_POSTGRESQL}/server \ + ${libdir}/${BPN_POSTGRESQL}/pgxs \ +" + +FILES:libecpg${MORELLO} = "${libdir}/libecpg*${SOLIBS}" +FILES:libecpg${MORELLO}-dev = "${libdir}/libecpg*${SOLIBSDEV} \ + ${libdir}/libpgtypes*${SOLIBSDEV} \ + ${includedir}/ecpg*.h ${includedir}/${BPN_POSTGRESQL}/ecpg*.h \ + ${includedir}/pgtypes*.h ${includedir}/${BPN_POSTGRESQL}/informix \ + ${includedir}/sql3types.h ${includedir}/sqlca.h \ +" + +FILES:libecpg${MORELLO}-doc = "${mandir}/man1/ecpg.*" +FILES:libecpg${MORELLO}-staticdev = "${libdir}/libecpg*.a" +SECTION:libecpg${MORELLO}-staticdev = "devel" +RDEPENDS:libecpg${MORELLO}-staticdev = "libecpg${MORELLO}-dev (= ${EXTENDPKGV})" + +FILES:libpq${MORELLO} = "${libdir}/libpq*${SOLIBS}" +FILES:libpq${MORELLO}-dev = "${libdir}/libpq*${SOLIBSDEV} \ + ${includedir} \ +" +FILES:libpq${MORELLO}-staticdev = "${libdir}/libpq*.a ${libdir}/libpgport.a" +SECTION:libpq${MORELLO}-staticdev = "devel" +RDEPENDS:libpq${MORELLO}-staticdev = "libpq${MORELLO}-dev (= ${EXTENDPKGV})" + +FILES:libecpg${MORELLO}-compat = "${libdir}/libecpg_compat*${SOLIBS}" +FILES:libecpg${MORELLO}-compat-dev = "${libdir}/libecpg_compat*${SOLIBS}" +FILES:libpgtypes${MORELLO} = "${libdir}/libpgtypes*${SOLIBS}" +FILES:libpgtypes${MORELLO}-staticdev = "${libdir}/libpgtypes*.a" +FILES:libpgtypes${MORELLO}-dev = "${libdir}/libpgtypes*${SOLIBS} ${includedir}/pgtypes*.h" + +FILES:${PN}-contrib = " ${bindir}/oid2name ${bindir}/pg_standby \ + ${S}/contrib/spi/*.example \ + ${libdir}/${BPN_POSTGRESQL}/_int.so ${libdir}/${BPN_POSTGRESQL}/adminpack.so \ + ${libdir}/${BPN_POSTGRESQL}/autoinc.so ${libdir}/${BPN_POSTGRESQL}/auto_explain.so \ + ${libdir}/${BPN_POSTGRESQL}/auth_delay.so ${libdir}/${BPN_POSTGRESQL}/btree_gin.so \ + ${libdir}/${BPN_POSTGRESQL}/btree_gist.so ${libdir}/${BPN_POSTGRESQL}/.so \ + ${libdir}/${BPN_POSTGRESQL}/chkpass.so ${libdir}/${BPN_POSTGRESQL}/citext.so \ + ${libdir}/${BPN_POSTGRESQL}/cube.so ${libdir}/${BPN_POSTGRESQL}/dblink.so \ + ${libdir}/${BPN_POSTGRESQL}/dict_int.so ${libdir}/${BPN_POSTGRESQL}/dict_xsyn.so \ + ${libdir}/${BPN_POSTGRESQL}/dummy_seclabel.so ${libdir}/${BPN_POSTGRESQL}/earthdistance.so \ + ${libdir}/${BPN_POSTGRESQL}/file_fdw.so ${libdir}/${BPN_POSTGRESQL}/fuzzystrmatch.so \ + ${libdir}/${BPN_POSTGRESQL}/hstore.so ${libdir}/${BPN_POSTGRESQL}/insert_username.so \ + ${libdir}/${BPN_POSTGRESQL}/isn.so ${libdir}/${BPN_POSTGRESQL}/lo.so \ + ${libdir}/${BPN_POSTGRESQL}/ltree.so ${libdir}/${BPN_POSTGRESQL}/moddatetime.so \ + ${libdir}/${BPN_POSTGRESQL}/pageinspect.so ${libdir}/${BPN_POSTGRESQL}/pg_buffercache.so \ + ${libdir}/${BPN_POSTGRESQL}/pg_freespacemap.so ${libdir}/${BPN_POSTGRESQL}/pg_trgm.so \ + ${libdir}/${BPN_POSTGRESQL}/pgcrypto.so ${libdir}/${BPN_POSTGRESQL}/pgrowlocks.so \ + ${libdir}/${BPN_POSTGRESQL}/pgstattuple.so ${libdir}/${BPN_POSTGRESQL}/pg_stat_statements.so \ + ${libdir}/${BPN_POSTGRESQL}/refint.so ${libdir}/${BPN_POSTGRESQL}/seg.so \ + ${libdir}/${BPN_POSTGRESQL}/sslinfo.so \ + ${libdir}/${BPN_POSTGRESQL}/tablefunc.so \ + ${libdir}/${BPN_POSTGRESQL}/test_parser.so ${libdir}/${BPN_POSTGRESQL}/timetravel.so \ + ${libdir}/${BPN_POSTGRESQL}/uuid-ossp.so \ + ${libdir}/${BPN_POSTGRESQL}/pgxml.so ${libdir}/${BPN_POSTGRESQL}/passwordcheck.so \ + ${libdir}/${BPN_POSTGRESQL}/pg_upgrade_support.so ${libdir}/${BPN_POSTGRESQL}/.so \ + ${libdir}/${BPN_POSTGRESQL}/unaccent.so \ +" +DESCRIPTION:${PN}-contrib = "The postgresql-contrib package contains \ + contributed packages that are included in the PostgreSQL distribution." + +FILES:${PN}-pltcl = "${libdir}/${BPN_POSTGRESQL}/pltcl.so ${bindir}/pltcl_delmod \ + ${binddir}/pltcl_listmod ${bindir}/pltcl_loadmod \ + ${datadir}/${BPN_POSTGRESQL}/unknown.pltcl" +SUMMARY:${PN}-pltcl = "The Tcl procedural language for PostgreSQL" +DESCRIPTION:${PN}-pltcl = "PostgreSQL is an advanced Object-Relational \ + database management system. The postgresql-pltcl package contains the PL/Tcl \ + procedural language for the backend." + +FILES:${PN}-plperl = "${libdir}/${BPN_POSTGRESQL}/plperl.so" +SUMMARY:${PN}-plperl = "The Perl procedural language for PostgreSQL" +DESCRIPTION:${PN}-plperl = "PostgreSQL is an advanced Object-Relational \ + database management system. The postgresql-plperl package contains the \ + PL/Perl procedural language for the backend." + +# In version 8, it will be plpython.so +# In version 9, it might be plpython{2,3}.so depending on python2 or 3 +FILES:${PN}-plpython = "${libdir}/${BPN_POSTGRESQL}/plpython*.so" +SUMMARY:${PN}-plpython = "The Python procedural language for PostgreSQL" +DESCRIPTION:${PN}-plpython = "PostgreSQL is an advanced Object-Relational \ + database management system. The postgresql-plpython package contains \ + the PL/Python procedural language for the backend." + + +FILES:${PN}-dbg += "gdb_debug \ + ${bindir}/pgbench \ + ${libdir}/${BPN_POSTGRESQL}/pgxs/src/test/regress/* \ + " + + +CVE_CHECK_IGNORE += "\ + CVE-2017-8806 \ +" + +SYSROOT_DIRS += "${bindir}/pgconfig" \ No newline at end of file diff --git a/recipes-dbs/postgresql/postgresql-morello_9.6.bb b/recipes-dbs/postgresql/postgresql-morello_9.6.bb new file mode 100644 index 0000000..6ca7934 --- /dev/null +++ b/recipes-dbs/postgresql/postgresql-morello_9.6.bb @@ -0,0 +1,155 @@ +require postgresql-morello.inc + +FILESEXTRAPATHS:prepend := "${THISDIR}/postgresql:${THISDIR}/cheri-patches:" + +PVBASE = "9.6" +LIC_FILES_CHKSUM = "file://COPYRIGHT;md5=87da2b84884860b71f5f24ab37e7da78" + +SRC_URI = "git://github.com/CTSRD-CHERI/postgres;protocol=https;branch=${SRCBRANCH} \ + file://0003-configure.in-bypass-autoconf-2.69-version-check.patch \ + file://postgresql-morello.init \ + file://postgresql-profile \ + file://postgresql.pam \ + file://postgresql-setup \ + file://pg_config \ +" + +SRC_URI += "\ + file://0001-port.h-change-argument-order-to-qsort_r-to-match-pos.patch \ + file://0002-qsort-change-defines-from-freebsd-to-cheri.patch \ +" + +SRC_URI += " \ + file://postgresql-init \ + file://postgresql-init.service \ + file://postgresql-morello.service \ + " + +SRC_URI += "\ + file://postgres-test \ + file://postgres-bench \ + file://test-schedule \ + " + +SRC_URI[sha256sum] = "d4f72cb5fb857c9a9f75ec8cf091a1771272802f2178f0b2e65b7b6ff64f4a30" + +SRCBRANCH = "96-cheri" +SRCREV = "e94e514cac6a8ae2277b3e44970c734c9a066f34" + +S = "${WORKDIR}/git" + +CFLAGS:remove = "-O2" + +SYSTEMD_AUTO_ENABLE:${PN} = "enable" + +DB_DATADIR = "/var/lib/postgresql/data" + +PACKAGECONFIG[tcl] = "--with-tcl --with-tclconfig=${STAGING_BINDIR_CROSS},--without-tcl,tcl-morello tcl-native," +# PACKAGECONFIG[perl] = "--with-perl,--without-perl,perl,perl" +# PACKAGECONFIG[python] = "--with-python,--without-python,python3,python3" +# PACKAGECONFIG[gssapi] = "--with-gssapi,--without-gssapi,krb5" +# PACKAGECONFIG[pam] = "--with-pam,--without-pam,libpam" +PACKAGECONFIG[ldap] = "--with-ldap,--without-ldap,openldap-morello" +#PACKAGECONFIG[systemd] = "--with-systemd,--without-systemd,systemd systemd-systemctl-native" +#PACKAGECONFIG[uuid] = "--with-uuid=e2fs,--without-uuid,util-linux" +#PACKAGECONFIG[libxml] = "--with-libxml,--without-libxml,libxml2,libxml2" +# PACKAGECONFIG[libxslt] = "--with-libxslt,--without-libxslt,libxslt" +PACKAGECONFIG[zlib] = "--with-zlib,--without-zlib,zlib-morello" +PACKAGECONFIG[openssl] = "--with-openssl,--without-openssl,openssl-morello," + +export PRINTF_SIZE_T_SUPPORT="yes" + +do_install:append() { + + install_dir="${D}" + + D_DEST_DIR=${install_dir}${sysconfdir}/${BPN_POSTGRESQL} + + install -d ${D_DEST_DIR} + install -m 0755 ${WORKDIR}/postgresql-init ${D_DEST_DIR}/postgresql-init + + sed -e "s:%DB_DATADIR%:${DB_DATADIR}:g" -i ${D_DEST_DIR}/postgresql-init + sed -e "s:%PGINSTALLDIR%:${prefix}:g" -i ${D_DEST_DIR}/postgresql-init + sed -e "s:%BINDIR%:${bindir}:g" -i ${D_DEST_DIR}/postgresql-init + sed -e "s:%SYSCONFDIR%:${sysconfdir}:g" -i ${D_DEST_DIR}/postgresql-init + + install -d ${D}${systemd_unitdir}/system/ + + PG_INIT_SERVICE_FILE=${D}${systemd_unitdir}/system/postgresql-init.service + install -m 644 ${WORKDIR}/postgresql-init.service ${PG_INIT_SERVICE_FILE} + + sed -e "s:%PGINSTALLDIR%:${prefix}:g" -i ${PG_INIT_SERVICE_FILE} + + sed -e "s:%SYSCONFIGDIR%:${sysconfdir}:g" -i ${PG_INIT_SERVICE_FILE} + sed -e "s:%SYSCONFIGDIR%:${sysconfdir}:g" -i ${PG_INIT_SERVICE_FILE} + + sed -e "s:%DB_USER%:${DB_USER}:g" -i ${PG_INIT_SERVICE_FILE} + sed -e "s:%DB_PASSWORD%:${DB_PASSWORD}:g" -i ${PG_INIT_SERVICE_FILE} + + PG_SERVICE_FILE=${D}${systemd_unitdir}/system/postgresql.service + install -m 644 ${WORKDIR}/postgresql-morello.service ${PG_SERVICE_FILE} + + sed -e 's,%BINDIR%,${bindir},g' -i ${PG_SERVICE_FILE} + sed -e "s:%PGINSTALLDIR%:${prefix}:g" -i ${PG_SERVICE_FILE} + + # Update PGDATA throughout + files="${install_dir}${localstatedir}/lib/${BPN_POSTGRESQL}/.profile" + files="$files ${D}${systemd_unitdir}/system/postgresql.service" + files="$files ${install_dir}${bindir}/${BPN}-setup" + files="$files ${install_dir}${sysconfdir}/init.d/${BPN}-server" + for f in $files + do + sed -e "s:(PGDATA=).*$:\1${DB_DATADIR}:g" -i $f + done + + # Ensure DB is initialize before we attempt to start the service + FILE=${D}${systemd_unitdir}/system/postgresql.service + sed -e '/ExecStart=.*/i ExecStartPre=${sysconfdir}/${BPN_POSTGRESQL}/postgresql-init initdb' -i $FILE + sed -e '/ExecStartPre=.*/i PermissionsStartOnly=true' -i $FILE + + # Install test scripts + BENCH_SCRIPT=${D}/postgres-bench.sh + install -m 0755 ${WORKDIR}/postgres-bench ${BENCH_SCRIPT} + + sed -e "s:%BINDIR%:${bindir}:g" -i ${BENCH_SCRIPT} + sed -e "s:%LIBDIR%:${libdir}:g" -i ${BENCH_SCRIPT} + + TEST_SCRIPT=${D}/postgres-test.sh + install -m 0755 ${WORKDIR}/postgres-test ${TEST_SCRIPT} + + sed -e "s:%BINDIR%:${bindir}:g" -i ${TEST_SCRIPT} + sed -e "s:%LIBDIR%:${libdir}:g" -i ${TEST_SCRIPT} + + install -d ${install_dir}${libdir}/${BPN_POSTGRESQL}/pgxs/src/test/regress + install -m 644 ${WORKDIR}/test-schedule ${install_dir}${libdir}/${BPN_POSTGRESQL}/pgxs/src/test/regress/test_schedule +} + +do_install:append () { + + install -d "${D}${libdir}" + cp ${B}/src/test/regress/*.so ${D}${libdir} +} + +do_install:append() { + ${OBJDUMP_COMMAND} ${D}${bindir}/pg_ctl > ${D}${PURECAP_DEBUGDIR}/pgctl.dump + ${READELF_COMMAND} ${D}${bindir}/pg_ctl > ${D}${PURECAP_DEBUGDIR}/pgctl.readelf + ${OBJDUMP_COMMAND} ${D}${bindir}/postgres > ${D}${PURECAP_DEBUGDIR}/postgres.dump + ${READELF_COMMAND} ${D}${bindir}/postgres > ${D}${PURECAP_DEBUGDIR}/postgres.readelf +} + +PACKAGES += " ${PN}-setup" + +SYSTEMD_PACKAGES += "${PN}-setup" +SYSTEMD_SERVICE:${PN}-setup = "postgresql-init.service" + +FILES:${PN}-setup = " \ + ${systemd_unitdir}/system \ +" + +FILES:${PN}-dbg += " \ + postgres-test.sh \ + postgres-bench.sh \ + ${libdir}/${BPN_POSTGRESQL}/pgxs/src/test/regress/test-schedule \ +" + +FILES:${PN}-gdb-debug += "/gdb_debug" \ No newline at end of file diff --git a/recipes-dbs/postgresql/postgresql/pg_config b/recipes-dbs/postgresql/postgresql/pg_config new file mode 100755 index 0000000..1c147d2 --- /dev/null +++ b/recipes-dbs/postgresql/postgresql/pg_config @@ -0,0 +1,15 @@ +#!/bin/bash + +if [[ "${1}" == "--includedir" ]]; then + + echo "${STAGING_DIR_TARGET}${includedir}" + +elif [[ "${1}" == "--libdir" ]]; then + + echo "${STAGING_DIR_TARGET}${libdir}" + +elif [[ "${1}" == "--version" ]]; then + + echo "9.6" + +fi \ No newline at end of file diff --git a/recipes-dbs/postgresql/postgresql/postgres-bench b/recipes-dbs/postgresql/postgresql/postgres-bench new file mode 100644 index 0000000..d9c1830 --- /dev/null +++ b/recipes-dbs/postgresql/postgresql/postgres-bench @@ -0,0 +1,16 @@ +#!/bin/sh + +if [ -z "$1" ]; then + echo "Usage: ./postgres-bench.sh EXISTING_DB_NAME" + exit 1 +fi + +BINDIR=%BINDIR% +LIBDIR=%LIBDIR% +PURECAPLD="LD_LIBRARY_PATH=${LIBDIR}" +DB_NAME=$1 + +export ${PURECAPLD} + +${BINDIR}/pgbench -i ${DB_NAME} -U postgres +${BINDIR}/pgbench -U postgres -c 2 -T 180 ${DB_NAME} 2>&1 | tee /tmp/pgbench-results.txt \ No newline at end of file diff --git a/recipes-dbs/postgresql/postgresql/postgres-test b/recipes-dbs/postgresql/postgresql/postgres-test new file mode 100644 index 0000000..00b57c2 --- /dev/null +++ b/recipes-dbs/postgresql/postgresql/postgres-test @@ -0,0 +1,49 @@ +#!/bin/sh +# stolen from postgresql-cheri + +BINDIR=%BINDIR% +LIBDIR=%LIBDIR% +PURECAPLD="LD_LIBRARY_PATH=${LIBDIR}" +LD_CHERI_LIBRARY_PATH=${LIBDIR} + +POSTGRES_INSTANCE="/tmp/postgres-test-cheri/instance" + +PG_REGRESS=${LIBDIR}/postgresql/pgxs/src/test/regress/pg_regress + +SCHEDULE_NAME=${SCHEDULE_NAME:-serial_schedule} + +OUTPUT_DIR="/tmp/pg_test" + +rm -rf $OUTPUT_DIR + +mkdir -p $OUTPUT_DIR +mkdir -p $OUTPUT_DIR/log +mkdir -p $OUTPUT_DIR/sql +mkdir -p $OUTPUT_DIR/expected +mkdir -p $OUTPUT_DIR/results +mkdir -p $OUTPUT_DIR/testtablespace +mkdir -p $POSTGRES_INSTANCE + +cd $OUTPUT_DIR + +if "${PG_REGRESS}" "--inputdir=${LIBDIR}/postgresql/pgxs/src/test/regress" "--bindir=${BINDIR}" "--dlpath=${LIBDIR}" "--schedule=${LIBDIR}/postgresql/pgxs/src/test/regress/${SCHEDULE_NAME}" "--outputdir=$OUTPUT_DIR" "--temp-instance=$POSTGRES_INSTANCE" "$@" +then + echo "TESTS SUCCCEEDED" +else + if [ "$?" = 1 ]; then + echo "TESTS UNSTABLE" + echo "CHECKING FOR ASSERTION FAILURES:" + grep TRAP "$OUTPUT_DIR/log/postmaster.log" || true + exit 0 + else + echo "Got test failures, reading initdb log: $OUTPUT_DIR/log/initdb.log" + cat "$OUTPUT_DIR/log/initdb.log" + false + fi +fi + +sudo cp /tmp/pg_test/regression.diffs regression.diffs +sudo cp /tmp/pg_test/regression.out regression.out +sudo cp -rf /tmp/pg_test/expected . +sudo cp -rf /tmp/pg_test/results . +sudo cp /tmp/pg_test/log/postmaster.log postmaster.log diff --git a/recipes-dbs/postgresql/postgresql/postgresql-init b/recipes-dbs/postgresql/postgresql/postgresql-init new file mode 100644 index 0000000..34e77ef --- /dev/null +++ b/recipes-dbs/postgresql/postgresql/postgresql-init @@ -0,0 +1,64 @@ +#!/bin/sh +# set -x + +PN=postgresql-morello +DATA_DIR=%DB_DATADIR% +BIN_DIR=%BINDIR% +SYSCONF_DIR=%SYSCONFDIR% + +# called by postgresql.service.. +initdb(){ + + if [ ! -e $DATA_DIR ]; then + mkdir -p $DATA_DIR + chown postgres $DATA_DIR + fi + + if [ -e $DATA_DIR/PG_VERSION ]; then + # the database has already been initialized, return + exit 0 + fi + + # Create the DB + sudo -u postgres ${BIN_DIR}/initdb -D $DATA_DIR + + if [ $? -ne 0 ]; then + echo "[INFO] postgres: failed to initalise the DB" + exit 1 + fi + + # Allow readers/writers + echo "listen_addresses = '*'" >> $DATA_DIR/postgresql.conf + echo "local root all password" >> $DATA_DIR/pg_hba.conf +} + +if [ "$1" == "initdb" ]; then + initdb + exit 0 +fi + +count=0 +done=0 +while [ $count -le 10 ] && [ $done -eq 0 ]; do + + sudo -u postgres ${BIN_DIR}/psql -c "CREATE ROLE ${DB_USER} WITH SUPERUSER LOGIN PASSWORD '${DB_PASSWORD}'" 2> /dev/null + + if [ $? -ne 0 ]; then + echo "[INFO] postgres: failed to create account for ${DB_USER}, trying again" + systemctl stop postresql + sleep 3 + systemctl start postgresql + sleep 3 + else + echo "[INFO] postgres: created account for ${DB_USER}, continuing .. " + done=1 + fi + count=`expr $count + 1` +done + +if [ $done -eq 0 ]; then + echo "[ERROR] postgres: unable to create admin account" + exit 1 +fi + +ln -s /usr/share/zoneinfo %PGINSTALLDIR%/usr/share/postgresql/timezone || true diff --git a/recipes-dbs/postgresql/postgresql/postgresql-init.service b/recipes-dbs/postgresql/postgresql/postgresql-init.service new file mode 100644 index 0000000..d140c26 --- /dev/null +++ b/recipes-dbs/postgresql/postgresql/postgresql-init.service @@ -0,0 +1,19 @@ +[Unit] +Description=Postgresql setup +Wants=postgresql.service +After=postgresql.service + +[Service] +Type=oneshot + +Environment=DB_USER=%DB_USER% +Environment=DB_PASSWORD=%DB_PASSWORD% + +Environment=PGROOT=%PGINSTALLDIR% + +ExecStart=%SYSCONFIGDIR%/postgresql/postgresql-init +ExecStartPost=/bin/bash -c '/bin/systemctl --no-reload disable postgresql-init.service' +RemainAfterExit=No + +[Install] +WantedBy=multi-user.target diff --git a/recipes-dbs/postgresql/postgresql/postgresql-morello.init b/recipes-dbs/postgresql/postgresql/postgresql-morello.init new file mode 100644 index 0000000..cb9b683 --- /dev/null +++ b/recipes-dbs/postgresql/postgresql/postgresql-morello.init @@ -0,0 +1,193 @@ +#!/bin/sh +# +# postgresql This is the init script for starting up the PostgreSQL +# server. +# +# chkconfig: - 64 36 +# description: PostgreSQL database server. +# processname: postmaster +# pidfile: /var/run/postmaster.PORT.pid + +# This script is slightly unusual in that the name of the daemon (postmaster) +# is not the same as the name of the subsystem (postgresql) + +# PGVERSION is the full package version, e.g., 8.4.0 +# Note: the specfile inserts the correct value during package build +PGVERSION=9.2.4 +# PGMAJORVERSION is major version, e.g., 10 (this should match PG_VERSION) +PGMAJORVERSION=`echo "$PGVERSION" | sed 's/^([0-9]*).*$/\1/'` + +# Source function library. +. /etc/init.d/functions + +# Find the name of the script +NAME=`basename $0` +if [ ${NAME:0:1} = "S" -o ${NAME:0:1} = "K" ] +then + NAME=${NAME:3} +fi + +# For SELinux we need to use 'runuser' not 'su' +if [ -x /sbin/runuser ] +then + SU=runuser +else + SU=su +fi + + +# Set defaults for configuration variables +PGENGINE=/usr/bin +PGPORT=5432 +PGDATA=/var/lib/postgresql/data +PGLOG=/var/lib/postgresql/pgstartup.log +# Value to set as postmaster process's oom_adj +PG_OOM_ADJ=-17 + +# Override defaults from /etc/sysconfig/postgresql if file is present +[ -f /etc/default/postgresql/${NAME} ] && . /etc/default/postgresql/${NAME} + +export PGDATA +export PGPORT + +lockfile="/var/lock/subsys/${NAME}" +pidfile="/var/run/postmaster.${PGPORT}.pid" + +script_result=0 + +start(){ + [ -x "$PGENGINE/postmaster" ] || exit 5 + + PSQL_START=$"Starting ${NAME} service: " + + # Make sure startup-time log file is valid + if [ ! -e "$PGLOG" -a ! -h "$PGLOG" ] + then + touch "$PGLOG" || exit 4 + chown postgres:postgres "$PGLOG" + chmod go-rwx "$PGLOG" + [ -x /sbin/restorecon ] && /sbin/restorecon "$PGLOG" + fi + + # Check for the PGDATA structure + if [ -f "$PGDATA/PG_VERSION" ] && [ -d "$PGDATA/base" ] + then + # Check version of existing PGDATA + if [ x`cat "$PGDATA/PG_VERSION"` != x"$PGMAJORVERSION" ] + then + SYSDOCDIR="(Your System's documentation directory)" + if [ -d "/usr/doc/postgresql-$PGVERSION" ] + then + SYSDOCDIR=/usr/doc + fi + if [ -d "/usr/share/doc/postgresql-$PGVERSION" ] + then + SYSDOCDIR=/usr/share/doc + fi + if [ -d "/usr/doc/packages/postgresql-$PGVERSION" ] + then + SYSDOCDIR=/usr/doc/packages + fi + if [ -d "/usr/share/doc/packages/postgresql-$PGVERSION" ] + then + SYSDOCDIR=/usr/share/doc/packages + fi + echo + echo $"An old version of the database format was found." + echo $"You need to upgrade the data format before using PostgreSQL." + echo $"See $SYSDOCDIR/postgresql-$PGVERSION/README.rpm-dist for more information." + exit 1 + fi + else + # No existing PGDATA! Warn the user to initdb it. + echo + echo "$PGDATA is missing. Use "postgresql-setup initdb" to initialize the cluster first." + echo -n " [FAILED] " + echo + exit 1 + fi + + echo -n "$PSQL_START" + test x"$PG_OOM_ADJ" != x && echo "$PG_OOM_ADJ" > /proc/self/oom_score_adj + $SU -l postgres -c "$PGENGINE/postmaster -p '$PGPORT' -D '$PGDATA' ${PGOPTS} &" >> "$PGLOG" 2>&1 < /dev/null + sleep 2 + pid=`head -n 1 "$PGDATA/postmaster.pid" 2>/dev/null` + if [ "x$pid" != x ] + then + echo -n " [ OK ]" + touch "$lockfile" + echo $pid > "$pidfile" + echo + else + echo -n " [FAILED]" + echo + script_result=1 + fi +} + +stop(){ + echo -n $"Stopping ${NAME} service: " + if [ -e "$lockfile" ] + then + $SU -l postgres -c "$PGENGINE/pg_ctl stop -D '$PGDATA' -s -m fast" > /dev/null 2>&1 < /dev/null + ret=$? + if [ $ret -eq 0 ] + then + echo -n " [ OK ] " + rm -f "$pidfile" + rm -f "$lockfile" + else + echo -n " [FAILED] " + script_result=1 + fi + else + # not running; per LSB standards this is "ok" + echo -n " [ OK ] " + fi + echo +} + +restart(){ + stop + start +} + +condrestart(){ + [ -e "$lockfile" ] && restart || : +} + +reload(){ + $SU -l postgres -c "$PGENGINE/pg_ctl reload -D '$PGDATA' -s" > /dev/null 2>&1 < /dev/null +} + + +# See how we were called. +case "$1" in + start) + start + ;; + stop) + stop + ;; + status) + status postmaster + script_result=$? + ;; + restart) + restart + ;; + condrestart|try-restart) + condrestart + ;; + reload) + reload + ;; + force-reload) + restart + ;; + *) + echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}" + exit 2 +esac + +exit $script_result \ No newline at end of file diff --git a/recipes-dbs/postgresql/postgresql/postgresql-morello.service b/recipes-dbs/postgresql/postgresql/postgresql-morello.service new file mode 100644 index 0000000..bce29b8 --- /dev/null +++ b/recipes-dbs/postgresql/postgresql/postgresql-morello.service @@ -0,0 +1,29 @@ +[Unit] +Description=PostgreSQL database server +After=network.target + +[Service] +Type=forking +User=postgres +Group=postgres + +# Port number for server to listen on +Environment=PGPORT=5432 + +# Location of database directory +Environment=PGDATA=/var/lib/postgresql/data + +Environment=PGROOT=%PGINSTALLDIR% + +# Disable OOM kill on the postmaster +OOMScoreAdjust=-17 + +ExecStart=/bin/bash -c '%BINDIR%/pg_ctl start -D ${PGDATA} -s -o "-p ${PGPORT}" -w -t 300' +ExecStop=/bin/bash -c '%BINDIR%/pg_ctl stop -D ${PGDATA} -s -m fast' +ExecReload=/bin/bash -c '%BINDIR%/pg_ctl reload -D ${PGDATA} -s' + +# Give a reasonable amount of time for the server to start up/shut down +TimeoutSec=300 + +[Install] +WantedBy=multi-user.target diff --git a/recipes-dbs/postgresql/postgresql/postgresql-profile b/recipes-dbs/postgresql/postgresql/postgresql-profile new file mode 100644 index 0000000..1c931f3 --- /dev/null +++ b/recipes-dbs/postgresql/postgresql/postgresql-profile @@ -0,0 +1,4 @@ +[ -f /etc/profile ] && source /etc/profile + +PGDATA=/var/lib/postgresql/data +export PGDATA diff --git a/recipes-dbs/postgresql/postgresql/postgresql-setup b/recipes-dbs/postgresql/postgresql/postgresql-setup new file mode 100644 index 0000000..75bb01e --- /dev/null +++ b/recipes-dbs/postgresql/postgresql/postgresql-setup @@ -0,0 +1,73 @@ +#!/bin/sh +# +# postgresql-setup Initialization operation for PostgreSQL + +# For SELinux we need to use 'runuser' not 'su' +if [ -x /sbin/runuser ] +then + SU=runuser +else + SU=su +fi + +PGENGINE=/usr/bin +PGDATA=/var/lib/postgresql/data +PGLOG=/var/lib/postgresql/pgstartup.log +script_result=0 + +initdb(){ + if [ -f "$PGDATA/PG_VERSION" ] + then + echo -n "Data directory is not empty!" + echo -n " [FAILED] " + echo + script_result=1 + else + echo -n "Initializing database: " + if [ ! -e "$PGDATA" -a ! -h "$PGDATA" ] + then + mkdir -p "$PGDATA" || exit 1 + chown postgres:postgres "$PGDATA" + chmod go-rwx "$PGDATA" + fi + # Clean up SELinux tagging for PGDATA + [ -x /sbin/restorecon ] && /sbin/restorecon "$PGDATA" + + # Make sure the startup-time log file is OK, too + if [ ! -e "$PGLOG" -a ! -h "$PGLOG" ] + then + touch "$PGLOG" || exit 1 + chown postgres:postgres "$PGLOG" + chmod go-rwx "$PGLOG" + [ -x /sbin/restorecon ] && /sbin/restorecon "$PGLOG" + fi + + # Initialize the database + $SU -l postgres -c "$PGENGINE/initdb --pgdata='$PGDATA' --auth='ident'" >> "$PGLOG" 2>&1 < /dev/null + + # Create directory for postmaster log + mkdir "$PGDATA/pg_log" + chown postgres:postgres "$PGDATA/pg_log" + chmod go-rwx "$PGDATA/pg_log" + + if [ -f "$PGDATA/PG_VERSION" ] + then + echo -n " [ OK ] " + else + echo -n " [FAILED] " + script_result=1 + fi + echo + fi +} + +case "$1" in + initdb) + initdb + ;; + *) + echo "Usage: $0 initdb" + exit 2 +esac + +exit $script_result diff --git a/recipes-dbs/postgresql/postgresql/postgresql.pam b/recipes-dbs/postgresql/postgresql/postgresql.pam new file mode 100644 index 0000000..0b6fdc5 --- /dev/null +++ b/recipes-dbs/postgresql/postgresql/postgresql.pam @@ -0,0 +1,4 @@ +#%PAM-1.0 +auth include common-auth +account include common-account +password include common-password diff --git a/recipes-dbs/postgresql/postgresql/test-schedule b/recipes-dbs/postgresql/postgresql/test-schedule new file mode 100644 index 0000000..b8808c9 --- /dev/null +++ b/recipes-dbs/postgresql/postgresql/test-schedule @@ -0,0 +1 @@ +test: type_sanity \ No newline at end of file diff --git a/recipes-dbs/postgresql/postgresql_%.bbappend b/recipes-dbs/postgresql/postgresql_%.bbappend new file mode 100644 index 0000000..66e03de --- /dev/null +++ b/recipes-dbs/postgresql/postgresql_%.bbappend @@ -0,0 +1,7 @@ +FILESEXTRAPATHS:prepend := "${THISDIR}/postgresql:" + +SYSTEMD_AUTO_ENABLE:${PN} = "disable" + +PROVIDES += "libpq" + +FILES:libpq = "${libdir}/libpq*${SOLIBS} ${includedir}"