all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Danny Milosavljevic <dannym@scratchpost.org>
To: Catonano <catonano@gmail.com>
Cc: guix-devel <guix-devel@gnu.org>
Subject: Re: weird errors; shepherd
Date: Tue, 23 Jan 2018 23:43:18 +0100	[thread overview]
Message-ID: <20180123234318.3463d51d@scratchpost.org> (raw)
In-Reply-To: <CAJ98PDyFxd_Tx+pLfRG3sRLfU=hkdaTq5YwU9dQEUTrq8gZMfw@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 865 bytes --]

The attached file is gnu/services/trytond.scm which successfully runs trytond.

Everyone:

After I've tried writing some shepherd service I have to say that writing a
shepherd "start" action is way too difficult.

Even now, I've not gotten to work:

* Having the activation depend on any other service.
* Logging errors from start-trytond to stderr or stdout.
  As far as I understand make-forkexec-constructor takes special care not
  to kill stderr.  As long there's no log-file specified it should leave stdout
  and stderr alone.  So where does the text go?

I've had other problems like:

* root's shepherd hangs sometimes and herd can't connect to it anymore.
* When I use (error "XXX") in a shepherd start block, booting the system
drops me into a REPL and doesn't let me out again (instead of just failing
this one service and continuing to boot).

Sigh...

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: trytond.scm --]
[-- Type: text/x-scheme, Size: 8273 bytes --]

;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2018 Adriano Peluso <catonano@gmail.com>
;;;
;;; This file is part of GNU Guix.
;;;
;;; GNU Guix is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Guix is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.

(define-module (gnu services trytond)
  #:use-module (gnu services)
  #:use-module (gnu services shepherd)
  #:use-module (gnu system shadow)
  #:use-module (gnu packages admin)
  #:use-module (gnu packages databases)
  #:use-module (gnu packages tryton)
  #:use-module (guix modules)
  #:use-module (guix records)
  #:use-module (guix build utils)
  #:use-module (guix gexp)
  #:use-module (ice-9 match)
  #:export (trytond-service-type
            <trytond-configuration>

            trytond-configuration
            trytond-configuration?

            trytond-configuration-trytond
            trytond-configuration-postgresql
            trytond-configuration-config-file
            trytond-configuration-data-directory
            trytond-configuration-postgres-role
            trytond-configuration-database-name))

;;; Commentary:
;;;
;;; Trytond based services. Mainly Trytond and GNUHealth for now
;;;
;;; Code:

(define %default-trytond-path
  "/var/lib/trytond")

(define %default-postgres-role
  "tryton")

(define %default-database-name
  "tryton")

(define %default-trytond-config
  (mixed-text-file "trytond.conf"
                   "[database]\n"
                   ;; XXX which postgres user shold we use here ?
                   (string-append "uri = postgresql://"
                                  %default-postgres-role
                                  "@127.0.0.1\n")
                   "path = " %default-trytond-path))

(define %default-passfile
  (mixed-text-file "passfile"
                   "tryton"))

(define-record-type* <trytond-configuration>
  trytond-configuration make-trytond-configuration
  trytond-configuration?
  (trytond     trytond-configuration-trytond ;<package>
               (default python-trytond))
  (postgresql  trytond-configuration-postgresql
               (default postgresql))
  (locale         trytond-configuration-locale
                  (default "en_US.utf8"))
  (config-file    trytond-configuration-file
                  (default %default-trytond-config))
  (passfile      trytond-passfile
                 (default %default-passfile))
  ;; Default: The db folder under the user home directory running trytond.
  (data-directory trytond-configuration-data-directory
                  (default %default-trytond-path))
  (postgres-role trytond-configuration-postgres-role
                 (default %default-postgres-role))
  (database-name trytond-configuration-database-name
                 (default %default-database-name)))

