From patchwork Fri May 19 01:59:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Maxim Cournoyer X-Patchwork-Id: 50141 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id AA53A27BBE9; Fri, 19 May 2023 03:01:20 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-3.7 required=5.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 62ACF27BBE2 for ; Fri, 19 May 2023 03:01:18 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pzpQV-0000O3-Fu; Thu, 18 May 2023 22:01:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pzpQU-0000Nq-JZ for guix-patches@gnu.org; Thu, 18 May 2023 22:01:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pzpQU-00067E-5G for guix-patches@gnu.org; Thu, 18 May 2023 22:01:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pzpQU-00072D-1X for guix-patches@gnu.org; Thu, 18 May 2023 22:01:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#63402] [PATCH v5 1/5] services: herd: Add a new 'current-service' procedure. Resent-From: Maxim Cournoyer Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Fri, 19 May 2023 02:01:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 63402 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 63402@debbugs.gnu.org Cc: Maxim Cournoyer Received: via spool by 63402-submit@debbugs.gnu.org id=B63402.168446166027025 (code B ref 63402); Fri, 19 May 2023 02:01:02 +0000 Received: (at 63402) by debbugs.gnu.org; 19 May 2023 02:01:00 +0000 Received: from localhost ([127.0.0.1]:54945 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pzpQR-00071p-Go for submit@debbugs.gnu.org; Thu, 18 May 2023 22:01:00 -0400 Received: from mail-qv1-f43.google.com ([209.85.219.43]:61719) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pzpQO-00071Y-37 for 63402@debbugs.gnu.org; Thu, 18 May 2023 22:00:58 -0400 Received: by mail-qv1-f43.google.com with SMTP id 6a1803df08f44-61b58b6e864so21966916d6.3 for <63402@debbugs.gnu.org>; Thu, 18 May 2023 19:00:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684461650; x=1687053650; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=AHK10pNweAf429LFpGHvkcqrYp/sf1a9/2a23XpN7PA=; b=qncQ1dXi+KS5O0AxbzuvrLuMRQQWTnKcCsfe+fk2SL2+Y6WX2wlcnyq2TZYW49KGQI qSrPuj1BSXHllev7QKSJYpc/2Cdw5oOoeedZFknW3nPs0f5IIOvHGos09irJTbPO+37u kMvemFf5bqjVCi7JUjlwH87Y7iHfAFtFeX7XziHa5GVuboj/PiTSqKNuQPq6aT97CVq7 3ZCP+BHVhNROUF8jV3D8kJjl7qaXveqEasiyzyklazvmxrtJLwBDFIx3NJoZ+VClGAA8 OCJz0nr7JWMShFUKGCaosXoPXmLFosJP+AMhHOUXomNYZfE0xyNaL+PYkCu6iugGfL/q g1Rg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684461650; x=1687053650; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=AHK10pNweAf429LFpGHvkcqrYp/sf1a9/2a23XpN7PA=; b=DcVg4FICdPa1VTNSGKRZUTiOVDVNALbqSTP2v6QeBQkIWGJHwqN6I37KpF9VmgUgJO Bzw6daesw3ODyLFMRFnrhJBCWQZh30QCVgc0S8E4LFE9Huj5POcfJCq1SBzOs10qL4AV qHKeSLMdKTI1b7NwwOhsXnc+w9U/HzL6HSlZWROb+cBZwkhifGEorUmPPuUU+HAsYzav IWrb7w3s9BT9gWqlOxBnDQCHHI6AH2yxZTCkZmnHHTcu1lwrK/mkU9ri1V2Qoghq2RaK tm7Yn6kobm2NNu7oGu1Mo9Bf9i6j5MTE3MBwMvgAthMicxirwXQ5WHPOD/RgYOmJvLCu 1sKw== X-Gm-Message-State: AC+VfDxpSMIYOwe9gH3t0An+8ol9rtR7PUorXqskhIIPcwSzrY+D561F koYl0guM7zMQ0j3nxsfpgJRhu8p2jbSNhw== X-Google-Smtp-Source: ACHHUZ5HC0Xv5eho/vhrlVuscMxCtl2orG+H7zSNUVc/b+2lvVwgHxW9TF8Q2819SkVy9f+cDo+CyQ== X-Received: by 2002:a05:6214:1256:b0:5ef:5049:f49a with SMTP id r22-20020a056214125600b005ef5049f49amr2081236qvv.32.1684461650105; Thu, 18 May 2023 19:00:50 -0700 (PDT) Received: from localhost.localdomain (dsl-150-33.b2b2c.ca. [66.158.150.33]) by smtp.gmail.com with ESMTPSA id mg14-20020a056214560e00b0062389d885f5sm964348qvb.47.2023.05.18.19.00.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 May 2023 19:00:49 -0700 (PDT) From: Maxim Cournoyer Date: Thu, 18 May 2023 21:59:13 -0400 Message-Id: <4ae50adcd4cef9d26b26eb4456727538d61f064c.1684461197.git.maxim.cournoyer@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches * gnu/services/herd.scm (current-service): New procedure, mostly reusing the existing current-services. (current-services): Implement in terms of the above procedure. --- gnu/services/herd.scm | 52 +++++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 19 deletions(-) diff --git a/gnu/services/herd.scm b/gnu/services/herd.scm index 48594015fc..02c2fec20f 100644 --- a/gnu/services/herd.scm +++ b/gnu/services/herd.scm @@ -1,6 +1,7 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2016-2019, 2022-2023 Ludovic Courtès ;;; Copyright © 2017, 2020 Mathieu Othacehe +;;; Copyright © 2023 Maxim Cournoyer ;;; ;;; This file is part of GNU Guix. ;;; @@ -51,6 +52,7 @@ (define-module (gnu services herd) live-service-canonical-name with-shepherd-action + current-service current-services unload-services unload-service @@ -208,31 +210,43 @@ (define (live-service-canonical-name service) "Return the 'canonical name' of SERVICE." (first (live-service-provision service))) -(define (current-services) - "Return the list of currently defined Shepherd services, represented as - objects. Return #f if the list of services could not be -obtained." - (with-shepherd-action 'root ('status) results - ;; We get a list of results, one for each service with the name 'root'. +(define (current-service name) + "Return the currently defined Shepherd service NAME, as a +object. Return #f if the service could not be obtained. As a special case, +@code{(current-service 'root)} returns all the current services." + (define (process-services services) + (resolve-transients + (map (lambda (service) + (alist-let* service (provides requires running transient?) + ;; The Shepherd 0.9.0 would not provide 'transient?' in + ;; its status sexp. Thus, when it's missing, query it + ;; via an "eval" request. + (live-service provides requires + (if (sloppy-assq 'transient? service) + transient? + (and running *unspecified*)) + running))) + services))) + + (with-shepherd-action name ('status) results + ;; We get a list of results, one for each service with the name NAME. ;; In practice there's only one such service though. (match results ((services _ ...) (match services ((('service ('version 0 _ ...) _ ...) ...) - (resolve-transients - (map (lambda (service) - (alist-let* service (provides requires running transient?) - ;; The Shepherd 0.9.0 would not provide 'transient?' in its - ;; status sexp. Thus, when it's missing, query it via an - ;; "eval" request. - (live-service provides requires - (if (sloppy-assq 'transient? service) - transient? - (and running *unspecified*)) - running))) - services))) + ;; Summary of all services (when NAME is 'root or 'shepherd). + (process-services services)) + (('service ('version 0 _ ...) _ ...) ;single service + (first (process-services (list services)))) (x - #f)))))) + #f)))))) ;singleton + +(define (current-services) + "Return the list of currently defined Shepherd services, represented as + objects. Return #f if the list of services could not be +obtained." + (current-service 'root)) (define (resolve-transients services) "Resolve the subset of SERVICES whose 'transient?' field is undefined. This