Skip to content

Commit

Permalink
Merge pull request #226 from blukat29/ollie/rpm-systemd
Browse files Browse the repository at this point in the history
build: RPM package installs initscripts and systemd services
  • Loading branch information
blukat29 authored Feb 3, 2025
2 parents 0b59732 + 75f2f5b commit f713f14
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 1 deletion.
10 changes: 10 additions & 0 deletions build/rpm/etc/systemd/system/kbnd.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[Unit]
Description= kbnd Service

[Service]
Type=forking
ExecStart=/etc/init.d/kbnd start
ExecStop=/etc/init.d/kbnd stop

[Install]
WantedBy=multi-user.target
10 changes: 10 additions & 0 deletions build/rpm/etc/systemd/system/kcnd.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[Unit]
Description= kcnd Service

[Service]
Type=forking
ExecStart=/etc/init.d/kcnd start
ExecStop=/etc/init.d/kcnd stop

[Install]
WantedBy=multi-user.target
10 changes: 10 additions & 0 deletions build/rpm/etc/systemd/system/kend.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[Unit]
Description= kend Service

[Service]
Type=forking
ExecStart=/etc/init.d/kend start
ExecStop=/etc/init.d/kend stop

[Install]
WantedBy=multi-user.target
10 changes: 10 additions & 0 deletions build/rpm/etc/systemd/system/kpnd.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[Unit]
Description= kpnd Service

[Service]
Type=forking
ExecStart=/etc/init.d/kpnd start
ExecStop=/etc/init.d/kpnd stop

[Install]
WantedBy=multi-user.target
10 changes: 10 additions & 0 deletions build/rpm/etc/systemd/system/kscnd.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[Unit]
Description= kscnd Service

[Service]
Type=forking
ExecStart=/etc/init.d/kscnd start
ExecStop=/etc/init.d/kscnd stop

[Install]
WantedBy=multi-user.target
10 changes: 10 additions & 0 deletions build/rpm/etc/systemd/system/ksend.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[Unit]
Description= ksend Service

[Service]
Type=forking
ExecStart=/etc/init.d/ksend start
ExecStop=/etc/init.d/ksend stop

[Install]
WantedBy=multi-user.target
10 changes: 10 additions & 0 deletions build/rpm/etc/systemd/system/kspnd.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[Unit]
Description= kspnd Service

[Service]
Type=forking
ExecStart=/etc/init.d/kspnd start
ExecStop=/etc/init.d/kspnd stop

[Install]
WantedBy=multi-user.target
18 changes: 17 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,43 @@ 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
# /etc/init.d/{{ .DaemonName }} requires /etc/init.d/functions file to work. That is why 'initscripts' is required.
# Installing initscripts has two outcomes.
# case 1. symlink /etc/init.d -> /etc/rc.d/init.d created. No action needed.
# case 2. symlink /etc/init.d -> /etc/rc.d/init.d creation failed because /etc/init.d/ directory exists
# (e.g. kend.rpm v1.x was previously installed) If so, create symlink to 'functions'.
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
# rpm v1.x installs init.d only. rpm v2.0+ installs init.d and systemd.
# case 1. upgrading from v2.0 and systemctl works.
# case 2. upgrading from v1.x and init.d works.
# case 3. upgrading from v1.x and init.d fails (e.g. In Rocky Linux, init.d fails without systemd)
(systemctl stop {{ .DaemonName }}.service || /etc/init.d/{{ .DaemonName }} stop || true) > /dev/null 2>&1
fi
%endif
Expand Down

0 comments on commit f713f14

Please sign in to comment.