about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMunyoki Kilyungi2024-12-23 11:17:56 +0300
committerMunyoki Kilyungi2025-01-06 22:24:58 +0300
commit800964a9211c59b02fc4696dac93d3c59eb621c4 (patch)
tree720c3a3af1d4fe13364085db7b448fd3abf13363
parent8490d297750afe38a93d84b1d86a27ec321a0160 (diff)
downloadgn-machines-800964a9211c59b02fc4696dac93d3c59eb621c4.tar.gz
Add gn-guile shepherd service genenetwork-service-type.
* genenetwork/services/genenetwork.scm: Import gn-guile, linux-container,
git-minimal, shepherd, least-authority, forge utils.
(<genenetwork-configuration>)[gn-guile-port, gn-doc-git-checkout]: New fields.
(gn-guile-gexp): New g-exp for running gn-guile.
(gn-guile-shepherd-service): New shepherd service to run gn-guile.
(genenetwork-service-type): Add gn-guile-shepherd-service.
* production-deploy.sh (container_script): Export gn-docs directory.
-rw-r--r--genenetwork/services/genenetwork.scm63
-rwxr-xr-xproduction-deploy.sh1
2 files changed, 64 insertions, 0 deletions
diff --git a/genenetwork/services/genenetwork.scm b/genenetwork/services/genenetwork.scm
index 03a2a2c..b863bcf 100644
--- a/genenetwork/services/genenetwork.scm
+++ b/genenetwork/services/genenetwork.scm
@@ -21,18 +21,23 @@
 
 (define-module (genenetwork services genenetwork)
   #:use-module ((gn packages genenetwork) #:select (genenetwork2 genenetwork3 gn-auth gn-uploader))
+  #:use-module ((gn packages guile) #:select (gn-guile))
+  #:use-module (gnu build linux-container)
   #:use-module ((gnu packages web) #:select (nginx))
   #:use-module ((gnu packages admin) #:select (shadow shepherd))
+  #:use-module ((gnu packages version-control) #:select (git-minimal))
   #:use-module ((gnu packages python) #:select (python))
   #:use-module (gnu services)
   #:use-module (gnu services web)
   #:use-module (gnu services mcron)
+  #:use-module (gnu services shepherd)
   #:use-module (gnu system file-systems)
   #:use-module (gnu system shadow)
   #:use-module (guix build python-build-system)
   #:use-module (guix diagnostics)
   #:use-module (guix gexp)
   #:use-module (guix i18n)
+  #:use-module (guix least-authority)
   #:use-module (guix packages)
   #:use-module (guix profiles)
   #:use-module (guix records)
@@ -40,6 +45,7 @@
   #:use-module (forge nginx)
   #:use-module (forge gunicorn)
   #:use-module (forge socket)
+  #:use-module (forge utils)
   #:use-module (srfi srfi-1)
   #:use-module (ice-9 match)
   #:export (genenetwork-service-type
@@ -109,6 +115,10 @@
                (default "/etc/genenetwork/gn3-secrets.py"))
   (gn-auth-secrets genenetwork-configuration-gn-auth-secrets
                    (default "/etc/genenetwork"))
+  (gn-guile-port genenetwork-configuration-gn-guile-port
+                 (default 8091))
+  (gn-doc-git-checkout genenetwork-configuration-gn-doc-git-checkout
+                       (default "/export/data/gn-docs"))
   (log-level genenetwork-configuration-log-level
              (default 'warning)
              (sanitize sanitize-log-level)))
@@ -547,6 +557,57 @@ a @code{<genenetwork-configuration>} record."
                                (build-xapian-index-cron-gexp config))
                #:user "root")))
 
+(define (gn-guile-gexp gn-guile-port)
+  (with-imported-modules '((guix build utils))
+    #~(begin
+        (use-modules (guix build utils))
+        (let ((current-repo-path (string-append (getcwd) "/gn-docs")))
+          (when (file-exists? current-repo-path)
+            (delete-file-recursively current-repo-path))
+          (setenv "CURRENT_REPO_PATH" current-repo-path)
+          (invoke #$(file-append git-minimal "/bin/git")
+                  "clone" "--depth" "1" (getenv "CGIT_REPO_PATH")))
+        (invoke #$(file-append gn-guile "/bin/gn-guile")
+                (number->string #$gn-guile-port)))))
+
+(define (gn-guile-shepherd-service config)
+  (match-record config <genenetwork-configuration>
+    (gn-doc-git-checkout gn-guile-port)
+    (shepherd-service
+     (documentation "Run gn-guile server.")
+     (provision '(gn-guile))
+     (requirement '(networking))
+     (modules '((ice-9 match)
+                (srfi srfi-1)))
+     (start
+      (let* ((gn-guile-settings
+              `(("CGIT_REPO_PATH" ,gn-doc-git-checkout)
+                ("LC_ALL" "en_US.UTF-8")
+                ("GIT_COMMITTER_NAME" "genenetwork")
+                ("GIT_COMMITTER_EMAIL" "no-reply@git.genenetwork.org"))))
+        #~(make-forkexec-constructor
+	   (list #$(least-authority-wrapper
+                    (program-file "gn-guile"
+                                  (gn-guile-gexp gn-guile-port))
+                    #:name "gn-guile-pola-wrapper"
+                    #:preserved-environment-variables
+                    (map first gn-guile-settings)
+                    #:mappings (list (file-system-mapping
+                                      (source gn-doc-git-checkout)
+                                      (target source)
+                                      (writable? #t)))
+                    #:namespaces (delq 'net %namespaces))
+                 "127.0.0.1" #$(number->string gn-guile-port))
+           #:user "genenetwork"
+           #:group "genenetwork"
+           #:environment-variables
+           (map (match-lambda
+                  ((spec value)
+                   (string-append spec "=" value)))
+                '#$gn-guile-settings)
+	   #:log-file "/var/log/gn-guile.log")))
+     (stop #~(make-kill-destructor)))))
+
 (define genenetwork-service-type
   (service-type
    (name 'genenetwork)
@@ -560,6 +621,8 @@ a @code{<genenetwork-configuration>} record."
                              genenetwork-gunicorn-apps)
           (service-extension forge-nginx-service-type
                              genenetwork-nginx-server-blocks)
+          (service-extension shepherd-root-service-type
+                             (compose list gn-guile-shepherd-service))
           (service-extension mcron-service-type genenetwork-mcron-jobs)))
    (default-value (genenetwork-configuration))))
 
diff --git a/production-deploy.sh b/production-deploy.sh
index a744f41..bd95814 100755
--- a/production-deploy.sh
+++ b/production-deploy.sh
@@ -37,6 +37,7 @@ container_script=$(guix system container \
                         --share=/export2/guix-containers/genenetwork/var/lib/genenetwork-sqlite=/var/lib/genenetwork-sqlite \
                         --share=/export2/guix-containers/genenetwork/var/lib/genenetwork-gnqa=/var/lib/genenetwork-gnqa \
                         --share=/var/run/mysqld=/run/mysqld \
+			--share=/export/data/gn-docs/ \
                         --share=/export2/guix-containers/genenetwork/tmp=/tmp \
                         production.scm)