Subject: [alpine-aports] MongoDB package

From: Filipp Andronov <[email-masked]>
Date: Sat, 16 May 2015 21:43:04 +0700

Hello,

Here is mongodb 3.0.2 package with dependencies:

Status: builds fine
Testing: I've only done smoke tests - install package into a fresh Alpine
docker container, run mongodb and made a few queries.

Things to be complete:
1. Build is only for x86_64, because I have to made a few hacks in code.
Most critical one is __ELF_NATIVE_CLASS
2. No tc-malloc. It doesnt build, so system allocator instead. Im working
on gpreftools package...
3. No heap usage statistics: always returns 0. It is broken in mongodb for
64bit architecture and also musl mallocinfo is not compatible with glibc.
So I just comment out heap reporting code, see comments in APKBUILD
4. Use more system libs, yaml & boost are from the top of my mind. Boost
make compilation fails, but should be easy to fix
5. Enable mongodb tests during build. Im just not sure how that should be
done in Alpine, i.e _where_ in build lifecycle tests should run

Please let me know if packages need to be improved. That is my first alpine
package, so I might break some dev guidelines.

-- 
Thanks and regards,
Philip Andronov
------------------------------------------
SaaS development team leader,
atlassian.com

Mobile: +84 (169) 6310357
Skype: filipp.andronov
Linkedin: http://ru.linkedin.com/pub/philip-andronov/32/369/63a
From 360649d675cbd4f4bbd3063c7be259a29fdac607 Mon Sep 17 00:00:00 2001
From: Philipp Andronov <[email-masked]>
Date: Sat, 16 May 2015 09:31:06 +0000
Subject: [PATCH 1/3] Restore libexecinfo as alternative from uclibc is not
 available anymore new aport: libexecinfo [1.1]

http://www.freshports.org/devel/libexecinfo
A quick-n-dirty BSD licensed clone of the GNU libc backtrace facility.
---
 testing/libexecinfo/20-define-gnu-source.patch | 24 ++++++++++
 testing/libexecinfo/30-linux-makefile.patch    | 44 +++++++++++++++++++
 testing/libexecinfo/APKBUILD                   | 61 ++++++++++++++++++++++++++
 3 files changed, 129 insertions(+)
 create mode 100644 testing/libexecinfo/20-define-gnu-source.patch
 create mode 100644 testing/libexecinfo/30-linux-makefile.patch
 create mode 100644 testing/libexecinfo/APKBUILD

