aboutsummaryrefslogtreecommitdiff
path: root/gnu/services/web.scm
diff options
context:
space:
mode:
Diffstat (limited to 'gnu/services/web.scm')
-rw-r--r--gnu/services/web.scm97
1 files changed, 61 insertions, 36 deletions
diff --git a/gnu/services/web.scm b/gnu/services/web.scm
index 816cbaa3f0..8f61f52485 100644
--- a/gnu/services/web.scm
+++ b/gnu/services/web.scm
@@ -39,6 +39,7 @@
#:use-module (gnu packages python)
#:use-module (gnu packages guile)
#:use-module (gnu packages logging)
+ #:use-module (guix packages)
#:use-module (guix records)
#:use-module (guix modules)
#:use-module (guix utils)
@@ -249,6 +250,9 @@
patchwork-configuration-settings-module
patchwork-configuration-domain
+ patchwork-wsgi-wrapper
+ patchwork-virtualhost
+ patchwork-initial-database-setup-service
patchwork-service-type))
;;; Commentary:
@@ -1321,7 +1325,7 @@ files.")
(name patchwork-database-configuration-name
(default "patchwork"))
(user patchwork-database-configuration-user
- (default ""))
+ (default "httpd"))
(password patchwork-database-configuration-password
(default ""))
(host patchwork-database-configuration-host
@@ -1452,19 +1456,16 @@ STATICFILES_STORAGE = (
"\n"
"exec(open(\"" patchwork-wsgi.py "\").read())\n"))
-(define patchwork-httpd-configuration
+(define patchwork-virtualhost
(match-lambda
(($ <patchwork-configuration> patchwork settings-module
domain)
(define wsgi.py (patchwork-wsgi-wrapper patchwork))
- (list "WSGISocketPrefix /var/run/mod_wsgi"
- (list "LoadModule wsgi_module "
- (file-append mod-wsgi "/modules/mod_wsgi.so"))
- (httpd-virtualhost
- "*:8080"
- `("ServerAdmin admin@example.com
+ (httpd-virtualhost
+ "*:8080"
+ `("ServerAdmin admin@example.com
ServerName " ,domain "
LogFormat \"%v %h %l %u %t \\\"%r\\\" %>s %b \\\"%{Referer}i\\\" \\\"%{User-Agent}i\\\"\" customformat
@@ -1474,8 +1475,8 @@ CustomLog \"/var/log/httpd/" ,domain "-access_log\" customformat
ErrorLog /var/log/httpd/error.log
WSGIScriptAlias / " ,wsgi.py "
-WSGIDaemonProcess patchwork user=httpd group=httpd processes=1 threads=2 display-name=%{GROUP} lang='en_US.UTF-8' locale='en_US.UTF-8' python-path=" ,settings-module "
-WSGIProcessGroup patchwork
+WSGIDaemonProcess " ,(package-name patchwork) " user=httpd group=httpd processes=1 threads=2 display-name=%{GROUP} lang='en_US.UTF-8' locale='en_US.UTF-8' python-path=" ,settings-module "
+WSGIProcessGroup " ,(package-name patchwork) "
WSGIPassAuthorization On
<Files " ,wsgi.py ">
@@ -1487,36 +1488,59 @@ Alias /static " ,patchwork "/share/patchwork/htdocs
AllowOverride None
Options MultiViews Indexes SymlinksIfOwnerMatch IncludesNoExec
Require method GET POST OPTIONS
-</Directory>"))))))
+</Directory>")))))
+
+(define (patchwork-httpd-configuration patchwork-configuration)
+ (list "WSGISocketPrefix /var/run/mod_wsgi"
+ (list "LoadModule wsgi_module "
+ (file-append mod-wsgi "/modules/mod_wsgi.so"))
+ (patchwork-virtualhost patchwork-configuration)))
-(define (patchwork-setup-gexp settings-module)
+(define patchwork-initial-database-setup-service
+ (match-lambda
+ (($ <patchwork-database-configuration>
+ engine name user password host port)
+
+ (define start-gexp
+ #~(lambda ()
+ (display "\nSETTING UP PATCHWORK DATABASE USER\n\n\n")
+ (let ((pid (primitive-fork))
+ (postgres (getpwnam "postgres")))
+ (if (eq? pid 0)
+ (dynamic-wind
+ (const #t)
+ (lambda ()
+ (setgid (passwd:gid postgres))
+ (setuid (passwd:uid postgres))
+ (primitive-exit
+ (if (and
+ (zero?
+ (system* #$(file-append postgresql "/bin/createuser")
+ #$user))
+ (zero?
+ (system* #$(file-append postgresql "/bin/createdb")
+ "-O" #$user #$name)))
+ 0
+ 1)))
+ (lambda ()
+ (primitive-exit 1)))
+ (zero? (cdr (waitpid pid)))))))
+
+ (shepherd-service
+ (requirement '(postgres))
+ (provision '(patchwork-postgresql-user-and-database))
+ (start start-gexp)
+ (stop #~(const #f))
+ (respawn? #f)
+ (documentation "Setup patchwork database.")))))
+
+(define (patchwork-setup-gexp patchwork settings-module)
(with-imported-modules (source-module-closure
'((guix build utils)))
#~(lambda ()
(catch #t
(lambda ()
(let ((pid (primitive-fork))
- (user (getpwnam "postgres")))
- (if (eq? pid 0)
- (dynamic-wind
- (const #t)
- (lambda ()
- (setgid (passwd:gid user))
- (setuid (passwd:uid user))
- (primitive-exit
- (if (and
- (zero?
- (system* #$(file-append postgresql "/bin/createuser")
- "httpd"))
- (zero?
- (system* #$(file-append postgresql "/bin/createdb")
- "-O" "httpd" "patchwork")))
- 0
- 1)))
- (lambda ()
- (primitive-exit 1)))
- (zero? (cdr (waitpid pid)))))
- (let ((pid (primitive-fork))
(user (getpwnam "httpd")))
(if (eq? pid 0)
(dynamic-wind
@@ -1526,7 +1550,6 @@ Alias /static " ,patchwork "/share/patchwork/htdocs
(setuid (passwd:uid user))
;; TODO Extract
(setenv "DJANGO_SECRET_KEY" "testsecretkey")
- (setenv "DATABASE_NAME" "patchwork")
(setenv "PYTHONPATH" #$settings-module)
(primitive-exit
(if (and
@@ -1557,8 +1580,10 @@ Alias /static " ,patchwork "/share/patchwork/htdocs
domain)
(list (shepherd-service
(requirement '(postgres))
- (provision '(patchwork-setup))
- (start (patchwork-setup-gexp settings-module))
+ (provision (list (string->symbol
+ (string-append (package-name patchwork)
+ "-setup"))))
+ (start (patchwork-setup-gexp patchwork settings-module))
(stop #~(const #f))
(respawn? #f)
(documentation "Setup patchwork."))))))))