File sphinx.spec of Package sphinx
#
# spec file for package sphinx
#
# Copyright (c) 2015 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/
#
%global sphinx_user sphinx
%global sphinx_group sphinx
%global daemon searchd
%global sphinx_home %{_localstatedir}/lib/sphinx
%global soname 0_0_1
# For being able to build for SLE_11
%{!?_tmpfilesdir:%global _tmpfilesdir /usr/lib/tmpfiles.d}
Name: sphinx
Version: 2.2.10
Release: 0
Summary: Free open-source SQL full-text search engine
License: GPL-2.0
Group: Productivity/Databases/Servers
Url: http://sphinxsearch.com/
Source0: http://sphinxsearch.com/files/%{name}-%{version}-release.tar.gz
Source1: %{daemon}.service
Source2: %{daemon}.init
Patch0: obs.patch
Patch2: sphinx-default_listen.patch
# for fix-ups
BuildRequires: dos2unix
BuildRequires: gcc-c++
BuildRequires: libexpat-devel
BuildRequires: mysql-devel
BuildRequires: postgresql-devel
%if 0%{?suse_version}
Requires(post): %fillup_prereq
Requires(pre): %{_bindir}/getent
#Requires(pre): permissions >= 2014.11
Requires(pre): pwdutils
%else
Requires(pre): shadow-utils
Requires(post): /sbin/chkconfig
Requires(preun): /sbin/service /sbin/chkconfig
Requires(postun): /sbin/service
%endif
%if 0%{?suse_version} > 1210
BuildRequires: systemd
BuildRequires: systemd-rpm-macros
Requires(pre): systemd
%define has_systemd 1
%else
Requires(pre): %insserv_prereq
%endif
Requires: logrotate
Provides: %{daemon}
#
BuildRoot: %{_tmppath}/%{name}-%{version}-build
%description
Sphinx is a full-text search engine, distributed under GPL version 2.
Commercial licensing (e.g. for embedded use) is also available upon request.
Generally, it's a standalone search engine, meant to provide fast,
size-efficient and relevant full-text search functions to other
applications. Sphinx was specially designed to integrate well with SQL
databases and scripting languages.
Currently built-in data source drivers support fetching data either via
direct connection to MySQL, or PostgreSQL, or from a pipe in a custom XML
format. Adding new drivers (e.g. to natively support some other DBMSes) is
designed to be as easy as possible.
Search API is natively ported to PHP, Python, Perl, Ruby, Java, and also
available as a pluggable MySQL storage engine. API is very lightweight so
porting it to new language is known to take a few hours.
As for the name, Sphinx is an acronym which is officially decoded as SQL
Phrase Index. Yes, I know about CMU's Sphinx project.
%package -n libsphinxclient-%{soname}
Summary: Pure C searchd client API library
Group: Development/Libraries/Other
%description -n libsphinxclient-%{soname}
Pure C searchd client API library
Sphinx search engine, http://sphinxsearch.com/
%package -n libsphinxclient-devel
Summary: Development libraries and header files for libsphinxclient
Group: Development/Libraries/Other
Requires: libsphinxclient = %{version}-%{release}
%description -n libsphinxclient-devel
Provides necessary development files for sphinx api and shared libs for sphinx client.
Pure C searchd client API library
Sphinx search engine, http://sphinxsearch.com/
# Comment
# we don't package api language java,ruby,php,python
# upstream don't recommend their usage.
%prep
%setup -q -n "%{name}-%{version}-release"
%patch0 -p1
%patch2 -p1
find -type d -name CVS -print0 | xargs -r0 rm -rf
%build
%configure --sysconfdir=%{_sysconfdir}/%{name}/ --with-mysql --with-pgsql --enable-id64
make %{?_smp_mflags} VERBOSE=1
pushd api/libsphinxclient
%configure --sysconfdir=%{_sysconfdir}/%{name}/
make VERBOSE=1 # Not supported upstream %%{?_smp_mflags}
popd
%install
make VERBOSE=1 DESTDIR=%{buildroot} install %{?_smp_mflags}
pushd api/libsphinxclient
make VERBOSE=1 DESTDIR=%{buildroot} install %{?_smp_mflags}
popd
# clean-up .la archives
find %{buildroot} -name '*.la' -exec rm -vf {} ';'
# clean-up .a archives
find %{buildroot} -name '*.a' -exec rm -vf {} ';'
# Create /var/log/sphinx
mkdir -p %{buildroot}%{_localstatedir}/log/%{name}
# Create /var/run/sphinx
mkdir -p %{buildroot}/run/%{name}
# Create /var/lib/sphinx
mkdir -p %{buildroot}%{_localstatedir}/lib/%{name}/data/index
# etc/sphinx.conf preparation
# Adjust sphinx*.conf.dist to our location
for CONF in %{buildroot}%{_sysconfdir}/%{name}/%{name}.conf.dist\
%{buildroot}%{_sysconfdir}/%{name}/%{name}-min.conf.dist;
do
sed -i 's|/var/log/%{daemon}.log|%{_localstatedir}/log/%{name}/%{daemon}.log|g' ${CONF}
sed -i 's|/var/log/query.log|%{_localstatedir}/log/%{name}/query.log|g' ${CONF}
sed -i 's|/var/log/%{daemon}.pid|/run/%{name}/%{daemon}.pid|g' ${CONF}
sed -i 's|/var/data|%{_localstatedir}/lib/%{name}/data|g' ${CONF}
done
cp -v %{buildroot}%{_sysconfdir}/%{name}/%{name}.conf{.dist,}
# Create /etc/logrotate.d/sphinx
mkdir -p %{buildroot}%{_sysconfdir}/logrotate.d
cat > %{buildroot}%{_sysconfdir}/logrotate.d/%{name} << EOF
%{_localstatedir}/log/%{name}/*.log {
weekly
rotate 10
copytruncate
delaycompress
compress
notifempty
missingok
create 640 %{sphinx_user} root
}
EOF
%if 0%{?has_systemd}
# Create /usr/tempfiles.d/sphinx
mkdir -p %{buildroot}%{_tmpfilesdir}
cat > %{buildroot}%{_tmpfilesdir}/%{name}.conf << EOF
d /run/%{name} 755 sphinx root -
EOF
%endif
# systemd vs SysVinit
mkdir -p %{buildroot}%{_sbindir}
%if 0%{?has_systemd}
install -D -m 644 %{SOURCE1} %{buildroot}%{_unitdir}/%{daemon}.service
ln -sf %{_sbindir}/service %{buildroot}%{_sbindir}/rc%{daemon}
%else
#SysVinit
install -D %{SOURCE2} %{buildroot}%{_sysconfdir}/init.d/%{daemon}
%if 0%{?suse_version}
ln -sf %{_sysconfdir}/init.d/%{daemon} %{buildroot}%{_sbindir}/rc%{daemon}
%endif
%endif
%pre
getent group %{sphinx_group} >/dev/null || groupadd -r %{sphinx_group}
getent passwd %{sphinx_user} >/dev/null || \
useradd -r -g %{sphinx_group} -d %{sphinx_home} -s /bin/sh \
-c "Sphinx Searchd daemon" %{sphinx_user}
exit 0
%if 0%{?has_systemd}
%service_add_pre %{daemon}.service
%endif
%post
%if 0%{?has_systemd}
%service_add_post %{daemon}.service
/usr/bin/systemd-tmpfiles --create %{_tmpfilesdir}/%{name}.conf || true
%else
%if 0%{?suse_version}
%{fillup_and_insserv -n "%{daemon}"}
%else
/sbin/chkconfig --add %{daemon}
%endif
%endif
# Create empty log files with correct rights if not exist
for LOG in %{_localstatedir}/log/%{name}/%{daemon}.log\
%{_localstatedir}/log/%{name}/query.log;
do
if [ ! -f ${LOG} ];then
touch ${LOG}
chmod 0640 ${LOG}
chown %{sphinx_user}:root ${LOG}
fi
done
%preun
%if 0%{?has_systemd}
%service_del_preun %{daemon}.service
/usr/bin/systemd-tmpfiles --remove %{_tmpfilesdir}/%{name}.conf || true
%else
%if 0%{?suse_version}
%stop_on_removal %{daemon}
%else
if [ $1 = 0 ] ; then
service %{daemon} stop >/dev/null 2>&1
/sbin/chkconfig --del %{daemon}
fi
%endif
%endif
%postun
%if 0%{?has_systemd}
%service_del_postun %{daemon}.service
%else
%if 0%{?suse_version}
%restart_on_update %{daemon}
%insserv_cleanup
%else
if [ "$1" -ge "1" ] ; then
service %{daemon} restart >/dev/null 2>&1
fi
%endif
%endif
%posttrans
# chown -R %%{sphinx_user}:root %%{_localstatedir}/log/sphinx/
chown -R %{sphinx_user}:%{sphinx_group} %{_localstatedir}/lib/%{name}/
%post -n libsphinxclient-%{soname} -p /sbin/ldconfig
%files
%defattr(750,root,root,-)
%config %dir %{_sysconfdir}/%{name}
# Restrict rights access to conf files they can contain sql db credentials
%defattr(640,root,%{sphinx_group},-)
%config %{_sysconfdir}/%{name}/example.sql
%config(noreplace) %{_sysconfdir}/%{name}/%{name}.conf
%config %{_sysconfdir}/%{name}/%{name}.conf.dist
%config %{_sysconfdir}/%{name}/%{name}-min.conf.dist
%defattr(-,root,root,-)
%if 0%{?has_systemd}
%{_unitdir}/%{daemon}.service
%{_tmpfilesdir}/%{name}.conf
%else
%{_sysconfdir}/init.d/%{daemon}
%endif
%{_sbindir}/rc%{daemon}
%config %{_sysconfdir}/logrotate.d/%{name}
%{_bindir}/spelldump
%{_bindir}/indexer
%{_bindir}/searchd
%{_bindir}/indextool
%{_bindir}/wordbreaker
%doc COPYING contrib/
%doc doc/*.html doc/*.css doc/*.txt
%doc %attr(644, root, man) %{_mandir}/man1/indexer.1*
%doc %attr(644, root, man) %{_mandir}/man1/indextool.1*
%doc %attr(644, root, man) %{_mandir}/man1/search.1*
%doc %attr(644, root, man) %{_mandir}/man1/searchd.1*
%doc %attr(644, root, man) %{_mandir}/man1/spelldump.1*
%dir %attr(0750, root, %{sphinx_group}) %{_localstatedir}/log/%{name}
#Doesn't work on SLE_11 :-(
%if 0%{?suse_version} > 1230
%ghost %attr(0640, %{sphinx_user}, root) %{_localstatedir}/log/%{name}/%{daemon}.log
%ghost %attr(0640, %{sphinx_user}, root) %{_localstatedir}/log/%{name}/query.log
%endif
%dir %attr(0755, %{sphinx_user}, %{sphinx_group}) %{_localstatedir}/lib/%{name}
%dir %attr(0755, %{sphinx_user}, %{sphinx_group}) %{_localstatedir}/lib/%{name}/data
%dir %attr(0755, %{sphinx_user}, %{sphinx_group}) %{_localstatedir}/lib/%{name}/data/index
%files -n libsphinxclient-%{soname}
%defattr(-,root,root,-)
%doc COPYING
%attr(755, root, root) %{_libdir}/libsphinxclient-0.0.1.so
%files -n libsphinxclient-devel
%defattr(-,root,root,-)
%doc COPYING
%{_includedir}/sphinxclient.h
%{_libdir}/libsphinxclient.so
%changelog