Subject: [bug#33185] [PATCH v2 2/2] services: Add patchwork.

From: Christopher Baines <[email-masked]>
Date: Tue, 22 Jan 2019 22:40:52 +0000

Christopher Baines <[email-masked]> writes:

> +(define (patchwork-django-admin-gexp patchwork settings-module)
> +  #~(lambda command
> +      (let ((pid (primitive-fork))
> +            (user (getpwnam "httpd")))
> +        (if (eq? pid 0)
> +            (dynamic-wind
> +              (const #t)
> +              (lambda ()
> +                (setgid (passwd:gid user))
> +                (setuid (passwd:uid user))
> +
> +                (setenv "DJANGO_SETTINGS_MODULE" "guix.patchwork.settings")
> +                (setenv "PYTHONPATH" #$settings-module)
> +                (primitive-exit
> +                 (if (zero?
> +                      (apply system*
> +                             #$(file-append patchwork "/bin/patchwork-admin")
> +                             command))
> +                     0
> +                     1)))
> +              (lambda ()
> +                (primitive-exit 1)))
> +            (zero? (cdr (waitpid pid)))))))
> +
> +(define (patchwork-django-admin-action patchwork settings-module)
> +  (shepherd-action
> +   (name 'django-admin)
> +   (documentation
> +    "Run a django admin command for patchwork")
> +   (procedure (patchwork-django-admin-gexp patchwork settings-module))))

It would be really useful to provide an easy way of accessing the Django
admin utilities. I think Shepherd actions might be a good way of doing
this, but I haven't got it working yet... I think something goes wrong
when it forks, so I might need to try different approaches to change
user.