diff options
| author | Christopher Baines <mail@cbaines.net> | 2017-06-24 14:19:46 +0100 |
|---|---|---|
| committer | Christopher Baines <mail@cbaines.net> | 2017-07-29 12:45:03 +0100 |
| commit | 730ed6ec8b69a0f908a8aadbbe0555dd45de227c (patch) | |
| tree | 68448b94cc257c8b034a668ca6b45f4712e7b86b /gnu/services/admin.scm | |
| parent | b5244fcb49804922e34fffb18d71908dac37b303 (diff) | |
gnu: services: admin: Add tailon.
* gnu/services/admin.scm
(<tailon-configuration>, <tailon-configuration-file>): New record types.
(tailon-configuration-files-string, tailon-shepherd-service): New
procedures.
(%tailon-accounts, tailon-service-type: New variables.
* doc/guix.texi (Monitoring Services: Document the Tailon service.
* gnu/local.mk (GNU_SYSTEM_MODULES): Add gnu/tests/admin.scm.
* gnu/tests/admin.scm: New file.
Diffstat (limited to 'gnu/services/admin.scm')
| -rw-r--r-- | gnu/services/admin.scm | 151 |
1 files changed, 150 insertions, 1 deletions
diff --git a/gnu/services/admin.scm b/gnu/services/admin.scm index b9e3fa70a45..1044833fef0 100644 --- a/gnu/services/admin.scm +++ b/gnu/services/admin.scm | |||
| @@ -20,14 +20,19 @@ | |||
| 20 | (define-module (gnu services admin) | 20 | (define-module (gnu services admin) |
| 21 | #:use-module (gnu packages admin) | 21 | #:use-module (gnu packages admin) |
| 22 | #:use-module (gnu packages base) | 22 | #:use-module (gnu packages base) |
| 23 | #:use-module (gnu packages logging) | ||
| 23 | #:use-module (gnu services) | 24 | #:use-module (gnu services) |
| 24 | #:use-module (gnu services mcron) | 25 | #:use-module (gnu services mcron) |
| 25 | #:use-module (gnu services shepherd) | 26 | #:use-module (gnu services shepherd) |
| 27 | #:use-module (gnu services web) | ||
| 28 | #:use-module (gnu system shadow) | ||
| 26 | #:use-module (guix gexp) | 29 | #:use-module (guix gexp) |
| 30 | #:use-module (guix store) | ||
| 27 | #:use-module (guix packages) | 31 | #:use-module (guix packages) |
| 28 | #:use-module (guix records) | 32 | #:use-module (guix records) |
| 29 | #:use-module (srfi srfi-1) | 33 | #:use-module (srfi srfi-1) |
| 30 | #:use-module (ice-9 vlist) | 34 | #:use-module (ice-9 vlist) |
| 35 | #:use-module (ice-9 match) | ||
| 31 | #:export (%default-rotations | 36 | #:export (%default-rotations |
| 32 | %rotated-files | 37 | %rotated-files |
| 33 | 38 | ||
| @@ -41,7 +46,27 @@ | |||
| 41 | rottlog-configuration | 46 | rottlog-configuration |
| 42 | rottlog-configuration? | 47 | rottlog-configuration? |
| 43 | rottlog-service | 48 | rottlog-service |
| 44 | rottlog-service-type)) | 49 | rottlog-service-type |
| 50 | |||
| 51 | <tailon-configuration-file> | ||
| 52 | tailon-configuration-file | ||
| 53 | tailon-configuration-file? | ||
| 54 | tailon-configuration-file-files | ||
| 55 | tailon-configuration-file-bind | ||
| 56 | tailon-configuration-file-relative-root | ||
| 57 | tailon-configuration-file-allow-transfers? | ||
| 58 | tailon-configuration-file-follow-names? | ||
| 59 | tailon-configuration-file-tail-lines | ||
| 60 | tailon-configuration-file-allowed-commands | ||
| 61 | tailon-configuration-file-debug? | ||
| 62 | |||
| 63 | <tailon-configuration> | ||
| 64 | tailon-configuration | ||
| 65 | tailon-configuration? | ||
| 66 | tailon-configuration-config-file | ||
| 67 | tailon-configuration-package | ||
| 68 | |||
| 69 | tailon-service-type)) | ||
| 45 | 70 | ||
| 46 | ;;; Commentary: | 71 | ;;; Commentary: |
| 47 | ;;; | 72 | ;;; |
| @@ -172,4 +197,128 @@ for ROTATION." | |||
| 172 | rotations))))) | 197 | rotations))))) |
| 173 | (default-value (rottlog-configuration)))) | 198 | (default-value (rottlog-configuration)))) |
| 174 | 199 | ||
| 200 | |||
| 201 | ;;; | ||
| 202 | ;;; Tailon | ||
| 203 | ;;; | ||
| 204 | |||
| 205 | (define-record-type* <tailon-configuration-file> | ||
| 206 | tailon-configuration-file make-tailon-configuration-file | ||
| 207 | tailon-configuration-file? | ||
| 208 | (files tailon-configuration-file-files | ||
| 209 | (default '("/var/log"))) | ||
| 210 | (bind tailon-configuration-file-bind | ||
| 211 | (default "localhost:8080")) | ||
| 212 | (relative-root tailon-configuration-file-relative-root | ||
| 213 | (default #f)) | ||
| 214 | (allow-transfers? tailon-configuration-file-allow-transfers? | ||
| 215 | (default #t)) | ||
| 216 | (follow-names? tailon-configuration-file-follow-names? | ||
| 217 | (default #t)) | ||
| 218 | (tail-lines tailon-configuration-file-tail-lines | ||
| 219 | (default 200)) | ||
| 220 | (allowed-commands tailon-configuration-file-allowed-commands | ||
| 221 | (default '("tail" "grep" "awk"))) | ||
| 222 | (debug? tailon-configuration-file-debug? | ||
| 223 | (default #f))) | ||
| 224 | |||
| 225 | (define (tailon-configuration-files-string files) | ||
| 226 | (string-append | ||
| 227 | "\n" | ||
| 228 | (string-join | ||
| 229 | (map | ||
| 230 | (lambda (x) | ||
| 231 | (string-append | ||
| 232 | " - " | ||
| 233 | (cond | ||
| 234 | ((string? x) | ||
| 235 | (simple-format #f "'~A'" x)) | ||
| 236 | ((list? x) | ||
| 237 | (string-join | ||
| 238 | (cons (simple-format #f "'~A':" (car x)) | ||
| 239 | (map | ||
| 240 | (lambda (x) (simple-format #f " - '~A'" x)) | ||
| 241 | (cdr x))) | ||
| 242 | "\n")) | ||
| 243 | (else (error x))))) | ||
| 244 | files) | ||
| 245 | "\n"))) | ||
| 246 | |||
| 247 | (define-gexp-compiler (tailon-configuration-file-compiler | ||
| 248 | (file <tailon-configuration-file>) system target) | ||
| 249 | (match file | ||
| 250 | (($ <tailon-configuration-file> files bind relative-root | ||
| 251 | allow-transfers? follow-names? | ||
| 252 | tail-lines allowed-commands debug?) | ||
| 253 | (text-file | ||
| 254 | "tailon-config.yaml" | ||
| 255 | (string-concatenate | ||
| 256 | (filter-map | ||
| 257 | (match-lambda | ||
| 258 | ((key . #f) #f) | ||
| 259 | ((key . value) (string-append key ": " value "\n"))) | ||
| 260 | |||
| 261 | `(("files" . ,(tailon-configuration-files-string files)) | ||
| 262 | ("bind" . ,bind) | ||
| 263 | ("relative-root" . ,relative-root) | ||
| 264 | ("allow-transfers" . ,(if allow-transfers? "true" "false")) | ||
| 265 | ("follow-names" . ,(if follow-names? "true" "false")) | ||
| 266 | ("tail-lines" . ,(number->string tail-lines)) | ||
| 267 | ("commands" . ,(string-append "[" | ||
| 268 | (string-join allowed-commands ", ") | ||
| 269 | "]")) | ||
| 270 | ,@(if debug? '(("debug" . "true")) '())))))))) | ||
| 271 | |||
| 272 | (define-record-type* <tailon-configuration> | ||
| 273 | tailon-configuration make-tailon-configuration | ||
| 274 | tailon-configuration? | ||
| 275 | (config-file tailon-configuration-config-file | ||
| 276 | (default (tailon-configuration-file))) | ||
| 277 | (package tailon-configuration-package | ||
| 278 | (default tailon))) | ||
| 279 | |||
| 280 | (define tailon-shepherd-service | ||
| 281 | (match-lambda | ||
| 282 | (($ <tailon-configuration> config-file package) | ||
| 283 | (list (shepherd-service | ||
| 284 | (provision '(tailon)) | ||
| 285 | (documentation "Run the tailon daemon.") | ||
| 286 | (start #~(make-forkexec-constructor | ||
| 287 | `(,(string-append #$package "/bin/tailon") | ||
| 288 | "-c" ,#$config-file) | ||
| 289 | #:user "tailon" | ||
| 290 | #:group "tailon")) | ||
| 291 | (stop #~(make-kill-destructor))))))) | ||
| 292 | |||
| 293 | (define %tailon-accounts | ||
| 294 | (list (user-group (name "tailon") (system? #t)) | ||
| 295 | (user-account | ||
| 296 | (name "tailon") | ||
| 297 | (group "tailon") | ||
| 298 | (system? #t) | ||
| 299 | (comment "tailon") | ||
| 300 | (home-directory "/var/empty") | ||
| 301 | (shell (file-append shadow "/sbin/nologin"))))) | ||
| 302 | |||
| 303 | (define tailon-service-type | ||
| 304 | (service-type | ||
| 305 | (name 'tailon) | ||
| 306 | (extensions | ||
| 307 | (list (service-extension shepherd-root-service-type | ||
| 308 | tailon-shepherd-service) | ||
| 309 | (service-extension account-service-type | ||
| 310 | (const %tailon-accounts)))) | ||
| 311 | (compose concatenate) | ||
| 312 | (extend (lambda (parameter files) | ||
| 313 | (tailon-configuration | ||
| 314 | (inherit parameter) | ||
| 315 | (config-file | ||
| 316 | (let ((old-config-file | ||
| 317 | (tailon-configuration-config-file parameter))) | ||
| 318 | (tailon-configuration-file | ||
| 319 | (inherit old-config-file) | ||
| 320 | (files (append (tailon-configuration-file-files old-config-file) | ||
| 321 | files)))))))) | ||
| 322 | (default-value (tailon-configuration)))) | ||
| 323 | |||
| 175 | ;;; admin.scm ends here | 324 | ;;; admin.scm ends here |
