diff options
author | Efraim Flashner | 2020-12-01 21:15:21 +0200 |
---|---|---|
committer | Efraim Flashner | 2020-12-01 21:15:21 +0200 |
commit | 1d456b37cabefe6caa94cab22e952622c0d26c1f (patch) | |
tree | af89d0e45062d2a3776bb629710f617e03118399 /gn/services | |
parent | 091e1391ffffa54431a224f38c3d64a9a1f63ce2 (diff) | |
download | guix-bioinformatics-1d456b37cabefe6caa94cab22e952622c0d26c1f.tar.gz |
octopus: add slurm services
Diffstat (limited to 'gn/services')
-rw-r--r-- | gn/services/science.scm | 274 |
1 files changed, 231 insertions, 43 deletions
diff --git a/gn/services/science.scm b/gn/services/science.scm index 4b34882..d1f3190 100644 --- a/gn/services/science.scm +++ b/gn/services/science.scm @@ -1,7 +1,13 @@ (define-module (gn services science) #:export (munge-configuration munge-configuration? - munge-service-type)) + munge-service-type + + slurm-configuration + slurm-configuration? + slurmd-service-type + slurmdbd-service-type + slurmctld-service-type)) (use-modules (gnu) (guix records) @@ -9,6 +15,7 @@ (use-service-modules shepherd) (use-package-modules admin parallel) +;; TODO: Make id/uid configurable (define %munge-accounts (list (user-group (name "munge") @@ -23,19 +30,6 @@ (home-directory "/var/lib/munge") (shell (file-append shadow "/sbin/nologin"))))) -(define %slurm-accounts - (list (user-group - (name "slurm") - (id 901) - (system? #t)) - (user-account - (name "slurm") - (group "slurm") - (uid 901) - (system? #t) - (comment "Slurm User") - (home-directory "/var/lib/slurm")))) - (define-record-type* <munge-configuration> munge-configuration make-munge-configuration @@ -51,20 +45,10 @@ (key munge-configuration-key (default "/etc/munge/munge.key"))) -(define-record-type* <slurm-configuration> - slurm-configuration - make-slurm-configuration - slurm-configuration? - (package slurm-configuration-package - (default slurm))) - (define (munge-activation config) "Return the activation GEXP for CONFIG for the munge service." (with-imported-modules '((guix build utils)) #~(begin - (use-modules (guix build utils) - (rnrs bytevectors) - (rnrs io ports)) (define %user (getpw "munge")) (let* ((homedir (passwd:dir %user)) (key #$(munge-configuration-key config)) @@ -78,29 +62,17 @@ (chmod dir #o700)) (list homedir etc-dir log-dir)) (unless (file-exists? key) - ;; Borrowed from /dev/urandom in (gnu services base) - (call-with-input-file "/dev/urandom" - (lambda (urandom) - (let ((buf (make-bytevector 1024))) - (get-bytevector-n! urandom buf 0 1024) - (call-with-output-file key - (lambda (seed) - (put-bytevector seed buf))))))) + (invoke #$(file-append (munge-configuration-package config) + "/sbin/mungekey") + "--create" + (string-append "--bits=" (number->string (* 8 1024))) ; bits, not bytes + (string-append "--keyfile=" key))) (chown key (passwd:uid %user) (passwd:gid %user)) (chmod key #o400) (unless (file-exists? run-dir) (mkdir-p run-dir)) (chown run-dir (passwd:uid %user) (passwd:gid %user)))))) -(define (slurm-activation config) - "Return the activation GEXP for CONFIG for the slurm service." - (with-imported-modules '((guix build utils)) - #~(begin - (use-modules (guix build utils)) - (unless (file-exists? "/var/lib/slurm") - (mkdir-p "/var/lib/slurm")) - (chown "/var/lib/slurm" (passwd:uid "slurm") (passwd:gid "slurm"))))) - (define munge-shepherd-service (match-lambda (($ <munge-configuration> package socket pid-file log-file key) @@ -108,7 +80,7 @@ (shepherd-service (documentation "Munge server") (provision '(munge)) - (requirement '(loopback user-processes file-systems)) + (requirement '(loopback user-processes)) (start #~(make-forkexec-constructor (list #$(file-append package "/sbin/munged") "--foreground" ; "--force" @@ -144,4 +116,220 @@ (compose list munge-configuration-package)))) (default-value (munge-configuration)) (description - "Run a munge service."))) + "Run @url{https://dun.github.io/munge/,Munge}, an authentication service."))) + +;; Initial documentation for upstreaming: +;@subsubheading Munge +; +;The following example describes a Munge service with the default configuration. +; +;@lisp +;(service munge-service-type) +;@end lisp +; +;@deftp {Data Type} munge-configuration +;Data type representing the configuration for the @code{munge-service-type}. +; +;@table @asis +;@item @code{package} +;Munge package to use for the service. +; +;@item @code{socket} (default "/var/run/munge/munge.socket.2") +;The socket Munge should use. +; +;@item @code{pid-file} (default "/var/run/munge/munged.pid") +;The PID file which Munge should use. +; +;@item @code{log-file} (default "/var/log/munge/munged.log") +;The location of the log file Munge should write to. +; +;@item @code{key} (default "/etc/munge/munge.key") +;The location of the shared key Munge should use. Since this a shared secret key between the different nodes it should not be added to the store. +; +;@end table +;@end deftp + + +;; TODO: Make id/uid configurable +(define %slurm-accounts + (list (user-group + (name "slurm") + (id 901) + (system? #t)) + (user-account + (name "slurm") + (group "slurm") + (uid 901) + (system? #t) + (comment "Slurm User") + (home-directory "/var/lib/slurm")))) + +(define-record-type* <slurm-configuration> + slurm-configuration + make-slurm-configuration + slurm-configuration? + ;; As I understand it, all the services depend on also running slurmd on + ;; that machine. Therefore it makes sense to have one config section with + ;; "common" and "extended" options. With all the possible options and + ;; versions we only cover the ones which affect the services. + (package slurm-configuration-package + (default slurm)) + (slurm-conf-file slurm-configuration-slurm-conf-file + (default "/etc/slurm/slurm.conf")) + (slurmd-log-file slurm-configuration-slurmd-log-file + (default "/var/log/slurm/slurmd.log")) + (slurmd-pid-file slurm-configuration-slurmd-pid-file + (default "/var/run/slurm/slurmd.pid")) + + (slurmd-spooldir slurm-configuration-slurmd-spooldir + (default "/var/spool/slurmd")) + + (run-slurmctld? slurm-configuration-run-slurmctld + (default #f)) + (slurmctld-log-file slurm-configuration-slurmctld-log-file + (default "/var/log/slurm/slurmctld.log")) + (slurmctld-pid-file slurm-configuration-slurmctld-pid-file + (default "/var/run/slurm/slurmctld.pid")) + + (run-slurmdbd? slurm-configuration-run-slurmdbd + (default #f)) + (slurmdbd-conf-file slurm-configuration-slurmdbd-conf-file + (default "/etc/slurm/slurmdbd.conf")) + (slurmdbd-pid-file slurm-configuration-slurmdbd-pid-file + (default "/var/run/slurm/slurmdbd.pid"))) + + +(define (slurm-activation config) + "Return the activation GEXP for CONFIG for the slurm service." + (with-imported-modules '((guix build utils)) + #~(begin + (use-modules (guix build utils)) + (define %user (getpw "slurm")) + (let ((homedir (passwd:dir %user)) + (spooldir #$(slurm-configuration-slurmd-spooldir config)) + (logdir (dirname #$(slurm-configuration-slurmd-log-file config))) + (piddir (dirname #$(slurm-configuration-slurmd-pid-file config)))) + (for-each (lambda (dir) + (unless (file-exists? dir) + (mkdir-p dir)) + (chown dir (passwd:uid %user) (passwd:gid %user))) + (list homedir spooldir piddir logdir))) + ;; /etc/slurm/slurm.conf needs to exist. + (file-exists? #$(slurm-configuration-slurm-conf-file config))))) + +(define slurmd-shepherd-service + (match-lambda + (($ <slurm-configuration> package slurm-conf-file slurmd-log-file slurmd-pid-file) + (list + (shepherd-service + (documentation "Slurmd server") + (provision '(slurmd)) + (requirement '(loopback munge)) + (start #~(make-forkexec-constructor + (list #$(file-append package "/sbin/slurmd") + "-L" #$slurmd-log-file + "-f" #$slurm-conf-file) + #:pid-file #$slurmd-pid-file)) + (stop #~(make-kill-destructor))))))) + +(define slurmctld-shepherd-service + (match-lambda + (($ <slurm-configuration> package slurm-conf-file _ _ _ run-slurmctld? slurmctld-log-file slurmctld-pid-file) + (list + (shepherd-service + (documentation "Slurmctld server") + (provision '(slurmctld)) + (requirement '(loopback munge)) + (start #~(make-forkexec-constructor + (list #$(file-append package "/sbin/slurmctld") + "-L" #$slurmctld-log-file + "-f" #$slurm-conf-file) + #:pid-file #$slurmctld-pid-file)) + (stop #~(make-kill-destructor)) + (auto-start? run-slurmctld?)))))) + +(define (slurmdbd-activation config) + "Test the Slurmdbd configration exists." + (file-exists? + (slurm-configuration-slurmdbd-conf-file config))) + +(define slurmdbd-shepherd-service + (match-lambda + (($ <slurm-configuration> package _ _ _ _ _ _ _ run-slurmdbd? slurmdbd-conf-file slurmdbd-pid-file) + (list + (shepherd-service + (documentation "Slurmdbd server") + (provision '(slurmdbd)) + (requirement '(loopback munge)) + (start #~(make-forkexec-constructor + (list #$(file-append package "/sbin/slurmdbd")) + #:pid-file #$slurmdbd-pid-file)) + (stop #~(make-kill-destructor)) + (auto-start? run-slurmdbd?)))))) + +(define (slurm-services-to-run config) + (append (slurmd-shepherd-service config) + (if (slurm-configuration-run-slurmctld? config) + (slurmctld-shepherd-service config) + '()) + (if (slurm-configuration-run-slurmdbd? config) + (slurmdbd-shepherd-service config) + '()))) + +(define (slurm-activations-to-run config) + (append (slurm-activation config) + (if (slurm-configuration-run-slurmctld? config) + (slurmctld-activation config) + '()) + (if (slurm-configuration-run-slurmdbd? config) + (slurmdbd-activation config) + '()))) + +(define slurmd-service-type + (service-type + (name 'slurmd) + (extensions + (list + (service-extension shepherd-root-service-type + ;(cons slurmd-shepherd-service + ; slurmdbd-shepherd-service)) + slurmd-shepherd-service) + ;slurm-services-to-run) + (service-extension activation-service-type + ;(append slurm-activation + ; slurmdbd-activation)) + slurm-activation) + ;slurm-activations-to-run) + (service-extension account-service-type + (const %slurm-accounts)) + (service-extension profile-service-type + (compose list slurm-configuration-package)))) + (default-value (slurm-configuration)) + (description + "Run @url{https://slurm.schedmd.com/slurm.html,Slurm}, a workflow manager service."))) + +(define slurmdbd-service-type + (service-type + (name 'slurmdbd) + (extensions + (list + (service-extension shepherd-root-service-type + slurmdbd-shepherd-service) + (service-extension activation-service-type + slurmdbd-activation))) + (default-value (slurm-configuration)) + (description + ;; TODO: Fix for slurmdbd or integrate with slurm(d). + "Run @url{https://slurm.schedmd.com/slurm.html,Slurm}, a workflow manager service."))) + +(define slurmctld-service-type + (service-type + (name 'slurmctld) + (extensions + (list + (service-extension shepherd-root-service-type + slurmctld-shepherd-service))) + (default-value (slurm-configuration)) + (description + ;; TODO: Fix for slurmctld or integrate with slurm(d). + "Run @url{https://slurm.schedmd.com/slurm.html,Slurm}, a workflow manager service."))) |