Add default service config
This commit is contained in:
parent
227e11be02
commit
1ef1e09b8d
8 changed files with 198 additions and 19 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue