From 939517b23d9f65183cfe3d24c9c2c09108add50f Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Fri, 9 Jul 2021 20:43:37 -0700 Subject: add SWAP:HAS-SWAP-FILE Signed-off-by: Sean Whitton --- consfigurator.asd | 1 + src/package.lisp | 7 +++++++ src/property/swap.lisp | 42 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+) create mode 100644 src/property/swap.lisp diff --git a/consfigurator.asd b/consfigurator.asd index dbc2564..73e82d3 100644 --- a/consfigurator.asd +++ b/consfigurator.asd @@ -63,6 +63,7 @@ (:file "src/property/systemd") (:file "src/property/firewalld") (:file "src/property/timezone") + (:file "src/property/swap") (:file "src/connection/shell-wrap") (:file "src/connection/fork") (:file "src/connection/rehome") diff --git a/src/package.lisp b/src/package.lisp index cf35b50..631f3f7 100644 --- a/src/package.lisp +++ b/src/package.lisp @@ -775,6 +775,13 @@ (:export #:configured #:configured-from-parent)) +(defpackage :consfigurator.property.swap + (:use #:cl #:consfigurator) + (:local-nicknames (#:cmd #:consfigurator.property.cmd) + (#:fstab #:consfigurator.property.fstab) + (#:os #:consfigurator.property.os)) + (:export #:has-swap-file)) + (defpackage :consfigurator.connection.local (:use #:cl #:consfigurator #:alexandria) (:export #:local-connection)) diff --git a/src/property/swap.lisp b/src/property/swap.lisp new file mode 100644 index 0000000..b3ab9c9 --- /dev/null +++ b/src/property/swap.lisp @@ -0,0 +1,42 @@ +;;; Consfigurator -- Lisp declarative configuration management system + +;;; Copyright (C) 2021 Sean Whitton + +;;; This file 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, or (at your option) +;;; any later version. + +;;; This file 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 this program. If not, see . + +(in-package :consfigurator.property.swap) +(named-readtables:in-readtable :consfigurator) + +(defprop %swapfile-exists :posix (size location) + (:check + (declare (ignore size)) + (remote-exists-p location)) + (:apply + (mrun #?"umask 077; fallocate -l ${size} ${(unix-namestring location)}") + (mrun "mkswap" location)) + (:unapply + (declare (ignore size)) + (mrun :may-fail "swapoff" location) + (delete-remote-trees location))) + +(defproplist has-swap-file :posix + (size &optional (location #P"/var/lib/swapfile")) + "Add a swap file. SIZE is the -l argument to fallocate(1). +Current implementation assumes a non-CoW filesystem; see NOTES in swapon(8)." + (:desc #?"Has swapfile of size ${size}") + (:hostattrs (os:required 'os:linux)) + (on-apply-change (%swapfile-exists size location) + (cmd:single "swapon" location)) + (fstab:entries + (strcat (unix-namestring location) " swap swap defaults 0 0"))) -- cgit v1.2.3