mastostart-guix/mastostart-gnu/services/mastostart.scm
Giacomo Leidi f5408c4399 mastostart-gnu: Aggiunge crawl job alla configurazione.
* mastostart-gnu/services/mastostart.scm: Fix per quando si condivide
la webroot con l'host.
* mastostart-gnu/system/mastostart.scm: Aggiunge crawl job alla configurazione.
2020-05-11 15:32:48 +02:00

103 lines
4 KiB
Scheme

(define-module (mastostart-gnu services mastostart)
#:use-module (gnu services)
#:use-module (gnu services shepherd)
#:use-module (gnu system shadow)
#:use-module (gnu packages admin)
#:use-module (gnu packages base)
#:use-module (guix build utils)
#:use-module (guix records)
#:use-module (guix gexp)
#:use-module (mastostart-gnu packages mastostart)
#:export (mastostart-service
mastostart-service-type
mastostart-configuration
mastostart-configuration?))
(define-record-type* <mastostart-configuration>
mastostart-configuration make-mastostart-configuration
mastostart-configuration?
(mastostart mastostart-configuration-mastostart
(default mastostart))
(webroot mastostart-configuration-webroot
(default "/srv"))
(reference-email mastostart-configuration-reference-email
(default "goodoldpaul@autistici.org"))
(test-email mastostart-configuration-test-email
(default "goodoldpaul@autistici.org"))
(memory-limit mastostart-configuration-memory-limit
(default "1G")))
(define %mastostart-accounts
(list (user-group
(name "mastostart")
(system? #t))
(user-account
(name "mastostart")
(group "mastostart")
(system? #t)
(home-directory "/var/empty")
(shell (file-append shadow "/sbin/nologin")))))
(define (%mastostart-activation config)
"Ritorna una gexp di attivazione per MastodonStartpage database server."
#~(begin
(use-modules (ice-9 popen)
(guix build utils))
(let* ((mustard.ini
(string-append #$mastostart "/web/mustard/sec/mustard.ini"))
(crawler.ini
(string-append #$mastostart "/web/mustard/crawler/php.ini"))
(memory-limit
#$(mastostart-configuration-memory-limit config))
(test-email
#$(mastostart-configuration-test-email config))
(reference-email
#$(mastostart-configuration-reference-email config)))
(call-with-output-file crawler.ini
(lambda (port)
(display (string-append "memory_limit="
memory-limit
"\n")
port)))
(rename-file (string-append #$mastostart
"/web/mustard/sec/mustard.ini.sample")
mustard.ini)
(substitute* mustard.ini
(("pippo@pippo\\.pip")
reference-email)
(("peppe@peppe\\.pep")
test-email)))))
(define (mastostart-shepherd-service config)
(list
(let ((mastostart (mastostart-configuration-mastostart config))
(webroot (mastostart-configuration-webroot config)))
(shepherd-service
(provision '(mastostart))
(one-shot? #t)
(requirement '(httpd mysql))
(documentation "Start serving the MastodonStartpage.")
(start (with-imported-modules '((ice-9 ftw))
#~(lambda _
(use-modules (ice-9 ftw))
(if (equal? (scandir #$webroot) '("." ".."))
(begin
(invoke #$(file-append coreutils "/bin/rm") "-rf"
#$webroot)
(invoke #$(file-append coreutils "/bin/ln") "-s"
#$(file-append mastostart "/web")
#$webroot))
#t))))
(stop #~(make-kill-destructor))))))
(define mastostart-service-type
(service-type
(name 'mastostart)
(extensions
(list (service-extension account-service-type
(const %mastostart-accounts))
;; (service-extension activation-service-type
;; %mastostart-activation)
(service-extension shepherd-root-service-type
mastostart-shepherd-service)))
(default-value (mastostart-configuration))))