diff --git a/testing/libexecinfo/20-define-gnu-source.patch b/testing/libexecinfo/20-define-gnu-source.patch
new file mode 100644
index 0000000..0ba1fc1
--- /dev/null
+++ b/testing/libexecinfo/20-define-gnu-source.patch
@@ -0,0 +1,24 @@
+--- execinfo.c.orig
++++ execinfo.c
+@@ -26,6 +26,7 @@
+  * $Id: execinfo.c,v 1.3 2004/07/19 05:21:09 sobomax Exp $
+  */
+ 
++#define _GNU_SOURCE
+ #include <sys/types.h>
+ #include <sys/uio.h>
+ #include <dlfcn.h>
+--- stacktraverse.c.orig
++++ stacktraverse.c
+@@ -1,3 +1,4 @@
++#define _GNU_SOURCE
+ #include <stddef.h>
+ 
+ #include "stacktraverse.h"
+--- test.c.orig
++++ test.c
+@@ -1,3 +1,4 @@
++#define _GNU_SOURCE
+ #include <stdio.h>
+ #include <stdlib.h>
+ 
diff --git a/testing/libexecinfo/30-linux-makefile.patch b/testing/libexecinfo/30-linux-makefile.patch
new file mode 100644
index 0000000..3bc8927
--- /dev/null
+++ b/testing/libexecinfo/30-linux-makefile.patch
@@ -0,0 +1,44 @@
+--- Makefile.orig
++++ Makefile
+@@ -23,24 +23,25 @@
+ # SUCH DAMAGE.
+ #
+ # $Id: Makefile,v 1.3 2004/07/19 05:19:55 sobomax Exp $
++#
++# Linux Makefile by Matt Smith <[email-masked]>, 2011/01/04
+ 
+-LIB=	execinfo
++CC=cc
++AR=ar
++EXECINFO_CFLAGS=$(CFLAGS) -O2 -pipe -fno-strict-aliasing -std=gnu99 -fstack-protector -c
++EXECINFO_LDFLAGS=$(LDFLAGS)
+ 
+-SRCS=	stacktraverse.c stacktraverse.h execinfo.c execinfo.h
++all: static dynamic
+ 
+-INCS=	execinfo.h
++static:
++	$(CC) $(EXECINFO_CFLAGS) $(EXECINFO_LDFLAGS) stacktraverse.c
++	$(CC) $(EXECINFO_CFLAGS) $(EXECINFO_LDFLAGS) execinfo.c
++	$(AR) rcs libexecinfo.a stacktraverse.o execinfo.o
+ 
+-SHLIB_MAJOR=	1
+-SHLIB_MINOR=	0
++dynamic:
++	$(CC) -fpic -DPIC $(EXECINFO_CFLAGS) $(EXECINFO_LDFLAGS) stacktraverse.c -o stacktraverse.So
++	$(CC) -fpic -DPIC $(EXECINFO_CFLAGS) $(EXECINFO_LDFLAGS) execinfo.c -o execinfo.So
++	$(CC) -shared -Wl,-soname,libexecinfo.so.1 -o libexecinfo.so.1 stacktraverse.So execinfo.So
+ 
+-NOPROFILE=	yes
+-
+-DPADD=		${LIBM}
+-LDADD=		-lm
+-
+-#WARNS?=	4
+-
+-#stacktraverse.c: gen.py
+-#	./gen.py > stacktraverse.c
+-
+-.include <bsd.lib.mk>
++clean:
++	rm -rf *.o *.So *.a *.so
diff --git a/testing/libexecinfo/APKBUILD b/testing/libexecinfo/APKBUILD
new file mode 100644
index 0000000..cc42b38
--- /dev/null
+++ b/testing/libexecinfo/APKBUILD
@@ -0,0 +1,61 @@
+# Contributor: Philipp Andronov <[email-masked]>
+# Maintainer: Matt Smith <[email-masked]>
+pkgname=libexecinfo
+pkgver=1.1
+pkgrel=0
+pkgdesc="A quick-n-dirty BSD licensed clone of the GNU libc backtrace facility."
+url="http://www.freshports.org/devel/libexecinfo"
+arch="all"
+license="BSD"
+depends=
+makedepends=
+install=
+subpackages=
+source="http://distcache.freebsd.org/local-distfiles/itetcu/$pkgname-$pkgver.tar.bz2
+	saveas-http://svnweb.freebsd.org/ports/head/devel/libexecinfo/files/patch-execinfo.c?revision=340725;content-type=text%2Fplain/10-execinfo.patch
+	20-define-gnu-source.patch
+	30-linux-makefile.patch
+	"
+
+_builddir="$srcdir"/$pkgname-$pkgver
+
+prepare() {
+	cd "$_builddir"
+	patch -p0 -i "$srcdir"/10-execinfo.patch
+	patch -p0 -i "$srcdir"/20-define-gnu-source.patch
+	patch -p0 -i "$srcdir"/30-linux-makefile.patch
+}
+
+build() {
+	cd "$_builddir"
+	export CFLAGS="${CFLAGS} -fno-omit-frame-pointer"
+	make || return 1
+}
+
+package() {
+	cd "$_builddir"
+
+	install -D -m755 "$_builddir"/execinfo.h \
+		"$pkgdir"/usr/include/execinfo.h || return 1
+	install -D -m755 "$_builddir"/stacktraverse.h \
+		"$pkgdir"/usr/include/stacktraverse.h || return 1
+	install -D -m755 "$_builddir"/libexecinfo.a \
+		"$pkgdir"/usr/lib/libexecinfo.a || return 1
+	install -D -m755 "$_builddir"/libexecinfo.so.1 \
+		"$pkgdir"/usr/lib/libexecinfo.so.1 || return 1
+	ln -s /usr/lib/libexecinfo.so.1 \
+		"$pkgdir"/usr/lib/libexecinfo.so || return 1
+}
+
+md5sums="8e9e81c554c1c5d735bc877448e92b91  libexecinfo-1.1.tar.bz2
+594e9f7b86780f2f0c623443dec7ca04  10-execinfo.patch
+8536668cd1813aa689f12d36c470c0a5  20-define-gnu-source.patch
+7dfdae632685a5331ca8317395132066  30-linux-makefile.patch"
+sha256sums="c9a21913e7fdac8ef6b33250b167aa1fc0a7b8a175145e26913a4c19d8a59b1f  libexecinfo-1.1.tar.bz2
+eff078913cf0baeff6e0442ec5c77d1b25d97d13a6d66d25f5576fd25486d752  10-execinfo.patch
+020c73643ac91df9e90532499404fdc10e3ca0d0e6979a8c1610ac340cabe8d6  20-define-gnu-source.patch
+4e310e178c27ecad1ccb7ced06719428ab44bd30163eb7042c5eb2f285f892cb  30-linux-makefile.patch"
+sha512sums="51fea7910ef6873061a25c22434ce4da724e9d8e37616a069ad0a58c0463755be4c6c7da88cd747484c2f3373909d7be4678b32a4bd91b6d9e0f74526094e92c  libexecinfo-1.1.tar.bz2
+a38f75d305518d3432807735456b32b223e89e0d08860e2dfafb5ad3b507de92d4fa60e4bb11978e3dbf20d68be05da42237ced7db625304b49a5288b90be232  10-execinfo.patch
+f335effbbb5425a4b1031fd8a4358f777825a5979f099d01357fab5715065e9f7439f118d155f124b1a15b1e91cd3a4e9a20793806d121f605775f148aea0102  20-define-gnu-source.patch
+3596aef8c6d0593afd063c2295ede3473d33afa52eafa5258bb48fcd472a36f987196c7de647b2b408a5a02138de9f36253d93f7a9f061e2bb6082fc429acb76  30-linux-makefile.patch"
-- 
2.0.5

