Skip to content

Commit 0687365

Browse files
authored
Merge pull request #5235 from sysown/v3.0.4-rpm_spec_rework
rework spec files, use rpm macros to handle systemd
2 parents 876d4ad + b2b8fbf commit 0687365

2 files changed

Lines changed: 73 additions & 90 deletions

File tree

Lines changed: 37 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
# we don't want separate debuginfo packages
2+
%global _enable_debug_package 0
3+
%define debug_package %{nil}
4+
# do not strip binaries
5+
%global __strip /bin/true
16
%define __spec_install_post %{nil}
2-
%define debug_package %{nil}
3-
%define __os_install_post %{_dbpath}/brp-compress
7+
%define __os_install_post %{_dbpath}/brp-compress %{nil}
48

59
Summary: A high-performance MySQL and PostgreSQL proxy
610
Name: proxysql
@@ -9,8 +13,12 @@ Release: 1
913
License: GPL-3.0-only
1014
Source: %{name}-%{version}.tar.gz
1115
URL: https://proxysql.com/
12-
Requires: gnutls, (openssl >= 3.0.0 or openssl3 >= 3.0.0)
16+
Requires: gnutls
17+
Requires: (openssl >= 3.0.0 or openssl3 >= 3.0.0)
18+
#BuildRequires: systemd-rpm-macros
1319
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root
20+
Provides: user(%{name})
21+
Provides: group(%{name})
1422

1523
%description
1624
%{summary}
@@ -19,72 +27,56 @@ BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root
1927
%setup -q
2028

2129
%pre
22-
# Cleanup artifacts
23-
if [ -f /var/lib/%{name}/PROXYSQL_UPGRADE ]; then
24-
rm -fr /var/lib/%{name}/PROXYSQL_UPGRADE
25-
fi
30+
# setup user, group
31+
getent passwd %{name} &>/dev/null || useradd -r -U -s /bin/false -d /var/lib/%{name} -c "ProxySQL Server" %{name}
2632

2733
%build
2834
# Packages are pre-built, nothing to do
2935

3036
%install
37+
export DONT_STRIP=1
3138
# Clean buildroot and install files
32-
/bin/rm -rf %{buildroot}
33-
/bin/mkdir -p %{buildroot}
34-
/bin/cp -a * %{buildroot}
39+
rm -rf %{buildroot}
40+
mkdir -p %{buildroot}
41+
cp -a * %{buildroot}
42+
mkdir -p %{buildroot}/var/run/%{name}
43+
mkdir -p %{buildroot}/var/lib/%{name}
3544

3645
%clean
37-
/bin/rm -rf %{buildroot}
46+
rm -rf %{buildroot}
3847

3948
%post
40-
# Create relevant user, directories and configuration files
41-
if [ ! -d /var/run/%{name} ]; then /bin/mkdir /var/run/%{name} ; fi
42-
if [ ! -d /var/lib/%{name} ]; then /bin/mkdir /var/lib/%{name} ; fi
43-
if ! id -u %{name} > /dev/null 2>&1; then useradd -r -U -s /bin/false -d /var/lib/%{name} -c "ProxySQL Server" %{name}; fi
44-
/bin/chown -R %{name}: /var/lib/%{name} /var/run/%{name}
45-
/bin/chown root:%{name} /etc/%{name}.cnf
46-
/bin/chmod 640 /etc/%{name}.cnf
47-
# Configure systemd appropriately.
48-
/bin/systemctl daemon-reload
49-
/bin/systemctl enable %{name}.service
50-
# Notify that a package update is in progress in order to start service.
51-
if [ $1 -eq 2 ]; then /bin/touch /var/lib/%{name}/PROXYSQL_UPGRADE ; fi
49+
# install service
50+
%systemd_post %{name}.service
51+
#%systemd_post_with_reload %{name}.service
5252

5353
%preun
54-
# When uninstalling always try stop the service, ignore failures
55-
/bin/systemctl stop %{name} || true
54+
# remove service
55+
%systemd_preun %{name}.service
5656

