From 5dc4932148f3c32903aa6f07dde3ab62063b843b Mon Sep 17 00:00:00 2001 From: JEAN-FRANCOIS GUILLAUME Date: Fri, 6 May 2022 09:37:24 +0200 Subject: [PATCH] adding squid service --- glicid/packages/networking.scm | 21 +++++++ glicid/services/networking.scm | 108 +++++++++++++++++++++++++++++++++ 2 files changed, 129 insertions(+) create mode 100644 glicid/packages/networking.scm create mode 100644 glicid/services/networking.scm diff --git a/glicid/packages/networking.scm b/glicid/packages/networking.scm new file mode 100644 index 0000000..95921f8 --- /dev/null +++ b/glicid/packages/networking.scm @@ -0,0 +1,21 @@ +(define-module (glicid packages networking) + #:use-module ((gnu packages networking) #:prefix gnu:) + #:use-module (guix download) + #:use-module (guix packages) +) + + +(define-public squid + (package + (inherit gnu:squid) + (name "squid") + (version "5.5") + (source + (origin + (method url-fetch) + (uri (string-append "http://www.squid-cache.org/Versions/v5/squid-" version ".tar.xz")) + (sha256 (base32 "0v0h949l4wd1hl87a8wkk1fkvj8j44wifyxi9myxdgbnci6lh7af")) + ) + ) + ) +) diff --git a/glicid/services/networking.scm b/glicid/services/networking.scm new file mode 100644 index 0000000..576424d --- /dev/null +++ b/glicid/services/networking.scm @@ -0,0 +1,108 @@ +(define-module (glicid services networking) + #:use-module (gnu packages networking) + #:use-module (gnu services) + #:use-module (gnu services shepherd) + #:use-module (guix) + #:use-module (guix records) + #:use-module (ice-9 match) + #: export ( + squid-configuration + squid-configuration? + squid-shepherd-service + squid-service-type + ) +) + +(define-record-type* + squid-configuration make-squid-configuration + squid-configuration? + (squid squid-configuration-squid + (default squid) + ) + (poer squid-configuration-port + (default 3128) + ) + (pid-file squid-configuration-pid-file + (default "/var/run/squid/squid.pid") + ) + (config-file squid-configuration-config-file + (default (file-append squid "/etc/squid.conf")) + ) + (log-file squid-configuration-log-file + (default "/var/log/squid.log") + ) +) + +(define squid-shepherd-service + (match-lambda + (($ squid port pid-file config-file log-file) + (list + (shepherd-service + (provision '(squid) ) + (documentation "Run squid.") + (requirement '(user-processes)) + (respawn? #t) + (start #~(make-forkexec-constructor + (list + #$(file-append squid "/libexec/squid") + "-a" #$port + "-u" #$port + "-f" #$config-file + ) + #:pid-file #$pid-file + #:log-file #$log-file + )) + (stop #~(exec-command + (list + #$(file-append squid "/libexec/squid") + "-a" #$port + "-u" #$port + "-k" "shutdown" + "-f" #$config-file + ) + #:pid-file #$pid-file + #:log-file #$log-file + )) + (actions (list + (shepherd-action + (name 'reload) + (documentation "Reload the settings file from disk.") + (procedure #~(exec-command + (list + #$(file-append squid "/libexec/squid") + "-a" #$port + "-u" #$port + "-k" "reconfigure" + "-f" #$config-file + ) + )) + ) + )) + ) + ) + ) + ) +) + + +(define %squid-activation + (with-imported-modules '((guix build utils)) + #~(begin + (use-modules (guix build utils)) + (mkdir-p "/var/run/squid") + #t + ) + ) +) + +(define squid-service-type + (service-type (name 'squid) + (extensions + (list + (service-extension shepherd-root-service-type squid-shepherd-service) + (service-extension activation-service-type (const %squid-activation)) + ) + ) + (description "Run @uref{http://www.squid-cache.org/, squid} community developped Squid software.") + ) +)