From 32b9c39a6824d8a1339ed5d77124dd24f1c6a343 Mon Sep 17 00:00:00 2001
From: Philipp Andronov <[email-masked]>
Date: Sat, 16 May 2015 09:35:06 +0000
Subject: [PATCH 2/3] new aport: wiredtiger [2.6.0]

http://www.wiredtiger.com
High performance, scalable, production quality, NoSQL, Open Source extensible platform for data management
---
 testing/wiredtiger/10-fix-code-generator.patch | 11 ++++++
 testing/wiredtiger/APKBUILD                    | 53 ++++++++++++++++++++++++++
 2 files changed, 64 insertions(+)
 create mode 100644 testing/wiredtiger/10-fix-code-generator.patch
 create mode 100644 testing/wiredtiger/APKBUILD

diff --git a/testing/wiredtiger/10-fix-code-generator.patch b/testing/wiredtiger/10-fix-code-generator.patch
new file mode 100644
index 0000000..618106f
--- /dev/null
+++ b/testing/wiredtiger/10-fix-code-generator.patch
@@ -0,0 +1,11 @@
+--- orig/wiredtiger-2.6.0/dist/s_typedef
++++ wiredtiger-2.6.0/dist/s_typedef
+@@ -21,7 +21,7 @@
+ 	l=`ls ../src/include/*.[hi] ../src/include/*.in |
+ 	    sed -e '/wiredtiger.*/d' -e '/queue.h/d'`
+ 	egrep -h \
+-	    '^[	 ]*(((struct|union)[	 ].*__wt_.*{)|WT_PACKED_STRUCT_BEGIN)' \
++	    '^[	 ]*(((struct|union)[	 ].*__wt_.*\{)|WT_PACKED_STRUCT_BEGIN)' \
+ 	    $l |
+ 	    sed -e 's/WT_PACKED_STRUCT_BEGIN(\(.*\))/struct \1 {/' \
+ 	        -e 's/WT_COMPILER_TYPE_ALIGN(.*)[ ]*//' \
diff --git a/testing/wiredtiger/APKBUILD b/testing/wiredtiger/APKBUILD
new file mode 100644
index 0000000..408a0ed
--- /dev/null
+++ b/testing/wiredtiger/APKBUILD
@@ -0,0 +1,53 @@
+# Contributor: Philipp Andronov <[email-masked]>
+# Maintainer: Philipp Andronov <[email-masked]>
+
+pkgname=wiredtiger
+pkgver=2.6.0
+pkgrel=0
+pkgdesc="High performance, scalable, production quality, NoSQL, Open Source extensible platform for data management"
+url="http://www.wiredtiger.com"
+arch="x86_64"
+license="custom"
+
+depends=""
+depends_dev="autoconf automake libtool"
+makedepends="$depends_dev"
+
+options="libtool"
+subpackages="$pkgname-doc $pkgname-dev"
+
+install=""
+source="http://source.wiredtiger.com/releases/wiredtiger-2.6.0.tar.bz2
+	10-fix-code-generator.patch
+	"
+
+_builddir="$srcdir"/$pkgname-$pkgver
+prepare() {
+	local i
+
+	cd "$_builddir"
+	for i in $source; do
+		case $i in
+		*.patch) msg $i; patch -p1 -i "$srcdir"/$i || return 1;;
+		esac
+	done
+}
+
+build() {
+	cd "$_builddir"
+	sh autogen.sh
+	./configure --prefix=/usr || exit 1
+	make || exit 1
+}
+
+package() {
+	cd "$_builddir"
+	make DESTDIR="$pkgdir" install
+	install -Dm644 LICENSE "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
+}
+md5sums="a238faf51904c703ea9dbe6360d0d31e  wiredtiger-2.6.0.tar.bz2
+a2d708fbb72b47aa94fb424e4b679484  10-fix-code-generator.patch"
+sha256sums="83dff9bbfa81104884647781d2dbe1457409a5d5b0de71af0fc5eb3864abaf70  wiredtiger-2.6.0.tar.bz2
+65fc3b0885ff2e2ed30b7eb9917671fd7acdbb63978d565e17d328c2da214326  10-fix-code-generator.patch"
+sha512sums="64c834a4ed07d32fe980baf2b79223b75ca4195a8dbac657efebb027faa93f9e7eef150e1d87f1aaa7a83942272ac8640edab5f494fc84c43da81cd1cda43332  wiredtiger-2.6.0.tar.bz2
+a24360c18a8dd677a1942fc66ecdfdb8bc514af6de3e19be822293fdc83c051c43f3270f91eaa4524f30b5bc82c6ecad5162ce5b3f5ff470bab4e1a5d9eb79ec  10-fix-code-generator.patch"
-- 
2.0.5

