File gearmand.spec of Package gearmand

#
# spec file for package gearmand
#
# Copyright (c) 2019 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 https://bugs.opensuse.org/
#


%define         libversion 8
%define         gearmand_user  gearman
%define         gearmand_group gearman
%{!?_tmpfilesdir:%global _tmpfilesdir %{_prefix}/lib/tmpfiles.d}
%if ! %{defined _rundir}
%define _rundir %{_localstatedir}/run
%endif
%if ! %{defined _fillupdir}
%define _fillupdir %{_localstatedir}/adm/fillup-templates
%endif
Name:           gearmand
Version:        1.1.19.1
Release:        0
Summary:        Gearman Job Server
License:        BSD-3-Clause
Group:          Productivity/Networking/Web/Servers
URL:            http://gearman.org
Source0:        %{name}-%{version}.tar.gz
Source1:        %{name}.init
Source2:        %{name}.sysconfig
Source3:        %{name}-rpmlintrc
Source4:        gearmand-firewall
Source5:        %{name}.service
Patch0:         fix-without-mysql.patch
Patch1:         makefile-remove-clean-rpm.patch
BuildRequires:  boost-devel
BuildRequires:  gcc
BuildRequires:  gcc-c++
BuildRequires:  gperf
BuildRequires:  hiredis-devel
BuildRequires:  libboost_program_options-devel
BuildRequires:  libcurl-devel
BuildRequires:  libevent-devel
BuildRequires:  libmemcached-devel
BuildRequires:  libtool
BuildRequires:  libuuid-devel
BuildRequires:  mysql-devel
BuildRequires:  pkgconfig
BuildRequires:  postgresql-devel
BuildRequires:  sqlite3-devel
BuildRequires:  update-alternatives
Requires:       %{name}-server = %{version}
%if 0%{?sle_version} <= 120300 && 0%{?is_opensuse}
BuildRequires:  boost-devel
BuildRequires:  libmysqlclient-devel
%endif
%if 0%{?suse_version} >= 1210
BuildRequires:  systemd
%{?systemd_requires}
%endif

%description
Gearman provides a generic application framework to farm out work to other
machines or processes that are better suited to do the work. It allows you to
do work in parallel, to load balance processing, and to call functions between
languages. It can be used in a variety of applications, from high-availability
web sites to the transport of database replication events. In other words, it
is the nervous system for how distributed processing communicates.

%package -n libgearman%{libversion}
Summary:        Library providing Gearman client and worker functions
Group:          System/Libraries

%description -n libgearman%{libversion}
Gearman is a system to farm out work to other machines, dispatching function
calls to machines that are better suited to do work, to do work in parallel,
to load balance lots of function calls, or to call functions between languages.

This package contains the C reimplementation of the client library.

%package server
Summary:        Gearmand Server
Group:          Productivity/Networking/Web/Servers
Requires:       %{name}-server-db = %{version}
Requires:       libgearman%{libversion} = %{version}
Requires:       logrotate
Requires(pre):  %fillup_prereq
Requires(pre):  %insserv_prereq
Requires(pre):  pwdutils
Requires(pre):  update-alternatives
Recommends:     %{name}-server-sqlite3 = %{version}
Recommends:     %{name}-tools = %{version}
Recommends:     memcached

%description server
Gearman provides a generic framework to farm out work to other machines,
dispatching function calls to machines that are better suited to do work, to do
work in parallel, to load balance processing, or to call functions between
languages.

This package provides the Gearmand Server.

%package server-mysql
Summary:        Gearmand Server with MySQL support
Group:          Productivity/Networking/Web/Servers
Requires(pre):  %{name}-server
Provides:       %{name}-server-db = %{version}

%description server-mysql
Gearman provides a generic framework to farm out work to other machines,
dispatching function calls to machines that are better suited to do work, to do
work in parallel, to load balance processing, or to call functions between
languages.

This package provides the Gearmand Server with MySQL support.

%package server-postgresql
Summary:        Gearmand Server with PostgreSQL support
Group:          Productivity/Networking/Web/Servers
Requires(pre):  %{name}-server
Provides:       %{name}-server-db = %{version}

%description server-postgresql
Gearman provides a generic framework to farm out work to other machines,
dispatching function calls to machines that are better suited to do work, to do
work in parallel, to load balance processing, or to call functions between
languages.

This package provides the Gearmand Server with PostgreSQL support.

%package server-sqlite3
Summary:        Gearmand Server with SQlite3 support
Group:          Productivity/Networking/Web/Servers
Requires(pre):  %{name}-server
Provides:       %{name}-server-db = %{version}

