Skip to content

Commit

Permalink
build: rpm installs initscripts and systemd services
Browse files Browse the repository at this point in the history
  • Loading branch information
blukat29 committed Jan 23, 2025
1 parent b185151 commit b65cc1c
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion build/rpm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ License: GNU
URL: https://kaia.io
Source0: %{name}-%{version}.tar.gz
BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX)
Requires: initscripts
%global debug_package %{nil}
Expand All @@ -224,28 +225,40 @@ mkdir -p $RPM_BUILD_ROOT/usr/bin
mkdir -p $RPM_BUILD_ROOT/etc/{{ .DaemonName }}/conf
mkdir -p $RPM_BUILD_ROOT/etc/init.d
mkdir -p $RPM_BUILD_ROOT/var/log/{{ .DaemonName }}
mkdir -p $RPM_BUILD_ROOT/etc/systemd/system
cp build/bin/{{ .ProgramName }} $RPM_BUILD_ROOT/usr/bin/{{ .ProgramName }}
%if %is_daemon
cp build/rpm/etc/init.d/{{ .DaemonName }} $RPM_BUILD_ROOT/etc/init.d/{{ .DaemonName }}
cp build/rpm/etc/{{ .DaemonName }}/conf/{{ .DaemonName }}{{ .PostFix }}.conf $RPM_BUILD_ROOT/etc/{{ .DaemonName }}/conf/{{ .DaemonName }}.conf
cp build/rpm/etc/systemd/system/{{ .DaemonName }}.service $RPM_BUILD_ROOT/etc/systemd/system/{{ .DaemonName }}.service
%endif
%files
%attr(755, -, -) /usr/bin/{{ .ProgramName }}
%if %is_daemon
%config(noreplace) %attr(644, -, -) /etc/{{ .DaemonName }}/conf/{{ .DaemonName }}.conf
%attr(754, -, -) /etc/init.d/{{ .DaemonName }}
%attr(644, -, -) /etc/systemd/system/{{ .DaemonName }}.service
%endif
%exclude /usr/local/var/lib/rpm/*
%exclude /usr/local/var/lib/rpm/.*
%exclude /usr/local/var/tmp/*
%pre
# The package 'initscripts' will install 'functions' file. But if /etc/init.d/ directory already existed
# (e.g. if kend v1.x was installed before), installing 'initscripts' partially fails
# so that 'functions' file only installed under /etc/rc.d/init.d but not under /etc/init.d.
# Since /etc/init.d/{{ .DaemonName }} requires it, create a symlink as a workaround.
if [ -d /etc/init.d ] && [ ! -e /etc/init.d/functions ]; then
ln -s /etc/rc.d/init.d/functions /etc/init.d/functions
fi
%if %is_daemon
if [ $1 -eq 2 ]; then
# Package upgrade
systemctl stop {{ .DaemonName }}.service > /dev/null 2>&1
# systemd (systemctl) may fail before kend v2.0 due to absence of systemd files.
# In that case, fall back to SysV (/etc/init.d).
(systemctl stop {{ .DaemonName }}.service || /etc/init.d/{{ .DaemonName }} stop) > /dev/null 2>&1
fi
%endif
Expand Down

0 comments on commit b65cc1c

Please sign in to comment.