[PATCH 2/4] Add systemd unit file for kojid

Dennis Gilmore dennis at ausil.us
Sat Jun 6 20:05:17 UTC 2015


From: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>

Signed-off-by: Dennis Gilmore <dennis at ausil.us>
---
 Makefile              |  3 ++-
 builder/Makefile      | 19 +++++++++++++------
 builder/kojid.service | 14 ++++++++++++++
 koji.spec             | 39 +++++++++++++++++++++++++++++++++++++--
 4 files changed, 66 insertions(+), 9 deletions(-)
 create mode 100644 builder/kojid.service

diff --git a/Makefile b/Makefile
index b9c23bf..d5e9b77 100644
--- a/Makefile
+++ b/Makefile
@@ -105,6 +105,7 @@ force-tag::
 #	@$(MAKE) tag TAG_OPTS="-F $(TAG_OPTS)"
 
 DESTDIR ?= /
+TYPE = systemd
 install:
 	@if [ "$(DESTDIR)" = "" ]; then \
 		echo " "; \
@@ -115,4 +116,4 @@ install:
 	mkdir -p $(DESTDIR)
 
 	for d in $(SUBDIRS); do make DESTDIR=`cd $(DESTDIR); pwd` \
-		-C $$d install; [ $$? = 0 ] || exit 1; done
+		-C $$d install TYPE=$(TYPE); [ $$? = 0 ] || exit 1; done
diff --git a/builder/Makefile b/builder/Makefile
index 02bae11..1de0a9c 100644
--- a/builder/Makefile
+++ b/builder/Makefile
@@ -1,6 +1,7 @@
-
 BINFILES = kojid
 LIBEXECFILES = mergerepos
+SYSTEMDSYSTEMUNITDIR = $(shell pkg-config systemd --variable=systemdsystemunitdir)
+TYPE = systemd
 
 _default:
 	@echo "nothing to make.  try make install"
@@ -9,7 +10,7 @@ clean:
 	rm -f *.o *.so *.pyc *~
 
 
-install:
+_install:
 	@if [ "$(DESTDIR)" = "" ]; then \
 		echo " "; \
 		echo "ERROR: A destdir is required"; \
@@ -23,13 +24,19 @@ install:
 	install -p -m 755 $(LIBEXECFILES) $(DESTDIR)/usr/libexec/kojid
 
 	mkdir -p $(DESTDIR)/etc/mock/koji
+
+	mkdir -p $(DESTDIR)/etc/kojid
+	install -p -m 644 kojid.conf $(DESTDIR)/etc/kojid/kojid.conf
+
+install-systemd: _install
+	mkdir -p $(DESTDIR)$(SYSTEMDSYSTEMUNITDIR)
+	install -p -m 644 kojid.service $(DESTDIR)$(SYSTEMDSYSTEMUNITDIR)
+
+install-sysv: _install
 	mkdir -p $(DESTDIR)/etc/rc.d/init.d
 	install -p -m 755 kojid.init $(DESTDIR)/etc/rc.d/init.d/kojid
 
 	mkdir -p $(DESTDIR)/etc/sysconfig
 	install -p -m 644 kojid.sysconfig $(DESTDIR)/etc/sysconfig/kojid
 
-	mkdir -p $(DESTDIR)/etc/kojid
-	install -p -m 644 kojid.conf $(DESTDIR)/etc/kojid/kojid.conf
-
-
+install: install-$(TYPE)
diff --git a/builder/kojid.service b/builder/kojid.service
new file mode 100644
index 0000000..1886a44
--- /dev/null
+++ b/builder/kojid.service
@@ -0,0 +1,14 @@
+[Unit]
+Description=Koji build server
+Documentation=https://fedoraproject.org/wiki/Koji/ServerHowTo
+
+After=network.target
+
+[Service]
+ExecStart=/usr/sbin/kojid \
+       --fg \
+       --force-lock \
+       --verbose
+
+[Install]
+WantedBy=multi-user.target
diff --git a/koji.spec b/koji.spec
index c2b1af4..82df76e 100644
--- a/koji.spec
+++ b/koji.spec
@@ -1,5 +1,12 @@
 %{!?python_sitelib: %define python_sitelib %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib()")}
 
+%if 0%{?fedora} >= 21 || 0%{?redhat} >= 7
+%global use_systemd 1
+%else
+%global use_systemd 0
+%global install_opt TYPE=sysv
+%endif
+
 %define baserelease 1
 #build with --define 'testbuild 1' to have a timestamp appended to release
 %if "x%{?testbuild}" == "x1"
@@ -23,6 +30,10 @@ Requires: rpm-python
 Requires: pyOpenSSL
 Requires: python-urlgrabber
 BuildRequires: python
+%if %{use_systemd}
+BuildRequires: systemd
+BuildRequires: pkgconfig
+%endif
 
 %description
 Koji is a system for building and tracking RPMS.  The base package
@@ -63,11 +74,17 @@ License: LGPLv2 and GPLv2+
 #mergerepos (from createrepo) is GPLv2+
 Requires: %{name} = %{version}-%{release}
 Requires: mock >= 0.9.14
+Requires(pre): /usr/sbin/useradd
+%if %{use_systemd}
+Requires(post): systemd
+Requires(preun): systemd
+Requires(postun): systemd
+%else
 Requires(post): /sbin/chkconfig
 Requires(post): /sbin/service
 Requires(preun): /sbin/chkconfig
 Requires(preun): /sbin/service
-Requires(pre): /usr/sbin/useradd
+%endif
 Requires: /usr/bin/cvs
 Requires: /usr/bin/svn
 Requires: /usr/bin/git
@@ -135,7 +152,7 @@ koji-web is a web UI to the Koji system.
 
 %install
 rm -rf $RPM_BUILD_ROOT
-make DESTDIR=$RPM_BUILD_ROOT install
+make DESTDIR=$RPM_BUILD_ROOT %{?install_opt} install
 
 %clean
 rm -rf $RPM_BUILD_ROOT
@@ -192,8 +209,12 @@ rm -rf $RPM_BUILD_ROOT
 %{_sbindir}/kojid
 %dir %{_libexecdir}/kojid
 %{_libexecdir}/kojid/mergerepos
+%if %{use_systemd}
+%{_unitdir}/kojid.service
+%else
 %{_initrddir}/kojid
 %config(noreplace) %{_sysconfdir}/sysconfig/kojid
+%endif
 %dir %{_sysconfdir}/kojid
 %config(noreplace) %{_sysconfdir}/kojid/kojid.conf
 %attr(-,kojibuilder,kojibuilder) %{_sysconfdir}/mock/koji
@@ -201,6 +222,19 @@ rm -rf $RPM_BUILD_ROOT
 %pre builder
 /usr/sbin/useradd -r -s /bin/bash -G mock -d /builddir -M kojibuilder 2>/dev/null ||:
 
+%if %{use_systemd}
+
+%post builder
+%systemd_post kojid.service
+
+%preun builder
+%systemd_preun kojid.service
+
+%postun builder
+%systemd_postun kojid.service
+
+%else
+
 %post builder
 /sbin/chkconfig --add kojid
 
@@ -209,6 +243,7 @@ if [ $1 = 0 ]; then
   /sbin/service kojid stop &> /dev/null
   /sbin/chkconfig --del kojid
 fi
+%endif
 
 %files vm
 %defattr(-,root,root)
-- 
2.4.2



More information about the koji-devel mailing list