aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2021-03-19 18:41:37 -0700
committerSean Whitton <spwhitton@spwhitton.name>2021-03-19 18:56:59 -0700
commit85f2ea158ea75776bd1a83b0cf28342d7005beb5 (patch)
tree3333188943f3d069a97fb2b193f0c8efcb9cfd92
parentbb54fc263a201dc950d6392886c498410ac3e4cf (diff)
downloadconsfigurator-85f2ea158ea75776bd1a83b0cf28342d7005beb5.tar.gz
add SERVICE:NO-SERVICES, SERVICE:RUNNING
Signed-off-by: Sean Whitton <spwhitton@spwhitton.name>
-rw-r--r--consfigurator.asd1
-rw-r--r--src/package.lisp7
-rw-r--r--src/property/service.lisp58
3 files changed, 66 insertions, 0 deletions
diff --git a/consfigurator.asd b/consfigurator.asd
index b487645..ab95b69 100644
--- a/consfigurator.asd
+++ b/consfigurator.asd
@@ -30,6 +30,7 @@
(:file "src/property/cmd")
(:file "src/property/file")
(:file "src/property/os")
+ (:file "src/property/service")
(:file "src/property/apt")
(:file "src/property/chroot")
(:file "src/property/user")
diff --git a/src/package.lisp b/src/package.lisp
index 67cf368..b496ff2 100644
--- a/src/package.lisp
+++ b/src/package.lisp
@@ -237,6 +237,13 @@
#:required
#:supports-arch-p))
+(defpackage :consfigurator.property.service
+ (:use #:cl #:alexandria #:consfigurator)
+ (:local-nicknames (#:os #:consfigurator.property.os)
+ (#:file #:consfigurator.property.file))
+ (:export #:no-services
+ #:running))
+
(defpackage :consfigurator.property.apt
(:use #:cl #:alexandria #:consfigurator)
(:local-nicknames (#:re #:cl-ppcre)
diff --git a/src/property/service.lisp b/src/property/service.lisp
new file mode 100644
index 0000000..7ab220b
--- /dev/null
+++ b/src/property/service.lisp
@@ -0,0 +1,58 @@
+;;; 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.service)
+(named-readtables:in-readtable :interpol-syntax)
+
+;;;; Controlling services using service(1)
+
+(define-constant +policyrcd+ #P"/usr/sbin/policy-rc.d" :test #'equal)
+(define-constant +policyrcd~+ #P"/usr/sbin/policy-rc.d~consfig" :test #'equal)
+
+(defprop %no-services :posix ()
+ (:hostattrs
+ (push-hostattrs :no-services t)))
+
+(defprop %policy-rc.d :posix ()
+ (:apply
+ (assert-euid-root)
+ (when (test "-e" +policyrcd+ "-a" "!" "-e" +policyrcd~+)
+ (mrun "mv" +policyrcd+ +policyrcd~+))
+ (file:has-content +policyrcd+ '("#!/bin/sh" "exit 101"))
+ (file:has-mode +policyrcd+ #o755))
+ (:unapply
+ (assert-euid-root)
+ (if (test "-e" +policyrcd~+)
+ (mrun "mv" +policyrcd~+ +policyrcd+)
+ (file:does-not-exist +policyrcd+))))
+
+(defproplist no-services :posix ()
+ "Disable starting services with service(1) and by the package manager."
+ (:desc #?"Starting services disabled")
+ (%no-services)
+ (os:typecase
+ (debian (%policy-rc.d))))
+
+(defprop running :posix (service)
+ "Attempt to start service using service(1).
+Assumes that if service(1) returns nonzero, it means the service was already
+running. If something more robust is required, use init system-specific
+properties."
+ (:desc #?"Attempt to start ${service} has been made")
+ (:apply
+ (unless (get-hostattrs-car :no-services)
+ (run :may-fail "service" service "start"))))