From d55b35d119592ee5aa452f7f1e98a885f5ed5fa9 Mon Sep 17 00:00:00 2001 From: Efraim Flashner Date: Tue, 28 Apr 2020 05:44:52 -0500 Subject: WIP ratspub service --- gn/services/ratspub-container.scm | 94 +++++++++++++++++++++++++++++++++++++++ gn/services/ratspub.service | 13 ++++++ 2 files changed, 107 insertions(+) create mode 100644 gn/services/ratspub-container.scm create mode 100644 gn/services/ratspub.service diff --git a/gn/services/ratspub-container.scm b/gn/services/ratspub-container.scm new file mode 100644 index 0000000..c026247 --- /dev/null +++ b/gn/services/ratspub-container.scm @@ -0,0 +1,94 @@ +(define-module (gn services ratspub-container)) + +(use-modules (gnu) + (gn packages ratspub) + (gn packages bioinformatics) + (guix modules) + (guix records) + (ice-9 match)) +(use-service-modules networking shepherd) +(use-package-modules certs) + +(define-record-type* + ratspub-configuration + make-ratspub-configuration + ratspub-configuration? + (package ratspub-configuration-package ; package + (default ratspub)) + (deploy-directory ratspub-configuration-deploy-directory + (default "/srv/http"))) + +(define ratspub-activation + (match-lambda + (($ package deploy-directory) + #~(begin + (use-modules (guix build utils)) + (when (directory-exists? #$deploy-directory) + ;; Not 'delete-file-recursively' because the directory might be empty. + (and (string-append #$coreutils "/bin/rm" "-r " #$deploy-directory "/*") + (delete-file #$deploy-directory))) + (mkdir-p #$deploy-directory) + (copy-recursively #$package #$deploy-directory))))) + +(define ratspub-shepherd-service + (match-lambda + (($ package deploy-directory) + (with-imported-modules (source-module-closure + '((gnu build shepherd) + (gnu system file-systems))) + (list (shepherd-service + (provision '(ratspub)) + (requirement '(networking)) + (modules '((gnu build shepherd) + (gnu system file-systems))) + (start #~(make-forkexec-constructor + '("./server.py") + #:directory "/srv/http" + #:environment-variables + '("EDIRECT_PUBMED_MASTER=/export2/PubMed" + "NLTK_DATA=/export2/PubMed/nltk_data" + "PERL_LWP_SSL_CA_FILE=/run/current-system/profile/etc/ssl/certs/ca-certificates.crt" + ;"PATH=/run/current-system/profile/bin" + ) + #:mappings (list (file-system-mapping + (source "/export2/PubMed") + (target source) + (writable? #t)) + ) + )) + (stop #~(make-kill-destructor)))))))) + +(define ratspub-service-type + (service-type + (name 'ratspub) + (extensions + (list + (service-extension activation-service-type + ratspub-activation) + (service-extension shepherd-root-service-type + ratspub-shepherd-service) + ;; Make sure RatsPub doesn't get garbage collected. + (service-extension profile-service-type + (compose list ratspub-configuration-package)))) + (default-value (ratspub-configuration)) + (description + "Run a RatsPub Webserver."))) + +(operating-system + ;(host-name "ratspub") + (host-name "penguin2") ; hardcoded in ratspub.py + (timezone "Etc/UTC") + (locale "en_US.utf8") + + (bootloader (bootloader-configuration + (bootloader grub-bootloader) + (target "does-not-matter"))) + (file-systems %base-file-systems) + ;; No firmware for VMs. + (firmware '()) + ;; We don't need any packages inside the container. + ;(packages '()) + (packages (list edirect-gn sed nss-certs)) + + (services (list (service dhcp-client-service-type) + (service ratspub-service-type)))) diff --git a/gn/services/ratspub.service b/gn/services/ratspub.service new file mode 100644 index 0000000..91b9509 --- /dev/null +++ b/gn/services/ratspub.service @@ -0,0 +1,13 @@ +[Unit] +Description=Rats.pub web server + +[Service] +ExecStart=/home/gn-rshiny/run_ratspub.sh +#WorkingDirectory=/home/gn-shiny/ratspub +#ExecStartPre='/bin/cp -r $(/var/guix/profiles/per-user/efraimf/current-guix/bin/guix build ratspub)/* /home/gn-shiny/ratspub' +#ExecStop='/bin/rm -rf /home/gn-shiny/ratspub/*' +Environment="EDIRECT_PUBMED_MASTER=/export2/PubMed" "NLTK_DATA=/export2/PubMed/nltk_data" "PERL_LWP_SSL_CA_FILE=/etc/ssl/certs/ca-certificates.crt" +Restart=always + +[Install] +WantedBy=multi-user.target -- cgit v1.2.3