services: web: Switch nginx related functions to use match-record.
As this is less prone to mistakes than match. * gnu/services/web.scm (default-nginx-config, nginx-activation, nginx-shepherd-service): Switch from using match-lambda to match-record.
This commit is contained in:
parent
2881f85220
commit
472368a8ac
1 changed files with 81 additions and 85 deletions
|
@ -231,39 +231,43 @@ of index files."
|
||||||
(cons head out)))
|
(cons head out)))
|
||||||
(fold-right flatten1 '() lst))
|
(fold-right flatten1 '() lst))
|
||||||
|
|
||||||
(define (default-nginx-config nginx log-directory run-directory server-list
|
(define (default-nginx-config config)
|
||||||
upstream-list server-names-hash-bucket-size
|
(match-record config
|
||||||
server-names-hash-bucket-max-size)
|
<nginx-configuration>
|
||||||
(apply mixed-text-file "nginx.conf"
|
(nginx log-directory run-directory
|
||||||
(flatten
|
server-blocks upstream-blocks
|
||||||
"user nginx nginx;\n"
|
server-names-hash-bucket-size
|
||||||
"pid " run-directory "/pid;\n"
|
server-names-hash-bucket-max-size)
|
||||||
"error_log " log-directory "/error.log info;\n"
|
(apply mixed-text-file "nginx.conf"
|
||||||
"http {\n"
|
(flatten
|
||||||
" client_body_temp_path " run-directory "/client_body_temp;\n"
|
"user nginx nginx;\n"
|
||||||
" proxy_temp_path " run-directory "/proxy_temp;\n"
|
"pid " run-directory "/pid;\n"
|
||||||
" fastcgi_temp_path " run-directory "/fastcgi_temp;\n"
|
"error_log " log-directory "/error.log info;\n"
|
||||||
" uwsgi_temp_path " run-directory "/uwsgi_temp;\n"
|
"http {\n"
|
||||||
" scgi_temp_path " run-directory "/scgi_temp;\n"
|
" client_body_temp_path " run-directory "/client_body_temp;\n"
|
||||||
" access_log " log-directory "/access.log;\n"
|
" proxy_temp_path " run-directory "/proxy_temp;\n"
|
||||||
" include " nginx "/share/nginx/conf/mime.types;\n"
|
" fastcgi_temp_path " run-directory "/fastcgi_temp;\n"
|
||||||
(if server-names-hash-bucket-size
|
" uwsgi_temp_path " run-directory "/uwsgi_temp;\n"
|
||||||
(string-append
|
" scgi_temp_path " run-directory "/scgi_temp;\n"
|
||||||
" server_names_hash_bucket_size "
|
" access_log " log-directory "/access.log;\n"
|
||||||
(number->string server-names-hash-bucket-size)
|
" include " nginx "/share/nginx/conf/mime.types;\n"
|
||||||
";\n")
|
(if server-names-hash-bucket-size
|
||||||
"")
|
(string-append
|
||||||
(if server-names-hash-bucket-max-size
|
" server_names_hash_bucket_size "
|
||||||
(string-append
|
(number->string server-names-hash-bucket-size)
|
||||||
" server_names_hash_bucket_max_size "
|
";\n")
|
||||||
(number->string server-names-hash-bucket-max-size)
|
"")
|
||||||
";\n")
|
(if server-names-hash-bucket-max-size
|
||||||
"")
|
(string-append
|
||||||
"\n"
|
" server_names_hash_bucket_max_size "
|
||||||
(map emit-nginx-upstream-config upstream-list)
|
(number->string server-names-hash-bucket-max-size)
|
||||||
(map emit-nginx-server-config server-list)
|
";\n")
|
||||||
"}\n"
|
"")
|
||||||
"events {}\n")))
|
"\n"
|
||||||
|
(map emit-nginx-upstream-config upstream-blocks)
|
||||||
|
(map emit-nginx-server-config server-blocks)
|
||||||
|
"}\n"
|
||||||
|
"events {}\n"))))
|
||||||
|
|
||||||
(define %nginx-accounts
|
(define %nginx-accounts
|
||||||
(list (user-group (name "nginx") (system? #t))
|
(list (user-group (name "nginx") (system? #t))
|
||||||
|
@ -275,61 +279,53 @@ of index files."
|
||||||
(home-directory "/var/empty")
|
(home-directory "/var/empty")
|
||||||
(shell (file-append shadow "/sbin/nologin")))))
|
(shell (file-append shadow "/sbin/nologin")))))
|
||||||
|
|
||||||
(define nginx-activation
|
(define (nginx-activation config)
|
||||||
(match-lambda
|
(match-record config
|
||||||
(($ <nginx-configuration> nginx log-directory run-directory server-blocks
|
<nginx-configuration>
|
||||||
upstream-blocks server-names-hash-bucket-size
|
(nginx log-directory run-directory file)
|
||||||
server-names-hash-bucket-max-size file)
|
#~(begin
|
||||||
#~(begin
|
(use-modules (guix build utils))
|
||||||
(use-modules (guix build utils))
|
|
||||||
|
|
||||||
(format #t "creating nginx log directory '~a'~%" #$log-directory)
|
(format #t "creating nginx log directory '~a'~%" #$log-directory)
|
||||||
(mkdir-p #$log-directory)
|
(mkdir-p #$log-directory)
|
||||||
(format #t "creating nginx run directory '~a'~%" #$run-directory)
|
(format #t "creating nginx run directory '~a'~%" #$run-directory)
|
||||||
(mkdir-p #$run-directory)
|
(mkdir-p #$run-directory)
|
||||||
(format #t "creating nginx temp directories '~a/{client_body,proxy,fastcgi,uwsgi,scgi}_temp'~%" #$run-directory)
|
(format #t "creating nginx temp directories '~a/{client_body,proxy,fastcgi,uwsgi,scgi}_temp'~%" #$run-directory)
|
||||||
(mkdir-p (string-append #$run-directory "/client_body_temp"))
|
(mkdir-p (string-append #$run-directory "/client_body_temp"))
|
||||||
(mkdir-p (string-append #$run-directory "/proxy_temp"))
|
(mkdir-p (string-append #$run-directory "/proxy_temp"))
|
||||||
(mkdir-p (string-append #$run-directory "/fastcgi_temp"))
|
(mkdir-p (string-append #$run-directory "/fastcgi_temp"))
|
||||||
(mkdir-p (string-append #$run-directory "/uwsgi_temp"))
|
(mkdir-p (string-append #$run-directory "/uwsgi_temp"))
|
||||||
(mkdir-p (string-append #$run-directory "/scgi_temp"))
|
(mkdir-p (string-append #$run-directory "/scgi_temp"))
|
||||||
;; Start-up logs. Once configuration is loaded, nginx switches to
|
;; Start-up logs. Once configuration is loaded, nginx switches to
|
||||||
;; log-directory.
|
;; log-directory.
|
||||||
(mkdir-p (string-append #$run-directory "/logs"))
|
(mkdir-p (string-append #$run-directory "/logs"))
|
||||||
;; Check configuration file syntax.
|
;; Check configuration file syntax.
|
||||||
(system* (string-append #$nginx "/sbin/nginx")
|
(system* (string-append #$nginx "/sbin/nginx")
|
||||||
"-c" #$(or file
|
"-c" #$(or file
|
||||||
(default-nginx-config nginx log-directory
|
(default-nginx-config config))
|
||||||
run-directory server-blocks upstream-blocks
|
"-t"))))
|
||||||
server-names-hash-bucket-size
|
|
||||||
server-names-hash-bucket-max-size))
|
|
||||||
"-t")))))
|
|
||||||
|
|
||||||
(define nginx-shepherd-service
|
(define (nginx-shepherd-service config)
|
||||||
(match-lambda
|
(match-record config
|
||||||
(($ <nginx-configuration> nginx log-directory run-directory server-blocks
|
<nginx-configuration>
|
||||||
upstream-blocks server-names-hash-bucket-size
|
(nginx file run-directory)
|
||||||
server-names-hash-bucket-max-size file)
|
(let* ((nginx-binary (file-append nginx "/sbin/nginx"))
|
||||||
(let* ((nginx-binary (file-append nginx "/sbin/nginx"))
|
(nginx-action
|
||||||
(nginx-action
|
(lambda args
|
||||||
(lambda args
|
#~(lambda _
|
||||||
#~(lambda _
|
(zero?
|
||||||
(zero?
|
(system* #$nginx-binary "-c"
|
||||||
(system* #$nginx-binary "-c"
|
#$(or file
|
||||||
#$(or file
|
(default-nginx-config config))
|
||||||
(default-nginx-config nginx log-directory
|
#$@args))))))
|
||||||
run-directory server-blocks upstream-blocks
|
|
||||||
server-names-hash-bucket-size
|
|
||||||
server-names-hash-bucket-max-size))
|
|
||||||
#$@args))))))
|
|
||||||
|
|
||||||
;; TODO: Add 'reload' action.
|
;; TODO: Add 'reload' action.
|
||||||
(list (shepherd-service
|
(list (shepherd-service
|
||||||
(provision '(nginx))
|
(provision '(nginx))
|
||||||
(documentation "Run the nginx daemon.")
|
(documentation "Run the nginx daemon.")
|
||||||
(requirement '(user-processes loopback))
|
(requirement '(user-processes loopback))
|
||||||
(start (nginx-action "-p" run-directory))
|
(start (nginx-action "-p" run-directory))
|
||||||
(stop (nginx-action "-s" "stop"))))))))
|
(stop (nginx-action "-s" "stop")))))))
|
||||||
|
|
||||||
(define nginx-service-type
|
(define nginx-service-type
|
||||||
(service-type (name 'nginx)
|
(service-type (name 'nginx)
|
||||||
|
|
Reference in a new issue