5757
%postun
58-
if [ $1 -eq 0 ]; then
59-
# This is a pure uninstall, systemd unit file removed
60-
# only daemon-reload is needed.
61-
/bin/systemctl daemon-reload
62-
else
63-
# This is an upgrade, ProxySQL should be started. This
64-
# logic works for packages newer than 2.0.7 and ensures
65-
# a faster restart time.
66-
/bin/systemctl start %{name}.service
67-
/bin/rm -fr /var/lib/%{name}/PROXYSQL_UPGRADE
68-
fi
58+
# remove user, group on uninstall
59+
# dont, its against the recommended practice
60+
#if [ "$1" == "0" ]; then
61+
# groupdel %{name}
62+
# userdel %{name}
63+
#fi
6964

7065
%posttrans
71-
if [ -f /var/lib/%{name}/PROXYSQL_UPGRADE ]; then
72-
# This is a safeguard to start the service after an update
73-
# which supports legacy "preun" / "postun" logic and will
74-
# only execute for packages before 2.0.7.
75-
/bin/systemctl start %{name}.service
76-
/bin/rm -fr /var/lib/%{name}/PROXYSQL_UPGRADE
77-
fi
66+
# reload, restart service
67+
#%systemd_posttrans_with_reload %{name}.service
68+
#%systemd_posttrans_with_restart %{name}.service
7869