From ca8855a40e5fdf87217a0af0cef4d755e8086566 Mon Sep 17 00:00:00 2001
From: Philipp Andronov <[email-masked]>
Date: Sat, 16 May 2015 10:57:39 +0000
Subject: [PATCH 3/3] new aport: mongodb [3.0.2]

http://www.mongodb.org
A high-performance, open source, schema-free document-oriented database
---
 testing/mongodb/10-fix-poll-h.patch           |  11 +++
 testing/mongodb/20-fix-libc-version.patch     |  37 +++++++++
 testing/mongodb/30-fix-backtrace.patch        |  24 ++++++
 testing/mongodb/40-fix-elf-native-class.patch |  12 +++
 testing/mongodb/APKBUILD                      | 112 ++++++++++++++++++++++++++
 testing/mongodb/mongodb.confd                 |  14 ++++
 testing/mongodb/mongodb.initd                 |  40 +++++++++
 testing/mongodb/mongodb.logrotate             |  13 +++
 testing/mongodb/mongodb.post-install          |   5 ++
 testing/mongodb/mongodb.pre-deinstall         |   4 +
 testing/mongodb/mongodb.pre-install           |   4 +
 testing/mongodb/mongos.confd                  |  16 ++++
 testing/mongodb/mongos.initd                  |  45 +++++++++++
 13 files changed, 337 insertions(+)
 create mode 100644 testing/mongodb/10-fix-poll-h.patch
 create mode 100644 testing/mongodb/20-fix-libc-version.patch
 create mode 100644 testing/mongodb/30-fix-backtrace.patch
 create mode 100644 testing/mongodb/40-fix-elf-native-class.patch
 create mode 100644 testing/mongodb/APKBUILD
 create mode 100644 testing/mongodb/mongodb.confd
 create mode 100644 testing/mongodb/mongodb.initd
 create mode 100644 testing/mongodb/mongodb.logrotate
 create mode 100644 testing/mongodb/mongodb.post-install
 create mode 100644 testing/mongodb/mongodb.pre-deinstall
 create mode 100644 testing/mongodb/mongodb.pre-install
 create mode 100644 testing/mongodb/mongos.confd
 create mode 100644 testing/mongodb/mongos.initd

