File mongodb.spec of Package mongodb

#
# spec file for package mongodb
#
# Copyright (c) 2016 SUSE LINUX GmbH, Nuernberg, Germany.
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via http://bugs.opensuse.org/
#


%define _home_dir       %{_var}/lib/%{name}
%define _mongodb_user     %{name}
%define _mongodb_group    %{name}
%if 0%{?suse_version} > 1220
    %bcond_without systemd
%else
    %bcond_with systemd
%endif
%define upstream_arches x86_64 ppc64le aarch64 s390x
%define mozjsVersion 45


Name:           mongodb
Version:        3.4.2
Release:        0
Summary:        MongoDB open source document-oriented database system (metapackage)
License:        AGPL-3.0
Group:          Productivity/Databases/Servers
Url:            http://www.mongodb.org
Source0:        https://fastdl.mongodb.org/src/mongodb-src-r%{version}.tar.gz
Source1:        mongodb.init
Source2:        mongodb.logrotate
Source3:        mongodb.conf
Source4:        mongodb.service

# Enable building with system version of libraries
# https://jira.mongodb.org/browse/SERVER-21353
Patch0:         system-libs.patch
# Update bundled https://github.com/chriskohlhoff/asio/ to latest master (to support openssl 1.1.0)
# revision: 14db6371b338339383aacaed29b0fa352259645a
# ASIO_STANDALONE and ASIO_SEPARATE_COMPILATION needs to be defined for proper build
Patch1:         asio-master.patch
# Fix using timer from updated asio (changed in new asio version)
Patch2:         asio-new.patch
# Add support also for 32bit platforms
#TODO - make it working also for 64bit platforms (to have same code on all platforms)
Patch3:         32bit-support.patch
# Add support for openssl >= 1.1.0
Patch4:         openssl-1.1.0.patch
# Enable ppc64 big endian support
Patch5:         ppc64.patch
# Fix for boost 1.62+
# Thanks to Gentoo
Patch6:		mongodb-3.4.2-boost-1.63-fix.patch

BuildRequires:  glibc-devel
BuildRequires:  openssl-devel
BuildRequires:  scons >= 2.3
BuildRequires:  valgrind-devel
BuildRequires:  libicu-devel
BuildRequires:  boost-devel >= 1.56
BuildRequires:  gperftools-devel
BuildRequires:  libpcap-devel
#BuildRequires:  libstemmer-devel
BuildRequires:  openssl-devel
BuildRequires:  pcre-devel
BuildRequires:  snappy-devel
BuildRequires:  yaml-cpp-devel
BuildRequires:  zlib-devel
BuildRequires:  asio-devel
BuildRequires:  systemd
%ifnarch %{upstream_arches}
BuildRequires:  mozjs%{mozjsVersion}-devel
%endif
Requires:       logrotate
Requires:       mongodb-mongoperf = %{version}
Requires:       mongodb-mongos = %{version}
Requires:       mongodb-server = %{version}
Requires:       mongodb-shell = %{version}
Requires(pre):  %{_sbindir}/groupadd
Requires(pre):  %{_sbindir}/useradd
Conflicts:      mongo-10gen-enterprise
Conflicts:      mongodb-enterprise
Conflicts:      mongodb-enterprise-unstable
Conflicts:      mongodb-org
Conflicts:      mongodb-org-unstable
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
ExcludeArch:    s390x ppc
# MongoDB (upstream) does NOT support PPC, PPC64 or PPC64LE
# on the 3.0.X series.
#
# MongoDB specifically recommends NOT
# building and using mongodb on PPC, including
# PPC64 and PPC64LE because it may, among
# other things, corrupt data. Compiling pure upstream
# mongodb also fails on PPC, PPC64 and PPC64LE.
#
# MongoDB is working and plans to support PPC64 and PPC64LE
# in the future.
#
# Leave PPC lines in spec file to make it (much) easier to enable
# PPC building when updating mongodb to newer version
# since they have been known to work and have been suggested by upstream
ExcludeArch: ppc64 ppc64le
# openSUSE version > 13.1 have the proper gcc to build mongodb,
# but 13.1 has an incompatible version of gcc 4.8
#
# Therefore, create a more strict requirement, that if satisfied,
# will let mongodb compile on 13.1
#
# This if/else/endif statment allows mongodb to compile on 13.2,
# because using a stricter requirement (like for <= 13.1) fails
%if 0%{?suse_version} && 0%{?suse_version} > 1310
BuildRequires:  gcc-c++ >= 4.8
%else
BuildRequires:  gcc-c++ >= 4.8.2
%endif
%ifarch ppc64 ppc64le
BuildRequires:  gperftools-devel
%endif
%if %{with systemd}
BuildRequires:  systemd
%{?systemd_requires}
%else
Requires(post): %insserv_prereq
Requires(pre):  %fillup_prereq
Requires(pre):  %insserv_prereq
%endif