%description server-sqlite3
Gearman provides a generic framework to farm out work to other machines,
dispatching function calls to machines that are better suited to do work, to do
work in parallel, to load balance processing, or to call functions between
languages.

This package provides the Gearmand Server with SQlite3 support

%package server-redis
Summary:        Gearmand Server with Redis support
Group:          Productivity/Networking/Web/Servers
Requires(pre):  %{name}-server
Provides:       %{name}-server-db = %{version}

%description server-redis
Gearman provides a generic framework to farm out work to other machines,
dispatching function calls to machines that are better suited to do work, to do
work in parallel, to load balance processing, or to call functions between
languages.

This package provides the Gearmand Server with Redis support

%package server-memcached
Summary:        Gearmand Server with memcached support
Group:          Productivity/Networking/Web/Servers
Requires(pre):  %{name}-server
Provides:       %{name}-server-db = %{version}

%description server-memcached
Gearman provides a generic framework to farm out work to other machines,
dispatching function calls to machines that are better suited to do work, to do
work in parallel, to load balance processing, or to call functions between
languages.

This package provides the Gearmand Server with memcached support

%package doc
Summary:        Gearman Developer Documentation
Group:          Documentation/Other
%if 0%{?suse_version}
Recommends:     %{name} = %{version}
%endif

%description doc
Gearman is a system to farm out work to other machines, dispatching function
calls to machines that are better suited to do work, to do work in parallel,
to load balance lots of function calls, or to call functions between languages.

This package contains the API docs for the libgearman library.

%package tools
Summary:        Tools for the Gearman distributed job queue
Group:          Productivity/Networking/Web/Servers
Requires:       libgearman%{libversion} = %{version}

%description tools
This package contains command line tools for manipulating gearman jobs.

%package devel
Summary:        Gearmand development files
Group:          Development/Libraries/Other
Requires:       glibc-devel
Requires:       libevent-devel
Requires:       libgearman%{libversion} = %{version}
Requires:       libuuid-devel

%description devel
This package contains necessary header files for Gearman development.

%prep
%setup -q
%patch0 -p1
%patch1 -p1

%build
mkdir -p gearmand-binaries
CONFIGURE_OPTS="--disable-static --disable-libdrizzle --disable-libtokyocabinet --enable-ssl=yes"
# build gearmand with mysql support
%configure $CONFIGURE_OPTS --disable-libmemcached --disable-libpq --without-sqlite3 --disable-hiredis
make %{?_smp_mflags}
cp gearmand/gearmand gearmand-binaries/gearmand-mysql
make %{?_smp_mflags} clean
# build gearmand with postgresql support
%configure $CONFIGURE_OPTS --disable-libmemcached --without-mysql --without-sqlite3 --disable-hiredis
make %{?_smp_mflags}
cp gearmand/gearmand gearmand-binaries/gearmand-postgresql
make %{?_smp_mflags} clean
# build gearmand with redis support
%configure $CONFIGURE_OPTS --disable-libmemcached --without-mysql --disable-libpq --without-sqlite3
make %{?_smp_mflags}
cp gearmand/gearmand gearmand-binaries/gearmand-redis
make %{?_smp_mflags} clean
# build gearmand with memcached support
%configure $CONFIGURE_OPTS --disable-hiredis --without-mysql --disable-libpq --without-sqlite3
make %{?_smp_mflags}
cp gearmand/gearmand gearmand-binaries/gearmand-memcached
make %{?_smp_mflags} clean
# build gearmand with sqlite3 support (the default)
%configure $CONFIGURE_OPTS --disable-libmemcached --without-mysql --disable-libpq --disable-hiredis
make %{?_smp_mflags}
cp gearmand/gearmand gearmand-binaries/gearmand-sqlite3

%install
%make_install
# install man pages
pushd man >/dev/null
mkdir -p %{buildroot}/%{_mandir}/man{1,3,8}
for no in 1 3 8 ; do
  for file in *.${no} ; do
	install -m644 $file  %{buildroot}/%{_mandir}/man${no}/
  done
done
popd >/dev/null
pushd %{buildroot}/%{_mandir}/man8 >/dev/null
ln -s %{name} %{name}-mysql
ln -s %{name} %{name}-postgresql
ln -s %{name} %{name}-sqlite3
ln -s %{name} %{name}-redis
ln -s %{name} %{name}-memcached
popd >/dev/null
# install binaries with different dependencies
pushd gearmand-binaries
for file in *; do
	install -m755 "$file" %{buildroot}%{_sbindir}/
