rework spec files, use rpm macros to handle systemd

pull/5235/head
Miro Stauder 5 months ago
parent 5d2d26d74e
commit b2b8fbf950

@ -1,6 +1,10 @@
# we don't want separate debuginfo packages
%global _enable_debug_package 0
%define debug_package %{nil}
# do not strip binaries
%global __strip /bin/true
%define __spec_install_post %{nil} %define __spec_install_post %{nil}
%define debug_package %{nil} %define __os_install_post %{_dbpath}/brp-compress %{nil}
%define __os_install_post %{_dbpath}/brp-compress
Summary: A high-performance MySQL and PostgreSQL proxy Summary: A high-performance MySQL and PostgreSQL proxy
Name: proxysql Name: proxysql
@ -9,8 +13,12 @@ Release: 1
License: GPL-3.0-only License: GPL-3.0-only
Source: %{name}-%{version}.tar.gz Source: %{name}-%{version}.tar.gz
URL: https://proxysql.com/ URL: https://proxysql.com/
Requires: gnutls, (openssl >= 3.0.0 or openssl3 >= 3.0.0) Requires: gnutls
Requires: (openssl >= 3.0.0 or openssl3 >= 3.0.0)
#BuildRequires: systemd-rpm-macros
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root
Provides: user(%{name})
Provides: group(%{name})
%description %description
%{summary} %{summary}
@ -19,72 +27,56 @@ BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root
%setup -q %setup -q
%pre %pre
# Cleanup artifacts # setup user, group
if [ -f /var/lib/%{name}/PROXYSQL_UPGRADE ]; then getent passwd %{name} &>/dev/null || useradd -r -U -s /bin/false -d /var/lib/%{name} -c "ProxySQL Server" %{name}
rm -fr /var/lib/%{name}/PROXYSQL_UPGRADE
fi
%build %build
# Packages are pre-built, nothing to do # Packages are pre-built, nothing to do
%install %install
export DONT_STRIP=1
# Clean buildroot and install files # Clean buildroot and install files
/bin/rm -rf %{buildroot} rm -rf %{buildroot}
/bin/mkdir -p %{buildroot} mkdir -p %{buildroot}
/bin/cp -a * %{buildroot} cp -a * %{buildroot}
mkdir -p %{buildroot}/var/run/%{name}
mkdir -p %{buildroot}/var/lib/%{name}
%clean %clean
/bin/rm -rf %{buildroot} rm -rf %{buildroot}
%post %post
# Create relevant user, directories and configuration files # install service
if [ ! -d /var/run/%{name} ]; then /bin/mkdir /var/run/%{name} ; fi %systemd_post %{name}.service
if [ ! -d /var/lib/%{name} ]; then /bin/mkdir /var/lib/%{name} ; fi #%systemd_post_with_reload %{name}.service
if ! id -u %{name} > /dev/null 2>&1; then useradd -r -U -s /bin/false -d /var/lib/%{name} -c "ProxySQL Server" %{name}; fi
/bin/chown -R %{name}: /var/lib/%{name} /var/run/%{name}
/bin/chown root:%{name} /etc/%{name}.cnf
/bin/chmod 640 /etc/%{name}.cnf
# Configure systemd appropriately.
/bin/systemctl daemon-reload
/bin/systemctl enable %{name}.service
# Notify that a package update is in progress in order to start service.
if [ $1 -eq 2 ]; then /bin/touch /var/lib/%{name}/PROXYSQL_UPGRADE ; fi
%preun %preun
# When uninstalling always try stop the service, ignore failures # remove service
/bin/systemctl stop %{name} || true %systemd_preun %{name}.service
%postun %postun
if [ $1 -eq 0 ]; then # remove user, group on uninstall
# This is a pure uninstall, systemd unit file removed # dont, its against the recommended practice
# only daemon-reload is needed. #if [ "$1" == "0" ]; then
/bin/systemctl daemon-reload # groupdel %{name}
else # userdel %{name}
# This is an upgrade, ProxySQL should be started. This #fi
# logic works for packages newer than 2.0.7 and ensures
# a faster restart time.
/bin/systemctl start %{name}.service
/bin/rm -fr /var/lib/%{name}/PROXYSQL_UPGRADE
fi
%posttrans %posttrans
if [ -f /var/lib/%{name}/PROXYSQL_UPGRADE ]; then # reload, restart service
# This is a safeguard to start the service after an update #%systemd_posttrans_with_reload %{name}.service
# which supports legacy "preun" / "postun" logic and will #%systemd_posttrans_with_restart %{name}.service
# only execute for packages before 2.0.7.
/bin/systemctl start %{name}.service
/bin/rm -fr /var/lib/%{name}/PROXYSQL_UPGRADE
fi
%files %files
%defattr(-,root,root,-) %defattr(-,root,root,-)
%config(noreplace) %{_sysconfdir}/%{name}.cnf %config(noreplace) %attr(640,root,%{name}) %{_sysconfdir}/%{name}.cnf
%attr(640,root,%{name}) %{_sysconfdir}/%{name}.cnf
%config(noreplace) %attr(640,root,%{name}) %{_sysconfdir}/logrotate.d/%{name} %config(noreplace) %attr(640,root,%{name}) %{_sysconfdir}/logrotate.d/%{name}
%{_bindir}/* %{_bindir}/*
%{_sysconfdir}/systemd/system/%{name}.service %{_sysconfdir}/systemd/system/%{name}.service
%{_sysconfdir}/systemd/system/%{name}-initial.service %{_sysconfdir}/systemd/system/%{name}-initial.service
/usr/share/proxysql/tools/proxysql_galera_checker.sh /usr/share/proxysql/tools/proxysql_galera_checker.sh
/usr/share/proxysql/tools/proxysql_galera_writer.pl /usr/share/proxysql/tools/proxysql_galera_writer.pl
%config(noreplace) %attr(750,%{name},%{name}) /var/run/%{name}/
%config(noreplace) %attr(750,%{name},%{name}) /var/lib/%{name}/
%changelog %changelog

@ -1,6 +1,10 @@
# we don't want separate debuginfo packages
%global _enable_debug_package 0
%define debug_package %{nil}
# do not strip binaries
%global __strip /bin/true
%define __spec_install_post %{nil} %define __spec_install_post %{nil}
%define debug_package %{nil} %define __os_install_post %{_dbpath}/brp-compress %{nil}
%define __os_install_post %{_dbpath}/brp-compress
Summary: A high-performance MySQL and PostgreSQL proxy Summary: A high-performance MySQL and PostgreSQL proxy
Name: proxysql Name: proxysql
@ -9,8 +13,11 @@ Release: 1
License: GPL-3.0-only License: GPL-3.0-only
Source: %{name}-%{version}.tar.gz Source: %{name}-%{version}.tar.gz
URL: https://proxysql.com/ URL: https://proxysql.com/
Requires: gnutls, (openssl >= 3.0.0 or openssl3 >= 3.0.0) Requires: gnutls
Requires: (openssl >= 3.0.0 or openssl3 >= 3.0.0)
#BuildRequires: systemd-rpm-macros
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root
Provides: user(%{name})
Provides: group(%{name}) Provides: group(%{name})
%description %description
@ -20,72 +27,56 @@ Provides: group(%{name})
%setup -q %setup -q
%pre %pre
# Cleanup artifacts # setup user, group
if [ -f /var/lib/%{name}/PROXYSQL_UPGRADE ]; then getent passwd %{name} &>/dev/null || useradd -r -U -s /bin/false -d /var/lib/%{name} -c "ProxySQL Server" %{name}
rm -fr /var/lib/%{name}/PROXYSQL_UPGRADE
fi
if ! id -u %{name} > /dev/null 2>&1; then useradd -r -U -s /bin/false -d /var/lib/%{name} -c "ProxySQL Server" %{name}; fi
%build %build
# Packages are pre-built, nothing to do # Packages are pre-built, nothing to do
%install %install
export DONT_STRIP=1
# Clean buildroot and install files # Clean buildroot and install files
/bin/rm -rf %{buildroot} rm -rf %{buildroot}
/bin/mkdir -p %{buildroot} mkdir -p %{buildroot}
/bin/cp -a * %{buildroot} cp -a * %{buildroot}
mkdir -p %{buildroot}/var/run/%{name}
mkdir -p %{buildroot}/var/lib/%{name}
%clean %clean
/bin/rm -rf %{buildroot} rm -rf %{buildroot}
%post %post
# Create relevant user, directories and configuration files # install service
if [ ! -d /var/run/%{name} ]; then /bin/mkdir /var/run/%{name} ; fi %systemd_post %{name}.service
if [ ! -d /var/lib/%{name} ]; then /bin/mkdir /var/lib/%{name} ; fi #%systemd_post_with_reload %{name}.service
/bin/chown -R %{name}: /var/lib/%{name} /var/run/%{name}
/bin/chown root:%{name} /etc/%{name}.cnf
/bin/chmod 640 /etc/%{name}.cnf
# Configure systemd appropriately.
/bin/systemctl daemon-reload
/bin/systemctl enable %{name}.service
# Notify that a package update is in progress in order to start service.
if [ $1 -eq 2 ]; then /bin/touch /var/lib/%{name}/PROXYSQL_UPGRADE ; fi
%preun %preun
# When uninstalling always try stop the service, ignore failures # remove service
/bin/systemctl stop %{name} || true %systemd_preun %{name}.service
%postun %postun
if [ $1 -eq 0 ]; then # remove user, group on uninstall
# This is a pure uninstall, systemd unit file removed # dont, its against the recommended practice
# only daemon-reload is needed. #if [ "$1" == "0" ]; then
/bin/systemctl daemon-reload # groupdel %{name}
else # userdel %{name}
# This is an upgrade, ProxySQL should be started. This #fi
# logic works for packages newer than 2.0.7 and ensures
# a faster restart time.
/bin/systemctl start %{name}.service
/bin/rm -fr /var/lib/%{name}/PROXYSQL_UPGRADE
fi
%posttrans %posttrans
if [ -f /var/lib/%{name}/PROXYSQL_UPGRADE ]; then # reload, restart service
# This is a safeguard to start the service after an update #%systemd_posttrans_with_reload %{name}.service
# which supports legacy "preun" / "postun" logic and will #%systemd_posttrans_with_restart %{name}.service
# only execute for packages before 2.0.7.
/bin/systemctl start %{name}.service
/bin/rm -fr /var/lib/%{name}/PROXYSQL_UPGRADE
fi
%files %files
%defattr(-,root,root,-) %defattr(-,root,root,-)
%config(noreplace) %{_sysconfdir}/%{name}.cnf %config(noreplace) %attr(640,root,%{name}) %{_sysconfdir}/%{name}.cnf
%attr(640,root,%{name}) %{_sysconfdir}/%{name}.cnf
%config(noreplace) %attr(640,root,%{name}) %{_sysconfdir}/logrotate.d/%{name} %config(noreplace) %attr(640,root,%{name}) %{_sysconfdir}/logrotate.d/%{name}
%{_bindir}/* %{_bindir}/*
%{_sysconfdir}/systemd/system/%{name}.service %{_sysconfdir}/systemd/system/%{name}.service
%{_sysconfdir}/systemd/system/%{name}-initial.service %{_sysconfdir}/systemd/system/%{name}-initial.service
/usr/share/proxysql/tools/proxysql_galera_checker.sh /usr/share/proxysql/tools/proxysql_galera_checker.sh
/usr/share/proxysql/tools/proxysql_galera_writer.pl /usr/share/proxysql/tools/proxysql_galera_writer.pl
%config(noreplace) %attr(750,%{name},%{name}) /var/run/%{name}/
%config(noreplace) %attr(750,%{name},%{name}) /var/lib/%{name}/
%changelog %changelog

Loading…
Cancel
Save