File mongodb.spec of Package mongodb
#
# spec file for package mongodb
#
#SuSe specific Part
%if 0%{?suse_version} == 1110
%define prepare_scons 1
%define init 1
Requires: syslog-ng coreutils pwdutils libstdc++
BuildRequires: syslog-ng coreutils pwdutils libstdc++
%endif
%if %{?centos_version:1}0
%define prepare_scons 1
Requires: coreutils libstdc++
BuildRequires: coreutils libstdc++
%endif
%if 0%{?suse_version} >= 1315
%define prepare_scons 0
Requires: libstdc++6 scons
BuildRequires: libstdc++6 scons
%endif
#all Distros
Name: mongodb
Version: 2.6.3
Release: 3
License: GNU
Summary: open-source document database
Url: http://www.mongodb.org/
Group: databases/mongodb
Source: https://fastdl.mongodb.org/src/mongodb-src-r2.6.3.tar.gz
BuildRequires: python
BuildRequires: gcc-c++
#BuildRequires: libstdc++
BuildRequires: rpm >= 4.4.2
BuildRequires: -post-build-checks
#BuildRequires: -post-build-checks
#Requires: libstdc++
BuildRoot: %{_tmppath}/%{name}-%{version}-build
#Variables
#If you change user and group the mongo service will still try to start as mongodb. You need to edit the standart config includet in this package as well.
%define mongo_user mongodb
%define mongo_group mongodb
%description
MongoDB is an open-source document database that provides high performance, high availability, and automatic scaling.
%prep
%setup -q
#Some Distros cant build since they dont provide scons >= 1.1. Therefore we need to compile it from source.
%if %{?prepare_scons:1}0
cd scons-2.3.1
mkdir ./installed
python ./setup.py build
python ./setup.py install --prefix ./installed
#Sometimes scons fails to find its own libraries after installation. As a workaround we hardcode a librarie location
sed -i -e 's;libs = \[\];libs = \["/usr/src/packages/BUILD/mongodb-2.6.3/scons-2.3.1/installed/lib64/scons-2.3.1"\];g' installed/bin/scons
%endif
%build
%install
%if %{?prepare_scons:1}0
scons-2.3.1/installed/bin/scons --prefix=%{buildroot}/usr install
%else
scons --prefix=%{buildroot}/usr install #use native scons
%endif
install -D rpm/mongod.conf %{buildroot}/etc/mongodb/mongodb.conf
install -d %{buildroot}/var/run
install -d %{buildroot}/var/log/mongodb
install -d %{buildroot}/var/lib/mongo
install -D %{_sourcedir}/mongodb.init %{buildroot}/etc/init.d/mongodb
touch %{buildroot}/var/run/mongod.pid
touch %{buildroot}/var/log/mongodb/mongod.log
install -D %{_sourcedir}/mongodb.logrotate %{buildroot}/etc/logrotate.d/mongodb
%pre
getent group %{mongo_group} || groupadd -r %{mongo_group}
getent passwd %{mongo_user} || useradd -r %{mongo_user} -g %{mongo_group}
%post
/sbin/chkconfig --add mongodb &>/dev/null
%preun
chkconfig -s mongodb off &>/dev/null
%postun
getent passwd %{mongo_user} && userdel -r %{mongo_user} -g %{mongo_group}
getent group %{mongo_group} && groudel -r %{mongo_group}
%files
%defattr(755,root,root)
%dir %attr(-,%{mongo_user},%{mongo_group}) /var/log/mongodb
%dir %attr(-,%{mongo_user},%{mongo_group}) /var/lib/mongo
%{_bindir}/mongo*
%{_bindir}/bsondump
%ghost /var/run/mongod.pid
%ghost /var/log/mongodb/mongod.log
%dir /etc/mongodb
%attr(644,root,root) /etc/mongodb/mongodb.conf
%config(noreplace) /etc/logrotate.d/mongodb
%if %{?centos_version:1}0
%else
%dir /etc/init.d/
%endif
/etc/init.d/mongodb
%changelog