Browse Source

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.
Giacomo Leidi 3 years ago
parent
commit
f5408c4399
2 changed files with 60 additions and 8 deletions
  1. 44 7
      mastostart-gnu/services/mastostart.scm
  2. 16 1
      mastostart-gnu/system/mastostart.scm

+ 44 - 7
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))))

+ 16 - 1
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)))