7970
%files
8071
%defattr(-,root,root,-)
81-
%config(noreplace) %{_sysconfdir}/%{name}.cnf
82-
%attr(640,root,%{name}) %{_sysconfdir}/%{name}.cnf
72+
%config(noreplace) %attr(640,root,%{name}) %{_sysconfdir}/%{name}.cnf
8373
%config(noreplace) %attr(640,root,%{name}) %{_sysconfdir}/logrotate.d/%{name}
8474
%{_bindir}/*
8575
%{_sysconfdir}/systemd/system/%{name}.service
8676
%{_sysconfdir}/systemd/system/%{name}-initial.service
8777
/usr/share/proxysql/tools/proxysql_galera_checker.sh
8878
/usr/share/proxysql/tools/proxysql_galera_writer.pl
79+
%config(noreplace) %attr(750,%{name},%{name}) /var/run/%{name}/
80+
%config(noreplace) %attr(750,%{name},%{name}) /var/lib/%{name}/
8981

9082
%changelog
Lines changed: 36 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
# we don't want separate debuginfo packages
2+
%global _enable_debug_package 0
3+
%define debug_package %{nil}
4+
# do not strip binaries
5+
%global __strip /bin/true
16
%define __spec_install_post %{nil}
2-
%define debug_package %{nil}
3-
%define __os_install_post %{_dbpath}/brp-compress
7+
%define __os_install_post %{_dbpath}/brp-compress %{nil}
48

59
Summary: A high-performance MySQL and PostgreSQL proxy
610
Name: proxysql
@@ -9,8 +13,11 @@ Release: 1
913
License: GPL-3.0-only
1014
Source: %{name}-%{version}.tar.gz
1115
URL: https://proxysql.com/
12-
Requires: gnutls, (openssl >= 3.0.0 or openssl3 >= 3.0.0)
16+
Requires: gnutls
17+
Requires: (openssl >= 3.0.0 or openssl3 >= 3.0.0)
18+
#BuildRequires: systemd-rpm-macros
1319
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root
20+
Provides: user(%{name})
1421
Provides: group(%{name})
1522

1623
%description
@@ -20,72 +27,56 @@ Provides: group(%{name})
2027
%setup -q
2128

2229
%pre
23-
# Cleanup artifacts
24-
if [ -f /var/lib/%{name}/PROXYSQL_UPGRADE ]; then
25-
rm -fr /var/lib/%{name}/PROXYSQL_UPGRADE
26-
fi
27-
if ! id -u %{name} > /dev/null 2>&1; then useradd -r -U -s /bin/false -d /var/lib/%{name} -c "ProxySQL Server" %{name}; fi
30+
# setup user, group
31+
getent passwd %{name} &>/dev/null || useradd -r -U -s /bin/false -d /var/lib/%{name} -c "ProxySQL Server" %{name}
2832

2933
%build
3034
# Packages are pre-built, nothing to do
3135

3236
%install
37+
export DONT_STRIP=1
3338
# Clean buildroot and install files
34-
/bin/rm -rf %{buildroot}
35-
/bin/mkdir -p %{buildroot}
36-
/bin/cp -a * %{buildroot}
39+
rm -rf %{buildroot}
40+
mkdir -p %{buildroot}
41+
cp -a * %{buildroot}
42+
mkdir -p %{buildroot}/var/run/%{name}
43+
mkdir -p %{buildroot}/var/lib/%{name}
3744

3845
%clean
39-
/bin/rm -rf %{buildroot}
46+
rm -rf %{buildroot}
4047

4148
%post
42-
# Create relevant user, directories and configuration files
43-
if [ ! -d /var/run/%{name} ]; then /bin/mkdir /var/run/%{name} ; fi
44-
if [ ! -d /var/lib/%{name} ]; then /bin/mkdir /var/lib/%{name} ; fi
45-
/bin/chown -R %{name}: /var/lib/%{name} /var/run/%{name}
46-
/bin/chown root:%{name} /etc/%{name}.cnf
47-
/bin/chmod 640 /etc/%{name}.cnf
48-
# Configure systemd appropriately.
49-
/bin/systemctl daemon-reload
50-
/bin/systemctl enable %{name}.service
51-
# Notify that a package update is in progress in order to start service.
52-
if [ $1 -eq 2 ]; then /bin/touch /var/lib/%{name}/PROXYSQL_UPGRADE ; fi
49+
# install service
50+
%systemd_post %{name}.service
51+
#%systemd_post_with_reload %{name}.service
5352

5453
%preun
55-
# When uninstalling always try stop the service, ignore failures
56-
/bin/systemctl stop %{name} || true
54+
# remove service
55+
%systemd_preun %{name}.service
5756

5857
%postun
59-
if [ $1 -eq 0 ]; then
60-
# This is a pure uninstall, systemd unit file removed
61-
# only daemon-reload is needed.
62-
/bin/systemctl daemon-reload
63-
else
64-
# This is an upgrade, ProxySQL should be started. This
65-
# logic works for packages newer than 2.0.7 and ensures
66-
# a faster restart time.
67-
/bin/systemctl start %{name}.service
68-
/bin/rm -fr /var/lib/%{name}/PROXYSQL_UPGRADE
69-
fi
58+
# remove user, group on uninstall
59+
# dont, its against the recommended practice
60+
#if [ "$1" == "0" ]; then
61+
# groupdel %{name}
62+
# userdel %{name}
63+
#fi
7064

7165
%posttrans
72-
if [ -f /var/lib/%{name}/PROXYSQL_UPGRADE ]; then
73-
# This is a safeguard to start the service after an update
74-
# which supports legacy "preun" / "postun" logic and will
75-
# only execute for packages before 2.0.7.
76-
/bin/systemctl start %{name}.service
77-
/bin/rm -fr /var/lib/%{name}/PROXYSQL_UPGRADE
78-
fi
66+
# reload, restart service
67+
#%systemd_posttrans_with_reload %{name}.service
68+
#%systemd_posttrans_with_restart %{name}.service
7969

8070
%files
8171
%defattr(-,root,root,-)
82-
%config(noreplace) %{_sysconfdir}/%{name}.cnf
83-
%attr(640,root,%{name}) %{_sysconfdir}/%{name}.cnf
72+
%config(noreplace) %attr(640,root,%{name}) %{_sysconfdir}/%{name}.cnf
8473
%config(noreplace) %attr(640,root,%{name}) %{_sysconfdir}/logrotate.d/%{name}
8574
%{_bindir}/*
8675
%{_sysconfdir}/systemd/system/%{name}.service
8776
%{_sysconfdir}/systemd/system/%{name}-initial.service
8877
/usr/share/proxysql/tools/proxysql_galera_checker.sh
8978
/usr/share/proxysql/tools/proxysql_galera_writer.pl
79+
%config(noreplace) %attr(750,%{name},%{name}) /var/run/%{name}/
80+
%config(noreplace) %attr(750,%{name},%{name}) /var/lib/%{name}/
9081

9182
%changelog

0 commit comments

Comments
 (0)