%description
MongoDB is built for scalability, performance and high availability,
scaling from single server deployments to large, complex multi-site architectures.
By leveraging in-memory computing, MongoDB provides high performance for both reads and writes.
MongoDB’s native replication and automated failover enable enterprise-grade reliability
andoperational flexibility.

MongoDB features:
* JSON Data Model with Dynamic Schemas
* Auto-Sharding for Horizontal Scalability
* Built-In Replication for High Availability
* Rich Secondary Indexes, including geospatial
* TTL indexes
* Text Search
* Aggregation Framework & Native MapReduce

This metapackage will install the mongo shell, import/export tools, other client utilities, server software, default configuration, and init.d scripts.

%package server
Summary:        MongoDB database server
Group:          Productivity/Databases/Servers
Requires:       openssl
Requires:		shadow
Conflicts:      mongo-10gen-enterprise-server
Conflicts:      mongodb-enterprise-server
Conflicts:      mongodb-enterprise-unstable-server
Conflicts:      mongodb-org-server
Conflicts:      mongodb-org-unstable-server

%description server
MongoDB is built for scalability, performance and high availability,
scaling from single server deployments to large, complex multi-site architectures.
By leveraging in-memory computing, MongoDB provides high performance for both reads and writes.
MongoDB’s native replication and automated failover enable enterprise-grade reliability
and operational flexibility.

MongoDB features:
* JSON Data Model with Dynamic Schemas
* Auto-Sharding for Horizontal Scalability
* Built-In Replication for High Availability
* Rich Secondary Indexes, including geospatial
* TTL indexes
* Text Search
* Aggregation Framework & Native MapReduce

This package contains the MongoDB server software, default configuration files, and service scripts.

%package shell
Summary:        MongoDB shell client
Group:          Productivity/Databases/Clients
Requires:       mongodb-server = %{version}
Requires:       openssl
Conflicts:      mongo-10gen-enterprise-shell
Conflicts:      mongodb-enterprise-shell
Conflicts:      mongodb-enterprise-unstable-shell
Conflicts:      mongodb-org-shell
Conflicts:      mongodb-org-unstable-shell

%description shell
MongoDB is built for scalability, performance and high availability,
scaling from single server deployments to large, complex multi-site architectures.
By leveraging in-memory computing, MongoDB provides high performance for both reads and writes.
MongoDB’s native replication and automated failover enable enterprise-grade reliability
andoperational flexibility.

MongoDB features:
* JSON Data Model with Dynamic Schemas
* Auto-Sharding for Horizontal Scalability
* Built-In Replication for High Availability
* Rich Secondary Indexes, including geospatial
* TTL indexes
* Text Search
* Aggregation Framework & Native MapReduce

This package contains the mongo shell.