done
popd
# create a dummy target for /etc/alternatives/gearmand
touch %{buildroot}/%{_sbindir}/%{name}
mkdir -p %{buildroot}%{_sysconfdir}/alternatives
ln -s -f ../../%{_sbindir}/%{name} %{buildroot}%{_sysconfdir}/alternatives/%{name}
%if 0%{?suse_version} < 1230
# install init script and dependencies
install -D -m 0755 %{SOURCE1} %{buildroot}%{_sysconfdir}/init.d/gearmand
ln -s -f ../../%{_sysconfdir}/init.d/gearmand %{buildroot}%{_sbindir}/rcgearmand
%endif
%if 0%{?suse_version} >= 1210
# install systemd specific files
install -Dm644 %{SOURCE5} %{buildroot}%{_unitdir}/%{name}.service
ln -s %{_sbindir}/service %{buildroot}%{_sbindir}/rc%{name}
%endif
install -D -m 0644 %{SOURCE2} %{buildroot}%{_fillupdir}/sysconfig.gearmand
# install documentation
install -d -m 0755 %{buildroot}%{_defaultdocdir}/%{name}
install -m 644 AUTHORS ChangeLog COPYING HACKING NEWS %{buildroot}%{_defaultdocdir}/%{name}/
cp -r docs %{buildroot}%{_defaultdocdir}/%{name}/
# install logrotate config
mkdir -p %{buildroot}%{_sysconfdir}/logrotate.d
cat >> %{buildroot}%{_sysconfdir}/logrotate.d/%{name} << EOF
%{_localstatedir}/log/gearmand/*.log {
        daily
        rotate 4
        missingok
        compress
%if 0%{?suse_version} >= 01210
        su %{gearmand_user} %{gearmand_group}
%endif
}
EOF
# make rpmlint happy: remove the directories
rm -rf "%{buildroot}%{_defaultdocdir}/%{name}/docs/libgearman/examples/.deps"
rm -rf "%{buildroot}%{_defaultdocdir}/%{name}/docs/libgearman/examples/.libs"
rm -rf "%{buildroot}%{_defaultdocdir}/%{name}/docs/libgearman/examples/.dirstamp"
rm -rf "%{buildroot}%{_defaultdocdir}/%{name}/docs/{conf.py.in,include.am}"
rm -rf "%{buildroot}%{_defaultdocdir}/%{name}/docs/source"
find "%{buildroot}%{_defaultdocdir}/%{name}" -type f -exec chmod 644 {} \;
# install SuSEfirewall2 script
%if 0%{?suse_version} < 1500
install -Dm644 %{SOURCE4} %{buildroot}/%{_sysconfdir}/sysconfig/SuSEfirewall2.d/services/%{name}-server
%endif


# install runtime directories
mkdir -p %{buildroot}%{_localstatedir}/log/gearmand
mkdir -p %{buildroot}%{_localstatedir}/lib/gearman

%if 0%{?suse_version} >= 1220
install -d -m 0755 %{buildroot}/%{_tmpfilesdir}
echo "d /%{_rundir}/%{name} 0755 %{gearmand_user} %{gearmand_group}" > %{buildroot}/%{_tmpfilesdir}/%{name}.conf
chmod 644 %{buildroot}/%{_tmpfilesdir}/%{name}.conf
%else
mkdir -p %{buildroot}/%{_rundir}
%endif
# manually change rundir uses in init.d script and systemd file
%if 0%{?suse_version} >= 1320
sed -i -e 's/\/var\/run\/%{name}/\/rundir\/%{name}/g' %{buildroot}%{_unitdir}/%{name}.service
%endif

%pre server
%{_sbindir}/groupadd -r %{gearmand_user} &>/dev/null || :
%{_sbindir}/useradd -g %{gearmand_group} -s /bin/false -r -c "Gearman Server" -d %{_localstatedir}/lib/gearman/ %{gearmand_user} &>/dev/null || :
%service_add_pre %{name}.service

%post server
%if 0%{?suse_version} < 1230
%{fillup_and_insserv -y gearmand}
%endif
%if 0%{?suse_version} >= 1210
systemd-tmpfiles --create %{_prefix}/lib/tmpfiles.d/%{name}.conf
%service_add_post %{name}.service
%fillup_only -n gearmand
%endif

%preun server
%stop_on_removal gearmand
if [ "$1" = 0 ] ; then
   %{_sbindir}/update-alternatives --remove "%{name}" "%{_sbindir}/%{name}"
fi
%service_del_preun %{name}.service

%postun server
%restart_on_update gearmand
%service_del_postun %{name}.service

%post server-mysql
%{_sbindir}/update-alternatives --install "%{_sbindir}/%{name}" "%{name}" "%{_sbindir}/%{name}-mysql" 30

%post server-postgresql
%{_sbindir}/update-alternatives --install "%{_sbindir}/%{name}" "%{name}" "%{_sbindir}/%{name}-postgresql" 20

%post server-sqlite3
%{_sbindir}/update-alternatives --install "%{_sbindir}/%{name}" "%{name}" "%{_sbindir}/%{name}-sqlite3" 10

%post server-redis
%{_sbindir}/update-alternatives --install "%{_sbindir}/%{name}" "%{name}" "%{_sbindir}/%{name}-redis" 10

%post server-memcached
%{_sbindir}/update-alternatives --install "%{_sbindir}/%{name}" "%{name}" "%{_sbindir}/%{name}-memcached" 10

%preun server-mysql
if [ "$1" = 0 ] ; then
   %{_sbindir}/update-alternatives --remove "%{name}" "%{_sbindir}/%{name}-mysql"
fi

%preun server-postgresql
if [ "$1" = 0 ] ; then
   %{_sbindir}/update-alternatives --remove "%{name}" "%{_sbindir}/%{name}-postgresql"
fi

%preun server-sqlite3
if [ "$1" = 0 ] ; then
   %{_sbindir}/update-alternatives --remove "%{name}" "%{_sbindir}/%{name}-sqlite3"
fi

%preun server-redis
if [ "$1" = 0 ] ; then
   %{_sbindir}/update-alternatives --remove "%{name}" "%{_sbindir}/%{name}-redis"
fi

%preun server-memcached
if [ "$1" = 0 ] ; then
   %{_sbindir}/update-alternatives --remove "%{name}" "%{_sbindir}/%{name}-memcached"
fi

%post   -n libgearman%{libversion} -p /sbin/ldconfig
%postun -n libgearman%{libversion} -p /sbin/ldconfig

%files server
%dir %{_defaultdocdir}/%{name}
%doc %{_defaultdocdir}/%{name}/*
%exclude %{_defaultdocdir}/%{name}/docs
%{_mandir}/man3/*
%{_mandir}/man8/*
%exclude %{_mandir}/man8/gearmand-*
%{_sbindir}/rcgearmand
%if 0%{?suse_version} < 1230
%{_sysconfdir}/init.d/gearmand
%endif
%if 0%{?suse_version} >= 1210
%{_unitdir}/%{name}.service
%endif
%if 0%{?suse_version} < 1500
%config %{_sysconfdir}/sysconfig/SuSEfirewall2.d/services/%{name}-server
%endif
%{_fillupdir}/sysconfig.gearmand
%config(noreplace) %{_sysconfdir}/logrotate.d/%{name}
%attr(-,%{gearmand_user},%{gearmand_group}) %dir %{_localstatedir}/log/gearmand
%attr(-,%{gearmand_user},%{gearmand_group}) %dir %{_localstatedir}/lib/gearman
%if 0%{?suse_version} < 1220
%ghost %attr(-,%{gearmand_user},%{gearmand_group}) %dir %{_rundir}/gearmand
%else
%{_tmpfilesdir}/%{name}.conf
%endif
%ghost %{_sysconfdir}/alternatives/%{name}

%files server-mysql
%{_sbindir}/gearmand-mysql
%ghost %{_sbindir}/gearmand
%{_mandir}/man8/gearmand-mysql*

%files server-postgresql
%{_sbindir}/gearmand-postgresql
%ghost %{_sbindir}/gearmand
%{_mandir}/man8/gearmand-postgresql*

%files server-sqlite3
%{_sbindir}/gearmand-sqlite3
%ghost %{_sbindir}/gearmand
%{_mandir}/man8/gearmand-sqlite3%{?ext_man}

%files server-redis
%{_sbindir}/gearmand-redis
%ghost %{_sbindir}/gearmand
%{_mandir}/man8/gearmand-redis*

%files server-memcached
%{_sbindir}/gearmand-memcached
%ghost %{_sbindir}/gearmand
%{_mandir}/man8/gearmand-memcached*

%files -n libgearman%{libversion}
%{_libdir}/libgearman.so.*

%files tools
%{_bindir}/gearman
%{_bindir}/gearadmin
%{_mandir}/man1/gearman*
%{_mandir}/man1/gearadmin.1%{?ext_man}

%files doc
%doc %{_defaultdocdir}/%{name}/docs

%files devel
%dir %{_includedir}/libgearman
%dir %{_includedir}/libgearman-1.0
%{_libdir}/pkgconfig/gearmand.pc
%{_includedir}/libgearman/*
%{_includedir}/libgearman-1.0/*
%{_libdir}/libgearman.la
%{_libdir}/libgearman.so

%changelog
openSUSE Build Service is sponsored by