aboutsummaryrefslogtreecommitdiff
path: root/src/property/systemd.lisp
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2021-06-30 22:59:11 -0700
committerSean Whitton <spwhitton@spwhitton.name>2021-07-06 21:18:26 -0700
commitb9ec8d60073e9b6ab8ae84c49f0076e3f56d751b (patch)
treedbc09da398c57cc00342f9eb93fba1e6d80aa0a3 /src/property/systemd.lisp
parentff636c86378e1b73c235f7fd783e7526760c3721 (diff)
downloadconsfigurator-b9ec8d60073e9b6ab8ae84c49f0076e3f56d751b.tar.gz
basic systemctl(1) properties: add :CHECK subroutines
Signed-off-by: Sean Whitton <spwhitton@spwhitton.name>
Diffstat (limited to 'src/property/systemd.lisp')
-rw-r--r--src/property/systemd.lisp30
1 files changed, 18 insertions, 12 deletions
diff --git a/src/property/systemd.lisp b/src/property/systemd.lisp
index c417df6..b38ed5d 100644
--- a/src/property/systemd.lisp
+++ b/src/property/systemd.lisp
@@ -20,27 +20,33 @@
(defprop started :posix (service)
(:desc #?"systemd service ${service} started")
- (:apply (mrun "systemctl" "start" service)
- :no-change))
+ (:check (zerop (mrun :for-exit "systemctl" "is-active" service)))
+ (:apply (mrun "systemctl" "start" service)))
(defprop stopped :posix (service)
(:desc #?"systemd service ${service} stopped")
- (:apply (mrun "systemctl" "stop" service)
- :no-change))
+ (:check (plusp (mrun :for-exit "systemctl" "is-active" service)))
+ (:apply (mrun "systemctl" "stop" service)))
(defprop enabled :posix (service)
(:desc #?"systemd service ${service} enabled")
- (:apply (mrun "systemctl" "enable" service)
- :no-change))
+ (:check (zerop (mrun :for-exit "systemctl" "is-enabled" service)))
+ (:apply (mrun "systemctl" "enable" service)))
(defprop disabled :posix (service)
(:desc #?"systemd service ${service} disabled")
- (:apply (mrun "systemctl" "disable" service)
- :no-change))
+ (:check
+ (let ((status (stripln (run :may-fail "systemctl" "is-enabled" service))))
+ (or (string-prefix-p "linked" status)
+ (string-prefix-p "masked" status)
+ (memstring=
+ status
+ '("static" "disabled" "generated" "transient" "indirect")))))
+ (:apply (mrun "systemctl" "disable" service)))
(defprop masked :posix (service)
(:desc #?"systemd service ${service} masked")
- (:apply (mrun "systemctl" "mask" service)
- :no-change)
- (:unapply (mrun "systemctl" "unmask" service)
- :no-change))
+ (:check (string-prefix-p "masked"
+ (run :may-fail "systemctl" "is-enabled" service)))
+ (:apply (mrun "systemctl" "mask" service))
+ (:unapply (mrun "systemctl" "unmask" service)))