diff --git a/testing/mongodb/10-fix-poll-h.patch b/testing/mongodb/10-fix-poll-h.patch
new file mode 100644
index 0000000..0ef14f4
--- /dev/null
+++ b/testing/mongodb/10-fix-poll-h.patch
@@ -0,0 +1,11 @@
+--- orig/mongodb-src-r3.0.2/src/mongo/util/net/socket_poll.h
++++ mongodb-src-r3.0.2/src/mongo/util/net/socket_poll.h
+@@ -29,7 +29,7 @@
+ #pragma once
+ 
+ #ifndef _WIN32
+-# include <sys/poll.h>
++# include <poll.h>
+ #else
+ # if defined(NTDDI_VERSION) && ( !defined(NTDDI_VISTA) || ( NTDDI_VERSION < NTDDI_VISTA ) )
+     // These are only defined in winsock2.h on newer windows but we need them everywhere.
diff --git a/testing/mongodb/20-fix-libc-version.patch b/testing/mongodb/20-fix-libc-version.patch
new file mode 100644
index 0000000..bf1aba0
--- /dev/null
+++ b/testing/mongodb/20-fix-libc-version.patch
@@ -0,0 +1,37 @@
+--- orig/mongodb-src-r3.0.2/src/mongo/util/processinfo_linux2.cpp
++++ mongodb-src-r3.0.2/src/mongo/util/processinfo_linux2.cpp
+@@ -34,7 +34,11 @@
+ #include <stdio.h>
+ #include <unistd.h>
+ #include <sys/mman.h>
+-#include <gnu/libc-version.h>
++#ifdef __GLIBC__
++# include <gnu/libc-version.h>
++#else
++# define gnu_get_libc_version(x) "unknown"
++#endif
+ #include <sys/utsname.h>
+ 
+ #include "processinfo.h"
+@@ -314,6 +318,7 @@
+             paths.push_back( "/etc/slackware-version" );
+             paths.push_back( "/etc/centos-release" );
+             paths.push_back( "/etc/os-release" );
++            paths.push_back( "/etc/alpine-release" );
+         
+             for ( i = paths.begin(); i != paths.end(); ++i ) {
+                 // for each path
+@@ -398,8 +403,11 @@
+ 
+     void ProcessInfo::getExtraInfo( BSONObjBuilder& info ) {
+         // [dm] i don't think mallinfo works. (64 bit.)  ??
+-        struct mallinfo malloc_info = mallinfo(); // structure has same name as function that returns it. (see malloc.h)
+-        info.append("heap_usage_bytes", malloc_info.uordblks/*main arena*/ + malloc_info.hblkhd/*mmap blocks*/);
++        //struct mallinfo malloc_info = mallinfo(); // structure has same name as function that returns it. (see malloc.h)
++        // info.append("heap_usage_bytes", malloc_info.uordblks/*main arena*/ + malloc_info.hblkhd/*mmap blocks*/);
++
++	// TODO: Fix for TC_malloc instance().getStats()
++	info.append("heap_usage_bytes", 0);	
+         //docs claim hblkhd is included in uordblks but it isn't
+ 
+         LinuxProc p(_pid);
diff --git a/testing/mongodb/30-fix-backtrace.patch b/testing/mongodb/30-fix-backtrace.patch
new file mode 100644
index 0000000..bf576e2
--- /dev/null
+++ b/testing/mongodb/30-fix-backtrace.patch
@@ -0,0 +1,24 @@
+--- orig/mongodb-src-r3.0.2/src/mongo/platform/backtrace.cpp
++++ mongodb-src-r3.0.2/src/mongo/platform/backtrace.cpp
+@@ -28,6 +28,12 @@
+ #if !defined(_WIN32)
+ #if defined(__sunos__) || !defined(MONGO_HAVE_EXECINFO_BACKTRACE)
+ 
++// dlfcn.h requires _GNU_SOURCE to be defined in order to export
++// Dl_* structures. Issue gonna be addressed in 3.1.3, see SERVER-17199
++#ifndef _GNU_SOURCE
++# define _GNU_SOURCE
++#endif
++
+ #include "mongo/platform/backtrace.h"
+ 
+ #include <boost/smart_ptr/scoped_array.hpp>
+@@ -42,6 +48,8 @@
+ 
+ using std::string;
+ using std::vector;
++
++typedef Dl_info         Dl_info_t;
+ 
+ namespace mongo {
+ namespace pal {
diff --git a/testing/mongodb/40-fix-elf-native-class.patch b/testing/mongodb/40-fix-elf-native-class.patch
new file mode 100644
index 0000000..badb712
--- /dev/null
+++ b/testing/mongodb/40-fix-elf-native-class.patch
@@ -0,0 +1,12 @@
+--- orig/mongodb-src-r3.0.2/src/mongo/util/stacktrace_posix.cpp
++++ mongodb-src-r3.0.2/src/mongo/util/stacktrace_posix.cpp
+@@ -209,6 +209,9 @@
+ #include <elf.h>
+ #include <link.h>
+ 
++// AlpineTODO: Better option??
++#define __ELF_NATIVE_CLASS 64
++
+ namespace mongo {
+ namespace {
+ 
diff --git a/testing/mongodb/APKBUILD b/testing/mongodb/APKBUILD
new file mode 100644
index 0000000..316a1fa
--- /dev/null
+++ b/testing/mongodb/APKBUILD
@@ -0,0 +1,112 @@
+# Contributor:
+# Maintainer:
+pkgname=mongodb
+pkgver=3.0.2
+pkgrel=0
+pkgdesc='A high-performance, open source, schema-free document-oriented database'
+url='http://www.mongodb.org'
+arch='x86_64'
+license='AGPL3'
+
+pkgusers="mongodb"
+depends="wiredtiger libexecinfo pcre"
+depends_dev="scons openssl-dev libexecinfo pcre-dev wiredtiger-dev"
+makedepends="$depends_dev"
+
+install="$pkgname.pre-install $pkgname.post-install $pkgname.pre-deinstall"
+source="http://downloads.mongodb.org/src/mongodb-src-r${pkgver}.tar.gz
+	10-fix-poll-h.patch
+	20-fix-libc-version.patch
+	30-fix-backtrace.patch
+	40-fix-elf-native-class.patch
+
+        mongodb.confd
+        mongodb.initd
+        mongodb.logrotate
+        mongos.confd
+        mongos.initd
+	"
+#
+# 1. Force 64bits because of 40-fix-elf-native-class.patch
+# 2. Use system allocator as tc-malloc doesn't build
+# 2. Use as much system libs as possible, boost doesn't compile foe example
+#
+# TODO: proper elf-netive-class fix
+# TODO: check if there are more libs could be replaced by system counterparts (see libpcap does't use, for example)
+# TODO: proper fix for heap usage 
+# Right now code patched to always return 0 for heap usage statistics. That is necessary because musl malloc info
+# doesn't compatible with glibc and breaks build. It is _possible_ to patch code to return 0
+# because on 64bit platform statistics is broken and returns wrong numbers, see SERVER-9168 mongo bug.
+#
+# There is a way to return propper value when tc-malloc used, but it doesn't compile for libmusl. Work is in progress,
+# contribution strongly welcome :D
+#
+_builddir="$srcdir"/$pkgname-src-r$pkgver
+_buildops="--variant-dir=build --64 --allocator=system --use-system-pcre --use-system-wiredtiger --extralib=libexecinfo"
+
+prepare() {
+        cd "$_builddir"
+
+        local i
+        for i in $source; do
+                case $i in
+                *.patch) msg $i; patch -p1 -i "$srcdir"/$i || return 1;;
+                esac
+        done
+}
+
+build() {
+        cd "$_builddir"
+
+	export SCONSFLAGS="$MAKEFLAGS"
+	scons $_buildops --prefix=$pkgdir/usr core
+}
+
+package() {
+        cd "$_builddir"
+
+	# install mongo targets
+	scons $_buildops --prefix=$pkgdir/usr install
+
+	# install alpine specific files
+	install -dm700 "$pkgdir/var/lib/mongodb"
+	install -dm755 "$pkgdir/var/log/mongodb"
+
+	install -Dm755 "$srcdir/mongodb.initd" "$pkgdir/etc/init.d/mongodb"
+	install -Dm644 "$srcdir/mongodb.confd" "$pkgdir/etc/conf.d/mongodb"
+	install -Dm644 "$srcdir/mongodb.logrotate" "$pkgdir/etc/logrotate.d/mongodb"
+
+	install -Dm755 "$srcdir/mongos.initd" "$pkgdir/etc/init.d/mongos"
+	install -Dm644 "$srcdir/mongos.confd" "$pkgdir/etc/conf.d/mongos"
+}
+
+md5sums="d9fe75f9bc88f34194d823f1d288e4d9  mongodb-src-r3.0.2.tar.gz
+b37ef33a58cbfddd7272b2e3e7c29d18  10-fix-poll-h.patch
+c30067f1f39707371db5897dbd46012f  20-fix-libc-version.patch
+4b27b6c9d0216234ac6a24106b624381  30-fix-backtrace.patch
+04a348397be8ca7471d404056d8a1490  40-fix-elf-native-class.patch
+7d2f94bed7bfacd32fcd52dfd931f077  mongodb.confd
+7bfbe9bd5da9254ab4981c7c3b8ac2bc  mongodb.initd
+49df78833de4cb6e2b9b1ab9da52c3ac  mongodb.logrotate
+33b23ee722f6e5d15eb6d9c2723a346f  mongos.confd
+e2e7904c561364545a48077ba4e84dc3  mongos.initd"
+sha256sums="010522203cdb9bbff52fbd9fe299b67686bb1256e2e55eb78abf35444f668399  mongodb-src-r3.0.2.tar.gz
+7eff5c3f9d0119c19b9144d0933f2cd60db0490e096d4b34c1578101ad06ba33  10-fix-poll-h.patch
+1cc23b97d2c0fcec0c67418c9d3fe842fd121fd7e0596ef4ae77b1b992919631  20-fix-libc-version.patch
+7630b7b55cd2b3e836c441e5ac13b4a111ef3552a9576433a58bd839a1b9259b  30-fix-backtrace.patch
+3a863660113d29728d7a852b3fba73926697b496848f8ccc4d8e73e6614cfdfc  40-fix-elf-native-class.patch
+a4ca29c577428c02cd0b0a8b46756df5f53a05519c9d13c270533cf99b9b819d  mongodb.confd
+ee590071ade60cffdd28ce5bd1e685bcfb49878fb88a21adea0cf30867587ade  mongodb.initd
+76994c32d999def5c925bd7be3f96687b3406f1d67b89aa6a4df8053025b1e01  mongodb.logrotate
+2afd582564623da0e928ca667d37bef467334c82d08b49301f1f6c16ba177767  mongos.confd
+0b7dafba846962f473c406e09d80923e07cf03bb8ba727b3e0408fbef28b23da  mongos.initd"
+sha512sums="ec14529f39459835644dd681a98133c276bb96c676ce3ad91c20dff1ce96aeda3e14f08c05019a72a6f8eaadfed7e176944b42187a273b3e82001946126931d7  mongodb-src-r3.0.2.tar.gz
+73427e35edaf6e6c3b9b2fc16ef4560fc3765084d840bdbec729445fa24ca87394798db16366e0ec320312b3c3b6e1fe58db013e902a2b1413c36b8e66c6bce8  10-fix-poll-h.patch
+b9c9f5dbefe765b3cd1043c259dda027721bf66e75024ec70c0d84fe6a1039065b133c3ea838e01538535d07e308c8629920b11fff51a304d0bf59d04ee3ad9b  20-fix-libc-version.patch
+914c896c7736330834a2a66b60615656b67df5348c65b8ba48478e98044d1fae781082aa510263a7f7a3cb13fa2c019747600250e5b584a12870553cf9fe1f99  30-fix-backtrace.patch
+56db8f43afc94713ac65b174189e2dd903b5e1eff0b65f1bdac159e52ad4de6606c449865d73bd47bffad6a8fc339777e2b11395596e9a476867d94a219c7925  40-fix-elf-native-class.patch
+9bcd870742c31bf25f34188ddc3c414de1103e9860dea9f54eee276b89bc2cf1226abab1749c5cda6a6fb0880e541373754e5e83d63cc7189d4b9c274fd555c3  mongodb.confd
+c0634af4653a3b3ca1a72671460e8ea11cce99b84a48782c5cdcc27453d7ead1e89a61d0ce225febda68913dd04e972b4d6a911060b1e5c4ecfbfc1e991e7b12  mongodb.initd
+8c089b1a11f494e4148fb4646265964c925bf937633a65e395ee1361d42facf837871dd493a9a2e0f480ae0e0829dbd3ed60794c5334e2716332e131fc5c2c51  mongodb.logrotate
+61d8734cef644187eeadc821c89e63a3fbf61860fe2db6e74557b1c6760fe83ba7549cb04f9e3aacea4d8e7e4d81a3b1bc0d5e29715eca33c4761adb17ea9ab7  mongos.confd
+28b54e19efd977721549b95e23d34b070c1af0648d5ae60e2457c86a3c18e5cbb6a56fa147d13a38ac540cf9315ac8f74cddaa3c7baafc56c8c6e5596ebef0c0  mongos.initd"
diff --git a/testing/mongodb/mongodb.confd b/testing/mongodb/mongodb.confd
new file mode 100644
index 0000000..4f76c5a
--- /dev/null
+++ b/testing/mongodb/mongodb.confd
@@ -0,0 +1,14 @@
+# Mongodb essentials
+MONGODB_EXEC="/usr/bin/mongod"
+MONGODB_RUN="/var/run/mongodb"
+MONGODB_DATA="/var/lib/mongodb"
+MONGODB_USER="mongodb"
+
+# Listen to specified IP, comment this to listen to all
+MONGODB_IP="127.0.0.1"
+
+# Listen to specified port
+MONGODB_PORT="27017"
+
+# Set extra options here, such as disabling the admin web server
+MONGODB_OPTIONS="--journal"
diff --git a/testing/mongodb/mongodb.initd b/testing/mongodb/mongodb.initd
new file mode 100644
index 0000000..5b7b77e
--- /dev/null
+++ b/testing/mongodb/mongodb.initd
@@ -0,0 +1,40 @@
+#!/sbin/runscript
+# Copyright 1999-2013 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Header: /var/cvsroot/gentoo-x86/dev-db/mongodb/files/mongodb.initd,v 1.5 2013/01/18 11:19:27 ultrabug Exp $
+
+depend() {
+	need net
+}
+
+start() {
+	checkpath -d -m 0750 -o "${MONGODB_USER}":mongodb "${MONGODB_RUN}"
+
+	# Listen to MONGODB_IP if configured
+	[ -z "${MONGODB_IP}" ] || MONGODB_OPTIONS="--bind_ip ${MONGODB_IP} ${MONGODB_OPTIONS}"
+
+	# Baselayout-1 user should use --chuid instead of --user
+	local USEROPT="--user"
+	if [ ! -f /etc/init.d/sysfs ]; then
+		USEROPT="--chuid"
+	fi
+
+	ebegin "Starting ${SVCNAME}"
+	start-stop-daemon --background --start --make-pidfile \
+		--pidfile ${MONGODB_RUN:-/var/run/mongodb}/${SVCNAME}.pid \
+		${USEROPT} ${MONGODB_USER:-mongodb} \
+		--exec ${MONGODB_EXEC:-/usr/bin/mongod} \
+		-- \
+		--port ${MONGODB_PORT:-27017} \
+		--dbpath ${MONGODB_DATA:-/var/lib/mongodb} \
+		--unixSocketPrefix ${MONGODB_RUN:-/var/run/mongodb} \
+		--logappend --logpath /var/log/mongodb/${SVCNAME}.log \
+		${MONGODB_OPTIONS}
+	eend $?
+}
+
+stop() {
+	ebegin "Stopping ${SVCNAME}"
+	start-stop-daemon --stop --pidfile ${MONGODB_RUN:-/var/run/mongodb}/${SVCNAME}.pid
+	eend $?
+}
diff --git a/testing/mongodb/mongodb.logrotate b/testing/mongodb/mongodb.logrotate
new file mode 100644
index 0000000..f95a438
--- /dev/null
+++ b/testing/mongodb/mongodb.logrotate
@@ -0,0 +1,13 @@
+# Default log rotation / compression keeps 1 year of logs.
+/var/log/mongodb/*.log {
+	daily
+	rotate 365
+	dateext
+	copytruncate
+	delaycompress
+	compress
+	notifempty
+	extension gz
+	sharedscripts
+	missingok
+}
diff --git a/testing/mongodb/mongodb.post-install b/testing/mongodb/mongodb.post-install
new file mode 100644
index 0000000..774c50e
--- /dev/null
+++ b/testing/mongodb/mongodb.post-install
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+chown mongodb:daemon var/lib/mongodb
+chown mongodb:daemon var/log/mongodb
+exit 0
diff --git a/testing/mongodb/mongodb.pre-deinstall b/testing/mongodb/mongodb.pre-deinstall
new file mode 100644
index 0000000..517d2a6
--- /dev/null
+++ b/testing/mongodb/mongodb.pre-deinstall
@@ -0,0 +1,4 @@
+#!/bin/bash
+
+deluser mongodb
+exit 0
diff --git a/testing/mongodb/mongodb.pre-install b/testing/mongodb/mongodb.pre-install
new file mode 100644
index 0000000..e02453f
--- /dev/null
+++ b/testing/mongodb/mongodb.pre-install
@@ -0,0 +1,4 @@
+#!/bin/sh
+
+adduser -D -G daemon -h /var/lib/mongodb -s /sbin/nologin mongodb
+exit 0
diff --git a/testing/mongodb/mongos.confd b/testing/mongodb/mongos.confd
new file mode 100644
index 0000000..644cd0a
--- /dev/null
+++ b/testing/mongodb/mongos.confd
@@ -0,0 +1,16 @@
+# Mongos essentials
+MONGOS_EXEC="/usr/bin/mongos"
+MONGOS_RUN="/var/run/mongodb"
+MONGOS_USER="mongodb"
+
+# Listen to specified IP, comment this to listen to all
+MONGOS_IP="127.0.0.1"
+
+# Listen to specified port
+MONGOS_PORT="27018"
+
+# 1 to 3 comma separated config servers (mandatory)
+MONGOS_CONFIGDB=""
+
+# Set extra options here
+MONGOS_OPTIONS=""
diff --git a/testing/mongodb/mongos.initd b/testing/mongodb/mongos.initd
new file mode 100644
index 0000000..2f9bd9a
--- /dev/null
+++ b/testing/mongodb/mongos.initd
@@ -0,0 +1,45 @@
+#!/sbin/runscript
+# Copyright 1999-2013 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Header: /var/cvsroot/gentoo-x86/dev-db/mongodb/files/mongos.initd,v 1.3 2013/01/18 11:19:27 ultrabug Exp $
+
+depend() {
+	need net
+}
+
+checkconfig() {
+	if [ -z "${MONGOS_CONFIGDB}" ]; then
+		eerror "MONGOS_CONFIGDB is not defined, check your configuration file !"
+		return 1
+	fi
+	return 0
+}
+
+start() {
+	checkconfig || return 1
+
+	checkpath -d -m 0750 -o "${MONGOS_USER}":mongodb "${MONGOS_RUN}"
+
+	# Listen to MONGOS_IP if configured
+	[ -z "${MONGOS_IP}" ] || MONGOS_OPTIONS="--bind_ip ${MONGOS_IP} ${MONGOS_OPTIONS}"
+
+	local USEROPT="--user"
+	ebegin "Starting ${SVCNAME}"
+	start-stop-daemon --background --start --make-pidfile \
+		--pidfile ${MONGOS_RUN:-/var/run/mongodb}/${SVCNAME}.pid \
+		${USEROPT} ${MONGOS_USER:-mongodb} \
+		--exec ${MONGOS_EXEC:-/usr/bin/mongos} \
+		-- \
+		--port ${MONGOS_PORT:-27018} \
+		--unixSocketPrefix ${MONGOS_RUN:-/var/run/mongodb} \
+		--logappend --logpath /var/log/mongodb/${SVCNAME}.log \
+		--configdb ${MONGOS_CONFIGDB} \
+		${MONGOS_OPTIONS}
+	eend $?
+}
+
+stop() {
+	ebegin "Stopping ${SVCNAME}"
+	start-stop-daemon --stop --pidfile ${MONGOS_RUN:-/var/run/mongodb}/${SVCNAME}.pid
+	eend $?
+}
-- 
2.0.5