Use systemd scriptlets in rpxy.spec
This commit is contained in:
parent
120ad601c1
commit
06d9cdf7e7
1 changed files with 34 additions and 42 deletions
|
|
@ -13,74 +13,66 @@ Requires: systemd
|
||||||
%description
|
%description
|
||||||
This rpm installs rpxy into /usr/bin and sets up a systemd service.
|
This rpm installs rpxy into /usr/bin and sets up a systemd service.
|
||||||
|
|
||||||
|
# Prep section: Unpack the source
|
||||||
%prep
|
%prep
|
||||||
%autosetup
|
%autosetup
|
||||||
|
|
||||||
|
# Install section: Copy files to their destinations
|
||||||
%install
|
%install
|
||||||
rm -rf %{buildroot}
|
rm -rf %{buildroot}
|
||||||
# Copy binary
|
|
||||||
mkdir -p %{buildroot}%{_bindir}
|
|
||||||
cp rpxy %{buildroot}%{_bindir}/
|
|
||||||
# Create systemd service
|
|
||||||
mkdir -p %{buildroot}%{_sysconfdir}/systemd/system
|
|
||||||
cp rpxy.service %{buildroot}%{_sysconfdir}/systemd/system/
|
|
||||||
# Create config directory
|
|
||||||
mkdir -p %{buildroot}%{_sysconfdir}/rpxy/acme_registry
|
|
||||||
cp config.toml %{buildroot}%{_sysconfdir}/rpxy/
|
|
||||||
# Copy documentation
|
|
||||||
mkdir -p %{buildroot}%{_docdir}/rpxy
|
|
||||||
cp LICENSE %{buildroot}%{_docdir}/rpxy/
|
|
||||||
cp README.md %{buildroot}%{_docdir}/rpxy/
|
|
||||||
|
|
||||||
|
# Create necessary directories
|
||||||
|
mkdir -p %{buildroot}%{_bindir}
|
||||||
|
mkdir -p %{buildroot}%{_sysconfdir}/systemd/system
|
||||||
|
mkdir -p %{buildroot}%{_sysconfdir}/rpxy/acme_registry
|
||||||
|
mkdir -p %{buildroot}%{_docdir}/rpxy
|
||||||
|
|
||||||
|
# Copy files
|
||||||
|
cp rpxy %{buildroot}%{_bindir}/
|
||||||
|
cp rpxy.service %{buildroot}%{_sysconfdir}/systemd/system/
|
||||||
|
cp config.toml %{buildroot}%{_sysconfdir}/rpxy/
|
||||||
|
cp LICENSE README.md %{buildroot}%{_docdir}/rpxy/
|
||||||
|
|
||||||
|
# Clean section: Remove buildroot
|
||||||
%clean
|
%clean
|
||||||
rm -rf %{buildroot}
|
rm -rf %{buildroot}
|
||||||
|
|
||||||
|
# Pre-install script
|
||||||
%pre
|
%pre
|
||||||
# Create the rpxy user if it does not exist
|
# Create the rpxy user if it does not exist
|
||||||
if ! id rpxy >/dev/null 2>&1; then
|
if ! getent passwd rpxy >/dev/null; then
|
||||||
/usr/sbin/useradd -r -s /bin/false -d / -c "rpxy system user" rpxy
|
useradd -r -s /sbin/nologin -d / -c "rpxy system user" rpxy
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Post-install script
|
||||||
%post
|
%post
|
||||||
# Set ownership of config file to rpxy user
|
# Set ownership of config file to rpxy user
|
||||||
chown -R rpxy:rpxy %{_sysconfdir}/rpxy
|
chown -R rpxy:rpxy %{_sysconfdir}/rpxy
|
||||||
|
|
||||||
# Reload systemd, enable and start rpxy service
|
# Reload systemd, enable and start rpxy service
|
||||||
systemctl daemon-reload
|
%systemd_post rpxy.service
|
||||||
systemctl enable rpxy
|
|
||||||
if [ $1 -eq 1 ]; then
|
|
||||||
systemctl start rpxy
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
# Pre-uninstall script
|
||||||
%preun
|
%preun
|
||||||
# Stop the service on uninstall or upgrade
|
%systemd_preun rpxy.service
|
||||||
if [ $1 -eq 0 ]; then
|
|
||||||
systemctl stop rpxy
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
# Post-uninstall script
|
||||||
%postun
|
%postun
|
||||||
# On uninstall, disable the service and reload systemd
|
%systemd_postun_with_restart rpxy.service
|
||||||
|
|
||||||
|
# Only remove user and config on full uninstall
|
||||||
if [ $1 -eq 0 ]; then
|
if [ $1 -eq 0 ]; then
|
||||||
systemctl disable rpxy
|
# Remove rpxy user
|
||||||
systemctl daemon-reload
|
userdel rpxy
|
||||||
fi
|
|
||||||
|
# Remove the configuration directory if it exists
|
||||||
# Remove rpxy user only if package is being completely removed (not upgraded)
|
[ -d %{_sysconfdir}/rpxy ] && rm -rf %{_sysconfdir}/rpxy
|
||||||
if [ $1 -eq 0 ]; then
|
|
||||||
# Check if the rpxy user exists before attempting to delete
|
|
||||||
if id rpxy >/dev/null 2>&1; then
|
|
||||||
/usr/sbin/userdel rpxy
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Remove the configuration directory if it exists and is empty
|
|
||||||
if [ -d %{_sysconfdir}/rpxy ]; then
|
|
||||||
rm -rf %{_sysconfdir}/rpxy
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Files section: List all files included in the package
|
||||||
%files
|
%files
|
||||||
%license %{_docdir}/rpxy/LICENSE
|
%license %{_docdir}/rpxy/LICENSE
|
||||||
%doc %{_docdir}/rpxy/README.md
|
%doc %{_docdir}/rpxy/README.md
|
||||||
%{_sysconfdir}/systemd/system/rpxy.service
|
%{_sysconfdir}/systemd/system/rpxy.service
|
||||||
%attr(-, rpxy, rpxy) %{_bindir}/rpxy
|
%attr(755, rpxy, rpxy) %{_bindir}/rpxy
|
||||||
%attr(-, rpxy, rpxy) %config(noreplace) %{_sysconfdir}/rpxy/config.toml
|
%attr(644, rpxy, rpxy) %config(noreplace) %{_sysconfdir}/rpxy/config.toml
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue