From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id eK+OFw4AE2BISAAA0tVLHw (envelope-from ) for ; Thu, 28 Jan 2021 18:18:54 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id COlaEw4AE2A3ZAAA1q6Kng (envelope-from ) for ; Thu, 28 Jan 2021 18:18:54 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id A3C2A940276 for ; Thu, 28 Jan 2021 18:18:53 +0000 (UTC) Received: from localhost ([::1]:33494 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l5Bsa-0002ej-Be for larch@yhetil.org; Thu, 28 Jan 2021 13:18:52 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51486) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l5Bs7-0002cu-MP for help-guix@gnu.org; Thu, 28 Jan 2021 13:18:25 -0500 Received: from flashner.co.il ([178.62.234.194]:39678) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l5Bs3-0004eI-J7 for help-guix@gnu.org; Thu, 28 Jan 2021 13:18:23 -0500 Received: from localhost (unknown [31.210.181.184]) by flashner.co.il (Postfix) with ESMTPSA id 56F1140297; Thu, 28 Jan 2021 18:17:46 +0000 (UTC) Date: Thu, 28 Jan 2021 20:17:07 +0200 From: Efraim Flashner To: Cameron Subject: Re: Custom Service Definition for Caddy Message-ID: References: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="V8DfuVEtmM3JvscS" Content-Disposition: inline In-Reply-To: X-PGP-Key-ID: 0x41AAE7DCCA3D8351 X-PGP-Key: https://flashner.co.il/~efraim/efraim_flashner.asc X-PGP-Fingerprint: A28B F40C 3E55 1372 662D 14F7 41AA E7DC CA3D 8351 Received-SPF: pass client-ip=178.62.234.194; envelope-from=efraim@flashner.co.il; helo=flashner.co.il X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-guix@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: help-guix@gnu.org Errors-To: help-guix-bounces+larch=yhetil.org@gnu.org Sender: "Help-Guix" X-Migadu-Flow: FLOW_IN X-Migadu-Spam-Score: -3.95 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of help-guix-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=help-guix-bounces@gnu.org X-Migadu-Queue-Id: A3C2A940276 X-Spam-Score: -3.95 X-Migadu-Scanner: scn1.migadu.com X-TUID: 7De2+1ehzG45 --V8DfuVEtmM3JvscS Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Jan 26, 2021 at 11:02:58AM -0600, Cameron wrote: > Hello again everyone! >=20 > I'm having a great time learning about Guix, but am struggling with defin= ing a custom service for Caddy. The 'caddy' package below works as expected= -- installing it puts the "caddy" binary in $PATH and it works fine when I= run it from a shell. >=20 >=20 > #+begin_src=20 > #+end_src >=20 > What doesn't work as expected is this service definition: >=20 > #+begin_src=20 > (define-record-type* > caddy-configuration make-caddy-configuration caddy-configuration? > (config-file caddy-configuration-config-file > (default "/etc/Caddyfile"))) >=20 > (define caddy-service-type > (shepherd-service-type > 'caddy > (lambda (config) > (shepherd-service > (documentation "Run the caddy daemon (caddy).") > (provision '(caddy)) > (requirement '(user-processes)) > (start #~(make-forkexec-constructor > (list "caddy" "run" > "-config" "/etc/Caddyfile") > #:log-file "/var/log/caddy.log")) > (stop #~(make-kill-destructor)))))) > #+end_src >=20 > ...which I then add to my services list in config.scm like this: >=20 > #+begin_src=20 > (service caddy-service-type > (caddy-configuration > (config-file "/etc/Caddyfile"))) > #+end_src >=20 > With this setup, 'herd start caddy' hangs for 30 seconds, during which ti= me the server is active and taking traffic according to the config in /etc/= Caddyfile but then something (presumably Shepherd) sends it a SIGTERM and i= t dutifully shuts down. The 'herd start caddy' then exits with an error: >=20 > #+begin_src=20 > root@tindall ~# START=3D$(date +%s); herd start caddy; END=3D$(date +%s);= echo $(($END - START)) > Service caddy could not be started. > herd: failed to start service caddy > 30 > root@tindall ~# tail -n 1 /var/log/caddy.log=20 > {"level":"info","ts":1611680035.1811087,"msg":"shutdown done","signal":"S= IGTERM"} > root@tindall ~#=20 > #+end_src >=20 > 'caddy run' will keep caddy in the foreground, but I see the same behavio= r when I use 'caddy start' (which forks another process for the daemon and = exits immediately) in the service definition instead. >=20 > I suspect something is wrong with the 'start' procedure I've defined, but= I'm struggling to figure out what it is. >=20 > What am I missing? >=20 > -Cameron >=20 Does caddy fork when you run "caddy run?" 'make-fork-constructor' forks when it runs the code, so if caddy also forks then you have a double-forked codepath and shepherd thinks the process is gone, so it goes to kill it. If caddy doesn't have something like --foreground or --no-daemonize then you might be looking at something like exec-command =66rom the manual=C2=B9. Alternatively it might work if you can set a PID file. =C2=B9 https://www.gnu.org/software/shepherd/manual/html_node/Service-De_00= 2d-and-Constructors.html#Service-De_002d-and-Constructors --=20 Efraim Flashner =D7=90=D7=A4=D7=A8=D7=99=D7=9D = =D7=A4=D7=9C=D7=A9=D7=A0=D7=A8 GPG key =3D A28B F40C 3E55 1372 662D 14F7 41AA E7DC CA3D 8351 Confidentiality cannot be guaranteed on emails sent or received unencrypted --V8DfuVEtmM3JvscS Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEoov0DD5VE3JmLRT3Qarn3Mo9g1EFAmAS/6MACgkQQarn3Mo9 g1GXAA/+M6eSmvs79/xa31/4z0dLNDFkGpCVljKtD/+s454XKih6twg3hoZdxA6L Zqa0Spv/oLGdd4CjhxXXwjEtDU9VgqqaQtOQ4nXAp9c+rZnGGFSYfgaazP3qLEFK GECRj4ySN219Z2iGEQ9n1DeH2il+22xHd+SV1peJHcg2IAqPxkSpULUjKBQJ1xk9 fkwNDJWjxt/VSPahBkkCg60yPx4Ls22qcAM8tiQM1srKElNIpTmqBtOboLevox4U cXUHqsxzHSDLLpS993oPLe4lYB8O1nUR95kUuGcWeN++nrNi5JTVodxIHEjU6QMA yaZAMccDa/qZCdWzJI1NmadlrRxgItiGZHXZp+vkkJ2c8TyNAQ5vrYMfx1rRaoST vzJhwo1wt+2cCWxevpe9lUJT1OI+vpO0Zrl18FtjPZa0wLLOqf7zLhh70QfVA4cY ZJId8dzirxXAjoqRf0d3d/O6r/6p/NpVVy1u4R1qTDOskQxHlPUg09paM8ZfIf56 CPS7K8sJwdAgnf6KN5vErtWAFtZZ2q+vNzBbT8wfA9Gud+N4Ar/zweVcmduKhUz1 u3C9hY5pRhx6LZnMla5NC05UPVOvUhkGP/hP8YKdWvfCYflO/mw6ECaPBM66VjQx e8l9Rx/orvwvBkBk9ZiljXiAKFUJc3jccxL2RVbkQn6mrgm6/Ok= =/f+/ -----END PGP SIGNATURE----- --V8DfuVEtmM3JvscS--