Coverage report: /home/ellis/comp/core/lib/cli/tools/sys.lisp

KindCoveredAll%
expression065 0.0
branch02 0.0
Key
Not instrumented
Conditionalized out
Executed
Not executed
 
Both branches taken
One branch taken
Neither branch taken
1
 ;;; sys.lisp --- System CLI Tools
2
 
3
 ;; 
4
 
5
 ;;; Code:
6
 (in-package :cli/tools/sys)
7
 
8
 (deferror systemd-error (simple-error error) ())
9
 
10
 (defun systemd-error (fmt &rest args)
11
   (error 'systemd-error :format-arguments args :format-control fmt))
12
 
13
 (defparameter *systemctl* (find-exe "systemctl"))
14
 
15
 (defun run-systemctl (args &key (output t))
16
   (let ((proc (sb-ext:run-program *systemctl* (or args nil) :output output)))
17
     (unless (or (= 0 #1=(sb-ext:process-exit-code proc))
18
                 (= 3 #1#))
19
       (systemd-error "SYSTEMCTL command failed: ~A ~A" *systemctl* (or args "")))))
20
 
21
 (defun systemctl-start (&rest args)
22
   (run-systemctl `("start" ,@args)))
23
 
24
 (defun systemctl-stop (&rest args)
25
   (run-systemctl `("stop" ,@args)))
26
 
27
 (defun systemctl-status (unit &key (user t) (lines 20))
28
   (run-systemctl 
29
    `("status" ,@(when lines `("--lines" ,(format nil "~A" lines)))
30
               "--no-pager"
31
               ,@(when user '("--user")) 
32
               ,unit)))
33
 
34
 (defun systemctl-restart (&rest args)
35
   (run-systemctl `("restart" ,@args)))
36
 
37
 (defun systemctl-json (&rest args)
38
   (deserialize
39
    (with-output-to-string (s)
40
      (run-systemctl (concatenate 'list '("-q" "-o" "json") args) :output s))
41
    :json))
42
 
43
 ;; (systemctl-json "--user")