From b1851510b08292e732033edaaa5153dc71df319e Mon Sep 17 00:00:00 2001 From: Sotatek-TuLe2 Date: Thu, 9 Jan 2025 10:15:59 +0700 Subject: [PATCH 1/2] build: add systemd files for rpm package --- build/rpm/etc/systemd/system/kbnd.service | 10 ++++++++++ build/rpm/etc/systemd/system/kcnd.service | 10 ++++++++++ build/rpm/etc/systemd/system/kend.service | 10 ++++++++++ build/rpm/etc/systemd/system/kpnd.service | 10 ++++++++++ build/rpm/etc/systemd/system/kscnd.service | 10 ++++++++++ build/rpm/etc/systemd/system/ksend.service | 10 ++++++++++ build/rpm/etc/systemd/system/kspnd.service | 10 ++++++++++ 7 files changed, 70 insertions(+) create mode 100644 build/rpm/etc/systemd/system/kbnd.service create mode 100644 build/rpm/etc/systemd/system/kcnd.service create mode 100644 build/rpm/etc/systemd/system/kend.service create mode 100644 build/rpm/etc/systemd/system/kpnd.service create mode 100644 build/rpm/etc/systemd/system/kscnd.service create mode 100644 build/rpm/etc/systemd/system/ksend.service create mode 100644 build/rpm/etc/systemd/system/kspnd.service diff --git a/build/rpm/etc/systemd/system/kbnd.service b/build/rpm/etc/systemd/system/kbnd.service new file mode 100644 index 000000000..1557719c2 --- /dev/null +++ b/build/rpm/etc/systemd/system/kbnd.service @@ -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 \ No newline at end of file diff --git a/build/rpm/etc/systemd/system/kcnd.service b/build/rpm/etc/systemd/system/kcnd.service new file mode 100644 index 000000000..7ec16ecfb --- /dev/null +++ b/build/rpm/etc/systemd/system/kcnd.service @@ -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 \ No newline at end of file diff --git a/build/rpm/etc/systemd/system/kend.service b/build/rpm/etc/systemd/system/kend.service new file mode 100644 index 000000000..57a03425c --- /dev/null +++ b/build/rpm/etc/systemd/system/kend.service @@ -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 \ No newline at end of file diff --git a/build/rpm/etc/systemd/system/kpnd.service b/build/rpm/etc/systemd/system/kpnd.service new file mode 100644 index 000000000..3daa76988 --- /dev/null +++ b/build/rpm/etc/systemd/system/kpnd.service @@ -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 \ No newline at end of file diff --git a/build/rpm/etc/systemd/system/kscnd.service b/build/rpm/etc/systemd/system/kscnd.service new file mode 100644 index 000000000..9ed418851 --- /dev/null +++ b/build/rpm/etc/systemd/system/kscnd.service @@ -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 \ No newline at end of file diff --git a/build/rpm/etc/systemd/system/ksend.service b/build/rpm/etc/systemd/system/ksend.service new file mode 100644 index 000000000..afa020f67 --- /dev/null +++ b/build/rpm/etc/systemd/system/ksend.service @@ -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 \ No newline at end of file diff --git a/build/rpm/etc/systemd/system/kspnd.service b/build/rpm/etc/systemd/system/kspnd.service new file mode 100644 index 000000000..5815f4087 --- /dev/null +++ b/build/rpm/etc/systemd/system/kspnd.service @@ -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 \ No newline at end of file From 75f2f5b7c536a24eb17b06dc695516420bb88bd6 Mon Sep 17 00:00:00 2001 From: "ollie.j" Date: Thu, 23 Jan 2025 19:18:37 +0900 Subject: [PATCH 2/2] build: rpm installs initscripts and systemd services --- build/rpm/main.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/build/rpm/main.go b/build/rpm/main.go index 4ed92a9df..ad9fd0f5b 100644 --- a/build/rpm/main.go +++ b/build/rpm/main.go @@ -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} @@ -224,11 +225,13 @@ 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 @@ -236,16 +239,29 @@ cp build/rpm/etc/{{ .DaemonName }}/conf/{{ .DaemonName }}{{ .PostFix }}.conf $RP %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