%global _hardened_build 1
%if 0%{?rhel} && 0%{?rhel} <= 6
%global systemd_enabled 0
%else
%global systemd_enabled 1
%endif
%global _varrundir %{_localstatedir}/run/%{name}
Name: pgbouncer
Version: 1.8.1
Release: 4%{?dist}
Summary: Lightweight connection pooler for PostgreSQL
License: MIT and BSD
URL: https://pgbouncer.github.io/
Source0: https://pgbouncer.github.io/downloads/files/%{version}/%{name}-%{version}.tar.gz
Source1: %{name}.init
Source2: %{name}.sysconfig
Source3: %{name}.logrotate
Source4: %{name}.service
Patch0: %{name}-ini.patch
BuildRequires: gcc
BuildRequires: libevent-devel >= 2.0 openssl-devel
%if %{systemd_enabled}
BuildRequires: systemd, systemd-units
# We require this to be present for %%{_prefix}/lib/tmpfiles.d
Requires: systemd
Requires(post): systemd-sysv
Requires(post): systemd
Requires(preun): systemd
Requires(postun): systemd
%else
Requires(post): chkconfig
Requires(preun): chkconfig
# This is for /sbin/service
Requires(preun): initscripts
Requires(postun): initscripts
%endif
Requires: /usr/sbin/useradd
%description
pgbouncer is a lightweight connection pooler for PostgreSQL.
pgbouncer uses libevent for low-level socket handling.
%prep
%setup -q
%patch0 -p0
%build
sed -i.fedora \
-e 's|-fomit-frame-pointer||' \
-e '/BININSTALL/s|-s||' \
configure
%configure --datadir=%{_datadir} --with-pam
make %{?_smp_mflags} V=1
%install
make install DESTDIR=%{buildroot}
# Install sysconfig file
install -p -d %{buildroot}%{_sysconfdir}/%{name}/
install -p -d %{buildroot}%{_sysconfdir}/sysconfig
install -p -m 644 %{SOURCE2} %{buildroot}%{_sysconfdir}/sysconfig/%{name}
install -p -m 644 etc/pgbouncer.ini %{buildroot}%{_sysconfdir}/%{name}
install -p -m 700 etc/mkauth.py %{buildroot}%{_sysconfdir}/%{name}/
%if %{systemd_enabled}
install -d %{buildroot}%{_unitdir}
install -m 644 %{SOURCE4} %{buildroot}%{_unitdir}/%{name}.service
# ... and make a tmpfiles script to recreate it at reboot.
%{__mkdir} -p %{buildroot}%{_tmpfilesdir}
cat > %{buildroot}%{_tmpfilesdir}/%{name}.conf <<EOF
d %{_varrundir} 0700 pgbouncer pgbouncer -
EOF
%else
install -p -d %{buildroot}%{_initrddir}
install -p -m 755 %{SOURCE1} %{buildroot}%{_initrddir}/%{name}
%endif
# Install logrotate file:
install -p -d %{buildroot}%{_sysconfdir}/logrotate.d
install -p -m 644 %{SOURCE3} %{buildroot}%{_sysconfdir}/logrotate.d/%{name}
# Remove duplicated files
%{__rm} -f %{buildroot}%{_docdir}/%{name}/pgbouncer.ini
%{__rm} -f %{buildroot}%{_docdir}/%{name}/NEWS
%{__rm} -f %{buildroot}%{_docdir}/%{name}/README
%{__rm} -f %{buildroot}%{_docdir}/%{name}/userlist.txt
%post
%if %{systemd_enabled}
%systemd_post %{name}.service
%tmpfiles_create
%else
# This adds the proper /etc/rc*.d links for the script
/sbin/chkconfig --add %{name}
%endif
%{__mkdir} -m 700 %{_localstatedir}/log/pgbouncer
%{__chown} -R pgbouncer:pgbouncer %{_localstatedir}/log/pgbouncer
%{__chown} -R pgbouncer:pgbouncer %{_varrundir} >/dev/null 2>&1 || :
%pre
groupadd -r pgbouncer >/dev/null 2>&1 || :
useradd -m -g pgbouncer -r -s /bin/bash \
-c "PgBouncer Server" pgbouncer >/dev/null 2>&1 || :
%preun
%if %{systemd_enabled}
%systemd_preun %{name}.service
%else
if [ $1 -eq 0 ] ; then
/sbin/service pgbouncer condstop >/dev/null 2>&1
chkconfig --del pgbouncer
fi
%endif
%postun
%{__rm} -rf /var/run/pgbouncer
%if %{systemd_enabled}
%systemd_postun_with_restart %{name}.service
%else
if [ $1 -ge 1 ] ; then
/sbin/service pgbouncer condrestart >/dev/null 2>&1 || :
fi
%endif
%files
%doc README.rst NEWS.rst
%if %{systemd_enabled}
%license COPYRIGHT
%endif
%dir %{_sysconfdir}/%{name}
%{_bindir}/%{name}
%config(noreplace) %{_sysconfdir}/%{name}/%{name}.ini
%if %{systemd_enabled}
%ghost %{_varrundir}
%{_tmpfilesdir}/%{name}.conf
%attr(644,root,root) %{_unitdir}/%{name}.service
%else
%{_initrddir}/%{name}
%endif
%config(noreplace) %{_sysconfdir}/sysconfig/%{name}
%config(noreplace) %{_sysconfdir}/logrotate.d/%{name}
%{_mandir}/man1/%{name}.*
%{_mandir}/man5/%{name}.*
%{_sysconfdir}/%{name}/mkauth.py*
%changelog
* Fri Jul 13 2018 Fedora Release Engineering <releng@fedoraproject.org> - 1.8.1-4
- Rebuilt for https://fedoraproject.org/wiki/Fedora_29_Mass_Rebuild
* Mon Jun 18 2018 Devrim Gündüz <devrim@gunduz.org> - 1.8.1-3
- Remove initscripts dependency, per bz #1592382
* Fri Feb 09 2018 Filipe Rosset <rosset.filipe@gmail.com> - 1.8.1-2
- rebuilt with pam support
* Fri Feb 09 2018 Filipe Rosset <rosset.filipe@gmail.com> - 1.8.1-1
- Bump to 1.8.1
* Fri Feb 09 2018 Fedora Release Engineering <releng@fedoraproject.org> - 1.7.2-5
- Rebuilt for https://fedoraproject.org/wiki/Fedora_28_Mass_Rebuild
* Thu Aug 03 2017 Fedora Release Engineering <releng@fedoraproject.org> - 1.7.2-4
- Rebuilt for https://fedoraproject.org/wiki/Fedora_27_Binutils_Mass_Rebuild
* Thu Jul 27 2017 Fedora Release Engineering <releng@fedoraproject.org> - 1.7.2-3
- Rebuilt for https://fedoraproject.org/wiki/Fedora_27_Mass_Rebuild
* Sat Feb 11 2017 Fedora Release Engineering <releng@fedoraproject.org> - 1.7.2-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_26_Mass_Rebuild
* Thu Feb 25 2016 Devrim Gündüz <devrim@gunduz.org> - 1.7.2-1
- Update to 1.7.2
* Mon Feb 22 2016 Devrim Gündüz <devrim@gunduz.org> - 1.7.1-1
- Update to 1.7.1
* Thu Feb 04 2016 Fedora Release Engineering <releng@fedoraproject.org> - 1.6.1-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_24_Mass_Rebuild
* Fri Sep 11 2015 Devrim Gündüz <devrim@gunduz.org> - 1.6.1-1
- Update to 1.6.1
- Merge with community spec file:
- Add systemd support
- Create unified spec file for all distros
- Trim changelog