%package mongos
Summary:        MongoDB sharded cluster query router
Group:          Productivity/Databases/Tools
Conflicts:      mongo-10gen-enterprise-mongos
Conflicts:      mongodb-enterprise-mongos
Conflicts:      mongodb-enterprise-unstable-mongos
Conflicts:      mongodb-org-mongos
Conflicts:      mongodb-org-unstable-mongos

%description mongos
MongoDB is built for scalability, performance and high availability,
scaling from single server deployments to large, complex multi-site architectures.
By leveraging in-memory computing, MongoDB provides high performance for both reads and writes.
MongoDB’s native replication and automated failover enable enterprise-grade reliability
andoperational flexibility.

MongoDB features:
* JSON Data Model with Dynamic Schemas
* Auto-Sharding for Horizontal Scalability
* Built-In Replication for High Availability
* Rich Secondary Indexes, including geospatial
* TTL indexes
* Text Search
* Aggregation Framework & Native MapReduce

This package contains mongos, the MongoDB sharded cluster query router.

%package mongoperf
Summary:        MongoDB utility to check disk I/O performance
Group:          Productivity/Databases/Tools
Conflicts:      mongo-10gen-enterprise-mongoperf
Conflicts:      mongodb-enterprise-mongoperf
Conflicts:      mongodb-enterprise-unstable-mongoperf
Conflicts:      mongodb-org-mongoperf
Conflicts:      mongodb-org-unstable-mongoperf

%description mongoperf
MongoDB is built for scalability, performance and high availability,
scaling from single server deployments to large, complex multi-site architectures.
By leveraging in-memory computing, MongoDB provides high performance for both reads and writes.
MongoDB’s native replication and automated failover enable enterprise-grade reliability
andoperational flexibility.

MongoDB features:
* JSON Data Model with Dynamic Schemas
* Auto-Sharding for Horizontal Scalability
* Built-In Replication for High Availability
* Rich Secondary Indexes, including geospatial
* TTL indexes
* Text Search
* Aggregation Framework & Native MapReduce

This package contains mongoperf.

%package devel
Summary:        Headers and libraries for MongoDB development
Group:          Development/Libraries/C and C++
Conflicts:      mongo-10gen-enterprise-devel
Conflicts:      mongodb-enterprise-devel
Conflicts:      mongodb-enterprise-unstable-devel
Conflicts:      mongodb-org-devel
Conflicts:      mongodb-org-unstable-devel

%description devel
MongoDB is built for scalability, performance and high availability,
scaling from single server deployments to large, complex multi-site architectures.
By leveraging in-memory computing, MongoDB provides high performance for both reads and writes.
MongoDB’s native replication and automated failover enable enterprise-grade reliability
andoperational flexibility.

MongoDB features:
* JSON Data Model with Dynamic Schemas
* Auto-Sharding for Horizontal Scalability
* Built-In Replication for High Availability
* Rich Secondary Indexes, including geospatial
* TTL indexes
* Text Search
* Aggregation Framework & Native MapReduce

This package provides the MongoDB static library and header files needed to develop MongoDB client software.

%prep
%setup -q -n mongodb-src-r%{version}
%patch0 -p1
%patch1 -p1
%patch2 -p1
%ifarch %{ix86} %{arm}
%patch3 -p1
%endif
%patch4 -p1
%patch5 -p1
%patch6 -p1

# change default database path to reflect the default database user directory
sed -i 's|/data/db/|%{_home_dir}/|' src/mongo/db/storage/storage_options.cpp

# CRLF -> LF
sed -i 's/\r//' README

# disable propagation of $TERM env var into the Scons build system
sed -i -r "s|(for key in \('HOME'), 'TERM'(\):)|\1\2|" SConstruct

# Use system versions of header files (bundled does not differ)
#sed -i -r "s|third_party/libstemmer_c/include/libstemmer.h|libstemmer.h|" src/mongo/db/fts/stemmer.h
sed -i -r "s|third_party/yaml-cpp-0.5.1/include/yaml-cpp/yaml.h|yaml-cpp/yaml.h|" src/mongo/util/options_parser/options_parser.cpp

