Add default service config

This commit is contained in:
Gamerboy59 2024-09-08 21:51:55 +02:00 committed by GitHub
commit 1ef1e09b8d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 198 additions and 19 deletions

View file

@ -18,10 +18,16 @@ This rpm installs rpxy into /usr/bin and sets up a systemd service.
%install
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/
@ -29,18 +35,52 @@ cp README.md %{buildroot}%{_docdir}/rpxy/
%clean
rm -rf %{buildroot}
%pre
# Create the rpxy user if it does not exist
if ! id rpxy >/dev/null 2>&1; then
/usr/sbin/useradd -r -s /bin/false -d / -c "rpxy system user" rpxy
fi
%post
# Set ownership of config file to rpxy user
chown -R rpxy:rpxy %{_sysconfdir}/rpxy
# Reload systemd, enable and start rpxy service
systemctl daemon-reload
systemctl enable rpxy
if [ $1 -eq 1 ]; then
systemctl start rpxy
fi
%preun
# Stop the service on uninstall or upgrade
if [ $1 -eq 0 ]; then
systemctl stop rpxy
fi
%postun
# On uninstall, disable the service and reload systemd
if [ $1 -eq 0 ]; then
systemctl disable rpxy
systemctl daemon-reload
fi
# Remove rpxy user only if package is being completely removed (not upgraded)
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
%files
%license %{_docdir}/rpxy/LICENSE
%doc %{_docdir}/rpxy/README.md
%{_bindir}/rpxy
%{_sysconfdir}/systemd/system/rpxy.service
%post
systemctl daemon-reload
systemctl enable rpxy
%preun
systemctl stop rpxy
%postun
systemctl disable rpxy
%attr(-, rpxy, rpxy) %{_bindir}/rpxy
%attr(-, rpxy, rpxy) %config(noreplace) %{_sysconfdir}/rpxy/config.toml