From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id uEN+IWkUGGArFAAA0tVLHw (envelope-from ) for ; Mon, 01 Feb 2021 14:47:05 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id 4H0qHWkUGGASagAAbx9fmQ (envelope-from ) for ; Mon, 01 Feb 2021 14:47:05 +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 D71F194059B for ; Mon, 1 Feb 2021 14:47:02 +0000 (UTC) Received: from localhost ([::1]:34460 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l6aTk-0003w4-IC for larch@yhetil.org; Mon, 01 Feb 2021 09:47:00 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:57650) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l6aTa-0003vT-PU for help-guix@gnu.org; Mon, 01 Feb 2021 09:46:50 -0500 Received: from out1-smtp.messagingengine.com ([66.111.4.25]:33819) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l6aTY-0004eK-Md for help-guix@gnu.org; Mon, 01 Feb 2021 09:46:50 -0500 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id DAEA55C0046; Mon, 1 Feb 2021 09:46:46 -0500 (EST) Received: from imap36 ([10.202.2.86]) by compute4.internal (MEProxy); Mon, 01 Feb 2021 09:46:46 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tindall.space; h=mime-version:message-id:in-reply-to:references:date:from:to :cc:subject:content-type:content-transfer-encoding; s=fm1; bh=Vb xa/hk+SFWjnWoK3rlVMxfmrzs2CShTJ5jTGNK9Hvg=; b=cASlH1S6iTMuMCTF3w l7lKkU/KTyQmP6bE07DbIR+XHEw7lteQbojHY9Fe6Uww5v6Bz0REbUJJOQydfebm 6m/QYZxieRksYCOO32M9gYuOvFTxjRxhDNIKbb3AMLA+zfb5r+sXWBfngim7vCvi cjVvLxJGI1Eybi2c7xUv3OohflwK8mNcgGzik3T02AUwj7Tp4EwdtYWRgnTzWajZ 0JHvreyV7Bwvci1X8rhpsxPfGSMqfBy+VpexB66dYOSQ/GreDB7l9gpVlf7+TZoS zFo/yONbIQ96zcuEsY4VSC8wtOqq7Gq0N5fn2+NTQXFhMDnQXMnvIubWS2juAY3y Z5YA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; bh=Vbxa/hk+SFWjnWoK3rlVMxfmrzs2CShTJ5jTGNK9H vg=; b=mB9mdCzoUYL5ZWHCd5m7XAxPncszk5WEA1zVXsC1uwnQo0fa9NaChuY/2 zoRxgmfI6JvncWhybXdYz/1FlUfKz9fgEtDM2qX95EWF/TFhlrI3zbBM3HPKhFMK MibkfVyyUb7kqSoS5CoYeUIgiKbgdNHR3m2fI9VxPkQ7KbLfBC3x7LkSib+8jmyi uEzG84yTp7oQ6RoaHBwkC4gz/xpi7unjj1wFHfmBdDFFb7PKKfa9i8WGUNC7bbfZ JE8n3bTO4dsbOqoQKFrVNjT3BfHqVbHVfTBfT3+4jS4eKE7Y6Vvm/V18tpnFLI0p OOL9gPQm6rC0OA7DdR66aj7LSL6KQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrfeekgdeijecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefofgggkfgjfhffhffvufgtgfesthhqredtreerjeenucfhrhhomhepvegrmhgv rhhonhcuoegtrghmsehtihhnuggrlhhlrdhsphgrtggvqeenucggtffrrghtthgvrhhnpe ffgeeutddvgfdvfeeltdefhfejieejtdehtdekvdevveekkedthedtgefhhedvteenucff ohhmrghinhepghhithhhuhgsrdgtohhmpdgtrgguugihshgvrhhvvghrrdgtohhmpdhgnh hurdhorhhgnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhho mheptggrmhesthhinhgurghllhdrshhprggtvg X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id A757610E005E; Mon, 1 Feb 2021 09:46:45 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.5.0-alpha0-84-gfc141fe8b8-fm-20210125.001-gfc141fe8 Mime-Version: 1.0 Message-Id: <7c9d921d-b939-413b-aeef-692b527f93b0@www.fastmail.com> In-Reply-To: References: Date: Mon, 01 Feb 2021 08:46:03 -0600 From: Cameron To: "Efraim Flashner" Subject: Re: Custom Service Definition for Caddy Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable Received-SPF: pass client-ip=66.111.4.25; envelope-from=cam@tindall.space; helo=out1-smtp.messagingengine.com X-Spam_score_int: -2 X-Spam_score: -0.3 X-Spam_bar: / X-Spam_report: (-0.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FROM_SUSPICIOUS_NTLD=0.499, PDS_OTHER_BAD_TLD=1.999, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no 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: "julia.galaman--- via" Errors-To: help-guix-bounces+larch=yhetil.org@gnu.org Sender: "Help-Guix" X-Migadu-Flow: FLOW_IN X-Migadu-Spam-Score: -1.55 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=tindall.space header.s=fm1 header.b=cASlH1S6; dkim=pass header.d=messagingengine.com header.s=fm1 header.b=mB9mdCzo; 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: D71F194059B X-Spam-Score: -1.55 X-Migadu-Scanner: scn0.migadu.com X-TUID: 4sIpGANNlPWw Thanks Efraim! I actually spent some time last night with strace trying = to figure out if the thing forks or not. "caddy run" is *supposed& to no= t daemonize, but who knows if it does some other fork funny business. It= was late though and I couldn't keep my eyes open. In the cold light of day this morning, I realized that Caddy 2.3.0 adds = a '-pidfile' option that lets you set a pidfile. With that, I can easily= satisfy 'make-forkexec-contstructor' because it has the #:pid-file opti= on to get the pid of the running daemon from there instead. I ended up w= ith this package and service definition, which work beautifully: #+begin_src=20 (define caddy (package (name "caddy") =20 (version "2.3.0") =20 (source (origin (method url-fetch/tarbomb) (uri (string-append "https://github.com/caddyserver/caddy/releases/= download/v" version "/caddy_" version "_linux_amd64.tar.gz")) (sha256 (base32 "0jfh5bxg36l4jrdd7y240irykrdvxi3d4hwq0bm2b8hki573fy8m")))) (build-system copy-build-system) (arguments '(#:install-plan '(("caddy" "bin/caddy")))) =20 (synopsis "This is a *BAD* Caddy package. It just pulls the already-b= uilt binary from Github, rather than building from source.") (description "See https://caddyserver.com/") (home-page "https://caddyserver.com/") (license licenses:asl2.0))) (define-record-type* caddy-configuration make-caddy-configuration caddy-configuration?) (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 '("caddy" "start" "-config" "/etc/Caddyfile" "-pidfile" "/var/run/caddy.pid") #:pid-file "/var/run/caddy.pid")) (stop #~(make-kill-destructor)))))) #+end_src -Cam On Thu, Jan 28, 2021, at 12:17 PM, Efraim Flashner wrote: > 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 = defining 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 whi= ch time the server is active and taking traffic according to the config = in /etc/Caddyfile but then something (presumably Shepherd) sends it a SI= GTERM and it dutifully shuts down. The 'herd start caddy' then exits wit= h 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","signa= l":"SIGTERM"} > > root@tindall ~#=20 > > #+end_src > >=20 > > 'caddy run' will keep caddy in the foreground, but I see the same be= havior when I use 'caddy start' (which forks another process for the dae= mon 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 >=20 > Does caddy fork when you run "caddy run?" 'make-fork-constructor' fork= s > 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-comman= d > from the manual=C2=B9. >=20 > Alternatively it might work if you can set a PID file. >=20 > =C2=B9=20 > https://www.gnu.org/software/shepherd/manual/html_node/Service-De_002d= -and-Constructors.html#Service-De_002d-and-Constructors >=20 > --=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 unencr= ypted >=20 > Attachments: > * signature.asc