# by default use system mongod, mongos and mongo binaries in resmoke.py
sed -i -r "s|os.curdir(, \"mongo\")|\"%{_bindir}\"\1|"   buildscripts/resmokelib/config.py
sed -i -r "s|os.curdir(, \"mongod\")|\"%{_bindir}\"\1|"   buildscripts/resmokelib/config.py
sed -i -r "s|os.curdir(, \"mongos\")|\"%{_bindir}\"\1|"   buildscripts/resmokelib/config.py

# set default data prefix in resmoke.py
sed -i -r "s|/data/db|%{_datadir}/%{pkg_name}-test/var|"   buildscripts/resmokelib/config.py

# Disable optimization for s2 library
# https://jira.mongodb.org/browse/SERVER-17511
sed -i -r "s|(env.Append\(CCFLAGS=\['-DDEBUG_MODE=false')(\]\))|\1,'-O0'\2|"  src/third_party/s2/SConscript

# fix one unit test which used gnu++11 code (c++11 is used)
sed -i 's|ASSERT_PARSES(double, "0xabcab.defdefP-10", 0xabcab.defdefP-10);||' src/mongo/base/parse_number_test.cpp

# set default storage engine for non 64-bit arches - RHBZ#1303846
%ifnarch %{upstream_arches} ppc64
sed -i 's|engine = "wiredTiger"|engine = "mmapv1"|' src/mongo/db/storage/storage_options.h
%endif


%build
# Prepare variables for building
cat > variables.list << EOF
CCFLAGS="%{?optflags}"
LINKFLAGS="%{?__global_ldflags} -Wl,-z,noexecstack -Wl,--reduce-memory-overheads,--no-keep-memory"
CPPDEFINES="BOOST_OPTIONAL_USE_SINGLETON_DEFINITION_OF_NONE ASIO_STANDALONE ASIO_SEPARATE_COMPILATION"
VERBOSE=1

%ifarch %{ix86}
# On i686 -ffloat-store is requred to round in GranularityRounderPreferredNumbers
# properly, without this:
# -> build/opt/mongo/db/pipeline/granularity_rounder_test,
#    build/opt/mongo/db/pipeline/accumulator_test, build/opt/mongo/util/summation_test
#    and build/opt/mongo/db/pipeline/document_source_test unittests fail
CCFLAGS+=" -ffloat-store"
%endif
%ifarch ppc64
# Needed for altivec instructions in mongo/db/fts/unicode/byte_vector_altivec.h
CCFLAGS+=" -mcpu=power8"
%endif
%ifarch aarch64
# Needed for CRC32 instructions in third_party/wiredtiger/src/checksum/arm64/crc32-arm64.c
CCFLAGS+=" -march=armv8-a+crc"
%endif
EOF
cat variables.list

# Define build options
cat > build-options << EOF
 %{?_smp_mflags} \
 --use-system-pcre \
 --use-system-boost \
 --use-system-snappy \
 --use-system-valgrind \
 --use-system-zlib \
 --use-system-yaml \
 --use-system-icu \
%ifarch s390x ppc64
 --mmapv1=off
%else
 --mmapv1=on \
%endif
%ifarch s390x
 --allocator=system \
 --use-s390x-crc32=off \
%else
 --use-system-tcmalloc \
%endif
%ifarch %{upstream_arches} ppc64
 --wiredtiger=on \
%else
 --wiredtiger=off \
%endif
%ifnarch %{upstream_arches}
 --use-system-mozjs \
 --js-engine=mozjs-%{mozjsVersion} \
%endif
 --ssl \
 --nostrip \
 --disable-warnings-as-errors \
 --variables-files=variables.list
EOF
# --use-system-asio \

# see output of "scons --help" for options
scons all $(cat build-options)


%install
scons install --prefix=%{buildroot}%{_prefix} $(cat build-options)

