rekahsoft: Refactor mounting of cephfs into guix service

* .guix/rekahsoft-gnu/services/ceph.scm: New file (which is expected to be removed once this
is moved upstream to the rekahsoft-guix channel). Defines cephfs configuration and guix
service which allows easy setup of cephfs filesystems

* .guix/rekahsoft/guix-config/vms/cloud0-home-rekahsoft-ca.scm (rekahsoft): Refactor to use
new cephfs-service to mount cephfs
This commit is contained in:
Collin J. Doering 2023-03-26 19:57:02 -04:00
parent 462ab6ac3d
commit 9b73115e7c
Signed by: rekahsoft
GPG Key ID: 7B4DEB93212B3022
2 changed files with 130 additions and 48 deletions

View File

@ -0,0 +1,105 @@
;;; Copyright © 2023 Collin J. Doering <collin@rekahsoft.ca>
;;;
;;; This file is part of the GNU Guix channel rekahsoft-guix
;;;
;;; The rekahsoft-guix channel for 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.
;;;
;;; The rekahsoft-guix channel for 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 the rekahsoft-guix channel for GNU Guix. If not, see
;;; <http://www.gnu.org/licenses/>.
(define-module (rekahsoft-gnu services ceph)
#:use-module (gnu services configuration)
#:use-module (gnu packages storage)
#:use-module (guix packages)
#:use-module (ice-9 match)
#:use-module (gnu services shepherd)
#:use-module (gnu)
#:export (cephfs-configuration cephfs-configuration? cephfs-service-type))
(define-configuration/no-serialization cephfs-configuration
(package
(package ceph)
"The ceph package to use.")
(mount-point
(string)
"Mount point used for cephfs filesystem.")
(name
(string)
"The Rados client (user) name.")
(fsid
(string)
"The CephFS file-system id.")
(fs-name
(string)
"A symbolic name to use for the CephFS mount.")
(options
(string "rw,relatime,acl")
"File-system mount options. Defaults to 'rw,relatime,acl'")
(secret-file
(string)
"Secret file path to use for authentication.")
(monitors
(list-of-strings)
"A list of monitor addresses in the form of <host>:<port>.")
(subdir
(string "/")
"An optional subdirectory to mount (defaults to '/').")
(legacy-mount-syntax?
(boolean #f)
"Use the legacy mount.ceph syntax; see ceph.mount documentation for more details."))
(define cephfs-shepherd-service
(match-lambda
(($ <cephfs-configuration> package mount-point name fsid fs-name options secret-file monitors subdir legacy-mount-syntax?)
(list (shepherd-service
(provision (list (string->symbol (string-append "cephfs-" mount-point))))
(documentation (string-append "Mount cephfs filesystem '" fsid "' (" mount-point ")."))
(requirement `(networking ,(string->symbol (string-append "file-system-" mount-point))))
(start #~(make-system-constructor "/run/setuid-programs/mount /mnt/cephfs"))
(stop #~(make-system-constructor "/run/setuid-programs/umount /mnt/cephfs"))
(respawn? #f))))))
;; Mount syntax changed between ceph 16 and 17, however the old syntax is still supported
;;
;; 16.x Pacific - https://docs.ceph.com/en/pacific/man/8/mount.ceph/
;; mount.ceph [mon1_socket,mon2_socket,…]:/[subdir] dir [-o options]
;; 17.x Quincy - https://docs.ceph.com/en/quincy/man/8/mount.ceph/
;; mount.ceph name*@*fsid.*fs_name*=/[subdir] dir [-o options]
(define cephfs-file-systems
(match-lambda
(($ <cephfs-configuration> package mount-point name fsid fs-name options secret-file monitors subdir legacy-mount-syntax?)
(list (file-system
(device (if legacy-mount-syntax?
(string-append (string-join monitors ",") ":" subdir)
(string-append name "@" fsid "." fs-name "=" subdir)))
(options (string-append options ","
(if legacy-mount-syntax?
(string-append "name=" name)
(string-append "mon_addr=" (string-join monitors "/")))
",secretfile=" secret-file))
;; Filesystem cannot be mounted as its not a real device; instead a shepherd service is used to mount the file-system
(mount? #f)
(create-mount-point? #t)
(mount-point mount-point)
(type "ceph"))))))
(define cephfs-profile
(compose list cephfs-configuration-package))
(define cephfs-service-type
(service-type
(name 'cephfs)
(description "Mount cephfs filesystems.")
(extensions
(list (service-extension shepherd-root-service-type cephfs-shepherd-service)
(service-extension file-system-service-type cephfs-file-systems)
(service-extension profile-service-type cephfs-profile)))))

View File

@ -7,58 +7,35 @@
#:use-module (gnu services docker)
#:use-module (gnu services shepherd)
#:use-module (rekahsoft guix-config proxmox-vm-lvm-minimal)
#:use-module (rekahsoft-gnu services ceph)
#:export (%system))
(define base-system (proxmox-vm-lvm-minimal "cloud0"))
(define cephfs-service
(simple-service 'cephfs shepherd-root-service-type
(list (shepherd-service
(provision '(cephfs))
(requirement '(networking file-system-/mnt/cephfs))
(start #~(make-system-constructor "/run/setuid-programs/mount /mnt/cephfs"))
(stop #~(make-system-constructor "/run/setuid-programs/umount /mnt/cephfs"))
(respawn? #f)))))
;; TODO: run nextcloud docker container as shepherd service
;; TODO: Manually setup basic nextcloud cron on guix host; this should be replaced with configuration as code - THIS DOESN'T ACTUALLY WORK. The manually created crontab is not exected.
;; TODO: add mcron job for nextcloud cron: 'docker exec -t -u www-data nextcloud php --define apc.enable_cli=1 -f /var/www/html/cron.php'
;; TODO: add mcron job for nextcloud preview generation: 'docker exec -t -u www-data nextcloud php occ preview:pre-generate'
(define %system
(operating-system
(inherit base-system)
(users (cons*
(user-account
(name "collin")
(comment "Master User")
(group "users")
(shell #~(string-append #$zsh "/bin/zsh"))
(supplementary-groups
'("wheel" "netdev" "audio" "video" "docker"))
(home-directory "/home/collin"))
(operating-system-users base-system)))
(inherit base-system)
(users (cons*
(user-account
(name "collin")
(comment "Master User")
(group "users")
(shell #~(string-append #$zsh "/bin/zsh"))
(supplementary-groups
'("wheel" "netdev" "audio" "video" "docker"))
(home-directory "/home/collin"))
(operating-system-users base-system)))
(file-systems
(append
(list (file-system
(device "172.16.0.20,172.16.0.21,172.16.0.22:/file-vault/nextcloud")
(options "rw,relatime,name=file-vault-nextcloud,secretfile=/etc/ceph/ceph.client.file-vault-nextcloud.key,acl")
;; Filesystem cannot be mounted as its not a real device; instead a shepherd service is used to mount the file-system
(mount? #f)
(create-mount-point? #t)
(mount-point "/mnt/cephfs")
(type "ceph")))
(operating-system-file-systems base-system)))
(packages
(append
(map specification->package
'("ceph"))
(operating-system-packages base-system)))
(services
(append
(list (service docker-service-type)
cephfs-service)
%proxmox-vm-lvm-minimal-services))))
(services
(append
(list (service docker-service-type)
(service cephfs-service-type
(cephfs-configuration
(name "file-vault-nextcloud")
(mount-point "/mnt/cephfs")
(fsid "0f2890c4-3a78-4859-b7c1-43f749b127b3")
(fs-name "cephfs")
(secret-file "/etc/ceph/ceph.client.file-vault-nextcloud.key")
(monitors (list "172.16.0.20" "172.16.0.21" "172.16.0.22"))
(subdir "/file-vault/nextcloud"))))
%proxmox-vm-lvm-minimal-services))))