From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:470:142:3::10]:56373) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iwTkb-0000dn-5C for guix-patches@gnu.org; Tue, 28 Jan 2020 11:30:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iwTkY-0004GE-Vs for guix-patches@gnu.org; Tue, 28 Jan 2020 11:30:05 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:55030) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iwTkY-0004FF-Rg for guix-patches@gnu.org; Tue, 28 Jan 2020 11:30:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1iwTkY-0004DD-Kh for guix-patches@gnu.org; Tue, 28 Jan 2020 11:30:02 -0500 Subject: [bug#39329] [PATCH v3 1/2] Add system start-up files for guix-daemon. Resent-Message-ID: From: Danny Milosavljevic Date: Tue, 28 Jan 2020 17:29:13 +0100 Message-Id: <20200128162914.13008-2-dannym@scratchpost.org> In-Reply-To: <20200128162914.13008-1-dannym@scratchpost.org> References: <20200128155529.12071-1-dannym@scratchpost.org> <20200128162914.13008-1-dannym@scratchpost.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+kyle=kyleam.com@gnu.org Sender: "Guix-patches" To: 39329@debbugs.gnu.org Cc: Danny Milosavljevic * etc/init.d/guix-daemon.in: New file. * nix/local.mk (etc/init.d/guix-daemon): New rule. (nodist_sysvinitservice_DATA): Add etc/init.d/guix-daemon.in . (CLEANFILES): Add etc/init.d/guix-daemon . * .gitignore: Add etc/init.d/guix-daemon . --- .gitignore | 1 + etc/init.d/guix-daemon.in | 80 +++++++++++++++++++++++++++++++++++++++ nix/local.mk | 16 +++++++- 3 files changed, 95 insertions(+), 2 deletions(-) create mode 100644 etc/init.d/guix-daemon.in diff --git a/.gitignore b/.gitignore index df59a9176e..de058dda5e 100644 --- a/.gitignore +++ b/.gitignore @@ -71,6 +71,7 @@ /etc/guix-daemon.service /etc/guix-publish.conf /etc/guix-publish.service +/etc/init.d/guix-daemon /guix-daemon /guix/config.scm /libformat.a diff --git a/etc/init.d/guix-daemon.in b/etc/init.d/guix-daemon.in new file mode 100644 index 0000000000..b9c99204df --- /dev/null +++ b/etc/init.d/guix-daemon.in @@ -0,0 +1,80 @@ +#!/bin/bash +### BEGIN INIT INFO +# Provides: guix-daemon +# Required-Start: $remote_fs $syslog +# Required-Stop: $remote_fs $syslog +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: Guix build daemon +# Description: Provides a daemon that does builds for Guix +### END INIT INFO + +set -e +mkdir -p "/var/run" +if [ ! -f "@localstatedir@/guix/profiles/per-user/root/current-guix/bin/guix-daemon" ] +then + exit 5 +fi + +case "$1" in +start) + if [ -f "/var/run/guix-daemon.pid" ] + then + if pgrep -F "/var/run/guix-daemon.pid" guix-daemon + then + exit 0 + else + echo "guix-daemon has a stale pid file" >&2 + exit 1 + fi + else + daemonize \ + -a \ + -e "/var/log/guix-daemon-stderr.log" \ + -o "/var/log/guix-daemon-stdout.log" \ + -E GUIX_LOCPATH=@localstatedir@/guix/profiles/per-user/root/guix-profile/lib/locale \ + -E LC_ALL=en_US.utf8 \ + -p "/var/run/guix-daemon.pid" \ + @localstatedir@/guix/profiles/per-user/root/current-guix/bin/guix-daemon \ + --build-users-group=guixbuild + fi + ;; +stop) + if [ -f "/var/run/guix-daemon.pid" ] + then + pkill -F "/var/run/guix-daemon.pid" guix-daemon || { + exit 1 + } + sleep 10 + pkill --signal 9 -F "/var/run/guix-daemon.pid" guix-daemon || true + exit 0 + else + exit 0 + fi + ;; +status) + if [ -f "/var/run/guix-daemon.pid" ] + then + if pgrep -F "/var/run/guix-daemon.pid" guix-daemon + then + echo "guix-daemon is running" + exit 0 + else + echo "guix-daemon has a stale pid file" + exit 1 + fi + else + echo "guix-daemon is not running" + exit 3 + fi + ;; +restart) +force-reload) + "$0" stop + "$0" start + ;; +*) + echo "Usage: $0 (start|stop|status|restart|force-reload)" + exit 3 + ;; +esac diff --git a/nix/local.mk b/nix/local.mk index dc5a8398b2..a64bdd2137 100644 --- a/nix/local.mk +++ b/nix/local.mk @@ -164,6 +164,16 @@ etc/guix-%.service: etc/guix-%.service.in \ "$<" > "$@.tmp"; \ mv "$@.tmp" "$@" +sysvinitservicedir = $(sysconfdir)/init.d +nodist_sysvinitservice_DATA = etc/init.d/guix-daemon + +etc/init.d/guix-daemon: etc/init.d/guix-daemon.in \ + $(top_builddir)/config.status + $(AM_V_GEN)$(MKDIR_P) "`dirname $@`"; \ + $(SED) -e 's|@''localstatedir''@|$(localstatedir)|' < \ + "$<" > "$@.tmp"; \ + mv "$@.tmp" "$@" + # The '.conf' jobs for Upstart. upstartjobdir = $(libdir)/upstart/system nodist_upstartjob_DATA = etc/guix-daemon.conf etc/guix-publish.conf @@ -177,7 +187,8 @@ etc/guix-%.conf: etc/guix-%.conf.in \ CLEANFILES += \ $(nodist_systemdservice_DATA) \ - $(nodist_upstartjob_DATA) + $(nodist_upstartjob_DATA) \ + $(nodist_sysvinitservice_DATA) EXTRA_DIST += \ %D%/AUTHORS \ @@ -185,7 +196,8 @@ EXTRA_DIST += \ etc/guix-daemon.service.in \ etc/guix-daemon.conf.in \ etc/guix-publish.service.in \ - etc/guix-publish.conf.in + etc/guix-publish.conf.in \ + etc/init.d/guix-daemon.in if CAN_RUN_TESTS