From f5408c43998687bdac25a0c15e20800ac4418a25 Mon Sep 17 00:00:00 2001 From: Giacomo Leidi Date: Mon, 11 May 2020 13:59:02 +0200 Subject: [PATCH] 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. --- mastostart-gnu/services/mastostart.scm | 51 ++++++++++++++++++++++---- mastostart-gnu/system/mastostart.scm | 17 ++++++++- 2 files changed, 60 insertions(+), 8 deletions(-) diff --git a/mastostart-gnu/services/mastostart.scm b/mastostart-gnu/services/mastostart.scm index 9dc6827..350d267 100644 --- a/mastostart-gnu/services/mastostart.scm +++ b/mastostart-gnu/services/mastostart.scm @@ -4,6 +4,7 @@ #: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) @@ -37,6 +38,36 @@ (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)) @@ -46,13 +77,17 @@ (one-shot? #t) (requirement '(httpd mysql)) (documentation "Start serving the MastodonStartpage.") - (start #~(lambda _ - (invoke #$(file-append coreutils "/bin/rm") "-rf" - #$webroot) - (invoke - #$(file-append coreutils "/bin/ln") "-s" - #$(file-append mastostart "/web") - #$webroot))) + (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 @@ -61,6 +96,8 @@ (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)))) diff --git a/mastostart-gnu/system/mastostart.scm b/mastostart-gnu/system/mastostart.scm index 76eb72a..f58ed14 100644 --- a/mastostart-gnu/system/mastostart.scm +++ b/mastostart-gnu/system/mastostart.scm @@ -1,17 +1,28 @@ (define-module (mastostart-gnu system mastostart) #:use-module (gnu) + #:use-module (guix) #:use-module (guix packages) #:use-module (gnu packages databases) #:use-module (guix packages) #:use-module (guix build syscalls) + #:use-module (mastostart-gnu packages mastostart) #:use-module (mastostart-gnu services mastostart)) -(use-service-modules databases +(use-service-modules base + databases + mcron networking shepherd ssh web) +(define-public crawl-job + ;; Lancia 'crawl.sh' alle 3AM ogni giorno. Qui scriviamo + ;; il job sotto forma di procedura Scheme. + #~(job '(next-hour '(3)) + (lambda () + (execl (string-append #$mastostart "/web/mustard/crawler/crawl.sh"))))) + (define-public %apache-listen-ports '("80")) (define-public %apache-server-name "127.0.0.1") @@ -48,6 +59,10 @@ (mysql-service) + (service mcron-service-type + (mcron-configuration + (jobs (list crawl-job)))) + (service mastostart-service-type (mastostart-configuration (webroot %apache-webroot)))