aboutsummaryrefslogtreecommitdiff
path: root/src/property/swap.lisp
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2021-07-09 20:43:37 -0700
committerSean Whitton <spwhitton@spwhitton.name>2021-07-10 21:42:22 -0700
commit939517b23d9f65183cfe3d24c9c2c09108add50f (patch)
treea82ee0778ffa3fec13f1d75b3c63511691f3e218 /src/property/swap.lisp
parent886b3bd27a6f5f31895874d256c98184ea9c23b9 (diff)
downloadconsfigurator-939517b23d9f65183cfe3d24c9c2c09108add50f.tar.gz
add SWAP:HAS-SWAP-FILE
Signed-off-by: Sean Whitton <spwhitton@spwhitton.name>
Diffstat (limited to 'src/property/swap.lisp')
-rw-r--r--src/property/swap.lisp42
1 files changed, 42 insertions, 0 deletions
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 <spwhitton@spwhitton.name>
+
+;;; 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 <http://www.gnu.org/licenses/>.
+
+(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")))