(define %trytond-accounts
  (list (user-group (name "trytond") (system? #t))
        (user-account
         (name "trytond")
         (group "trytond")
         (system? #t)
         (comment "Trytond server user")
         (home-directory "/var/empty")
         (shell (file-append shadow "/sbin/nologin")))))

(define (setup-role.sql role)
  (plain-file "setup-role.sql" (format #f "
DO
$body$
BEGIN
   IF NOT EXISTS (
      SELECT *
      FROM   pg_catalog.pg_user
      WHERE  usename = '~A') THEN
      CREATE ROLE \"~A\" LOGIN;
   END IF;
END
$body$;
" role role)))

(define (setup-database.sql database role)
  (plain-file "setup-database.sql"
   (format #f "CREATE DATABASE \"~A\" WITH OWNER = \"~A\";" database role)))

(define (trytond-activation config)
  (let* ((postgresql (trytond-configuration-postgresql config))
         (role (trytond-configuration-postgres-role config))
         (database (trytond-configuration-database-name config))
         (data-directory (trytond-configuration-data-directory config)))
    #~(begin
        (let ((trytond-user (getpwnam "trytond")))
           (mkdir-p #$data-directory)
           (chown #$data-directory
                  (passwd:uid trytond-user)
                  (passwd:gid trytond-user))))))

(define trytond-shepherd-service
  (match-lambda
   (($ <trytond-configuration> trytond
                               postgresql
                               locale
                               config-file
                               passfile
                               data-directory
                               postgres-role
                               database-name)
    (let* ((setup-role.sql (setup-role.sql postgres-role))
           (setup-database.sql (setup-database.sql database-name postgres-role))
           (start-script
            (program-file "start-trytond"
                          (with-imported-modules '((guix build utils))
                            #~(begin
                                (use-modules (guix build utils))
                                ;; Set up postgres database.
                                (let ((psql (string-append #$postgresql
                                                           "/bin/psql")))
                                  (invoke psql "-U" "postgres"
                                               "-f" #$setup-role.sql)
                                  (system* psql "-U" "postgres"
                                                "-f" #$setup-database.sql))
                                ;; Set up tables.
                                (let ((trytond-admin (string-append #$trytond
                                                                    "/bin/trytond-admin"))
                                      (args (append (list "-c" #$config-file
                                                          "-d" #$database-name
                                                          "--all")
                                                    (if #$locale
                                                        (list "-l" #$locale)
                                                        '()))))
                                  (setenv "TRYTONPASSFILE" #$passfile)
                                  (apply invoke trytond-admin args))
                                ;; Start daemon.
                                (execl (string-append #$trytond
                                                      "/bin/trytond")
                                       (string-append #$trytond
                                                      "/bin/trytond")
                                       "-c" #$config-file))))))
      (list (shepherd-service
                (provision '(trytond))
                (documentation "Trytond daemon.")
                (requirement '(user-processes loopback postgres))
                ; TODO #:pid-file
                (start #~(make-forkexec-constructor #$start-script
                                                    #:log-file "/tmp/QQ"
                                                    #:user "trytond"
                                                    #:group "trytond"))
                (stop #~(make-kill-destructor))))))))

(define trytond-service-type
  (service-type (name 'trytond)
                (extensions
                 (list (service-extension shepherd-root-service-type
                                          trytond-shepherd-service)
                       (service-extension activation-service-type
                                          trytond-activation)
                       (service-extension account-service-type
                                          (const %trytond-accounts))))
                (default-value (trytond-configuration))))

  reply	other threads:[~2018-01-23 22:43 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-13 17:00 weird errors Catonano
2018-01-13 21:13 ` Ludovic Courtès
2018-01-14  7:21   ` Catonano
2018-01-14 10:43     ` Danny Milosavljevic
2018-01-14 10:57       ` Danny Milosavljevic
2018-01-14 11:00       ` Catonano
2018-01-14 16:38         ` Ricardo Wurmus
2018-01-14 20:35           ` Catonano
2018-01-14 16:45         ` Danny Milosavljevic
2018-01-14 20:33           ` Catonano
2018-01-15  5:43           ` Alex Vong
2018-01-22 10:52         ` Catonano
2018-01-22 10:59           ` Danny Milosavljevic
2018-01-22 12:42             ` Catonano
2018-01-22 19:01               ` Danny Milosavljevic
2018-01-22 20:37                 ` Catonano
2018-01-23 22:43                   ` Danny Milosavljevic [this message]
2018-01-24 12:34                     ` weird errors; shepherd Catonano
2018-01-24 12:46                       ` Danny Milosavljevic
2018-01-24 12:52                         ` Catonano
2018-01-24 14:47                     ` Ludovic Courtès
2018-01-24 19:36                       ` Danny Milosavljevic
2018-01-24 22:28                         ` Ludovic Courtès
2018-01-29  7:24                     ` Catonano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180123234318.3463d51d@scratchpost.org \
    --to=dannym@scratchpost.org \
    --cc=catonano@gmail.com \
    --cc=guix-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.