mkdir -p %{buildroot}%{_sbindir}
mv %{buildroot}%{_bindir}/mongod %{buildroot}%{_sbindir}/mongod
mv %{buildroot}%{_bindir}/mongos %{buildroot}%{_sbindir}/mongos

mkdir -p %{buildroot}%{_var}/log/mongodb
mkdir -p %{buildroot}%{_var}/lib/mongodb

%if %{with systemd}
    install -D -p -m 0644 %{SOURCE4} %{buildroot}%{_unitdir}/%{name}.service
    install -D -p -m 0755 %{SOURCE1} %{buildroot}%{_sbindir}/rc%{name}
%else
    install -D -p -m 0755 %{SOURCE1} %{buildroot}%{_sysconfdir}/init.d/%{name}
    ln -sf %{_initddir}/%{name} %{buildroot}%{_sbindir}/rc%{name}
%endif

install -D -p -m 0644 %{SOURCE2} %{buildroot}%{_sysconfdir}/logrotate.d/%{name}
install -D -p -m 0644 %{SOURCE3} %{buildroot}%{_sysconfdir}/%{name}.conf

mkdir -p %{buildroot}%{_mandir}/man1/
install -p -m 0644 debian/mongod.1 %{buildroot}%{_mandir}/man1/
install -p -m 0644 debian/mongoperf.1 %{buildroot}%{_mandir}/man1/
install -p -m 0644 debian/mongos.1 %{buildroot}%{_mandir}/man1/
install -p -m 0644 debian/mongo.1 %{buildroot}%{_mandir}/man1/


%pre server
if ! %{_bindir}/id -g %{_mongodb_group} &>/dev/null; then
    %{_sbindir}/groupadd -r %{_mongodb_group}
fi
if ! %{_bindir}/id %{_mongodb_user} &>/dev/null; then
    %{_sbindir}/useradd -M -r -g %{_mongodb_group} \
        -d %{_home_dir} -s /bin/false \
        -c "MongoDB database admin" %{_mongodb_user} > /dev/null 2>&1
fi

%if %{with systemd}
    %{service_add_pre %{name}.service}
%endif

%post server
/sbin/ldconfig
%if %{with systemd}
    %{service_add_post %{name}.service}
%else
    %{fillup_and_insserv -f %{name}}
%endif

%preun server
%if %{with systemd}
    %{service_del_preun %{name}.service}
%else
    %{stop_on_removal %{name}}
%endif

%postun server
/sbin/ldconfig
%if %{with systemd}
    %{service_del_postun %{name}.service}
%else
    %{restart_on_update %{name}}
    %insserv_cleanup
%endif

%files
%defattr(-,root,root)

%files server
%defattr(-,root,root,-)
%{_sbindir}/mongod
%config(noreplace) %{_sysconfdir}/%{name}.conf
%config(noreplace) %{_sysconfdir}/logrotate.d/%{name}
%{_sbindir}/rc%{name}
%{_mandir}/man1/mongod.1*

%if %{with systemd}
%{_unitdir}/%{name}.service
%else
%{_sysconfdir}/init.d/%{name}
%endif
%attr(0750,mongodb,mongodb) %{_var}/log/%{name}
%attr(0750,mongodb,mongodb) %{_var}/lib/%{name}

%files shell
%defattr(-,root,root,-)
%{_bindir}/mongo
%{_mandir}/man1/mongo.1*

%files mongos
%defattr(-,root,root,-)
%{_sbindir}/mongos
%{_mandir}/man1/mongos.1*

%files mongoperf
%defattr(-,root,root,-)
%{_bindir}/mongoperf
%{_mandir}/man1/mongoperf.1*

# TODO:
# * /var/lib/[mongodb] is NOT a subvolume in default BTRFS setup,
# which means system snapper snapshots will include mongodb database files!
# this is an issue with any database that's not PostgreSQL

%changelog
openSUSE Build Service is sponsored by