[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bug#27855] [PATCH] gnu: Add rsync service.
From: |
Oleg Pykhalov |
Subject: |
[bug#27855] [PATCH] gnu: Add rsync service. |
Date: |
Thu, 03 Aug 2017 18:20:31 +0300 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) |
Hello Christopher,
Christopher Baines <address@hidden> writes:
> On Sat, 29 Jul 2017 14:03:49 +0300
> Oleg Pykhalov <address@hidden> wrote:
>
>> >> address@hidden {Scheme Variable} rsync-service-type
>> >> +This is the type for the @uref{https://rsync.samba.org} rsync
>> >> daemon, address@hidden record as in this example:
>> >> +
>> >> address@hidden
>> >> +(service rsync-service-type
>> >> + (rsync-configuration))
>> >> address@hidden example
>> >> +
>> >> +See below for details about @code{rsync-configuration}.
>> >> address@hidden deffn
>> >> +
>> >> address@hidden {Data Type} rsync-configuration
>> >> +Data type representing the configuration for @code{rsync-service}.
>> >> +
>> >> address@hidden @asis
>> >> address@hidden @code{package} (default: @var{rsync})
>> >> +Package object of the Rsync utility for efficiently transferring
>> >> and +synchronizing files.
>> >
>> > Object doesn't really fit here, if anything its a record. Also, I
>> > don't think this needs a description of what rsync does, it's
>> > probably clearest to just say that this is the rsync package?
>>
>> OK, is it good?
>>
>> @code{rsync} package to use.
>
> Yep, in my opinion, that is the right amount of information.
>
>> >> +(define (rsync-config-file config)
>> >> + "Return the rsync configuration file corresponding to CONFIG."
>> >> + (computed-file
>> >> + "rsync.conf"
>> >> + #~(begin
>> >> + (call-with-output-file #$output
>> >> + (lambda (port)
>> >> + (display "# Generated by 'rsync-service'.\n" port)
>> >> + (format port "pid file = ~a\n"
>> >> + #$(rsync-configuration-pid-file config))
>> >> + (format port "lock file = ~a\n"
>> >> + #$(rsync-configuration-lock-file config))
>> >> + (format port "log file = ~a\n"
>> >> + #$(rsync-configuration-log-file config))
>> >> + (format port "port = ~a\n"
>> >> + #$(number->string
>> >> + (rsync-configuration-port-number config)))
>> >> + (format port "use chroot = ~a\n"
>> >> + #$(if (rsync-configuration-use-chroot? config)
>> >> + "true" "false"))
>> >> + (display "[files]\n" port)
>> >> + (format port "path = ~a\n"
>> >> + #$(rsync-configuration-share-path config))
>> >> + (format port "comment = ~a\n"
>> >> + #$(rsync-configuration-share-comment config))
>> >> + (format port "read only = ~a\n"
>> >> + #$(if (rsync-configuration-read-only? config)
>> >> + "true" "false"))
>> >> + (format port "timeout = ~a\n"
>> >> + #$(number->string
>> >> + (rsync-configuration-timeout config)))
>> >> + #t)))))
>> >
>> > It might be neater here to use mixed-text-file here. It might look
>> > something like...
>> >
>> > (define (rsync-config-file config)
>> > "Return the rsync configuration file corresponding to CONFIG."
>> > (match config
>> > (($ <rsync-configuration> package port-number pid-file lock-file
>> > log-file use-chroot? share-path
>> > share-comment read-only? timeout)
>> > (mixed text-file "rsync.conf"
>> > "# Generated by 'rsync-service'.\n"
>> > "pid file = " pid-file "\n"
>> > "lock file = " lock-file "\n"
>> > "log file = " log-file "\n"
>> > "port = " (number->string port-number) "\n"
>> > "use chroot = " (if use-chroot? "true" "false") "\n"
>> > "[files]\n"
>> > "path = " share-path "\n"
>> > "comment = " share-comment "\n"
>> > "read only = " (if read-only? "true" "false") "\n"
>> > "timeout = " (number->string timeout) "\n"))))
OK, patched.
>> > One thing I tried with the Tailon service, was to define a
>> > gexp-compiler for the record type representing the configuration
>> > file. One really big advantage in the case of Tailon is that it
>> > easily allows the use of a custom file, just by providing a
>> > different gexp.
>>
>> So, this way you could provide your existing Tailon config as a file
>> in system declaration? Nice.
>
> Yep, I think something like the following should just work, but I
> haven't tested it yet.
>
> (service tailon-service-type
> (tailon-configuration
> (config-file (local-file "../tailon.yml"))))
>
> I bring this up, as I think it is great if this is a feature of all
> services, I'm having trouble though working out how you might do that
> in this case, with the use of values in the activation service
> extension. I can see complicated approaches, but nothing simple and
> clear enough.
I tried to apply your work in tailon service, but I have troubles as you
described. So I just cleaned up code little bit.
>From 2cbbf8a9bf36edb153e04445bb8d52cd056d2767 Mon Sep 17 00:00:00 2001
From: Oleg Pykhalov <address@hidden>
Date: Thu, 3 Aug 2017 18:12:48 +0300
Subject: [PATCH] services: rsync: Clean up code.
* gnu/services/rsync.scm: Clean up.
---
gnu/services/rsync.scm | 175 +++++++++++++++++++++----------------------------
1 file changed, 75 insertions(+), 100 deletions(-)
diff --git a/gnu/services/rsync.scm b/gnu/services/rsync.scm
index 9cf2bc89a..e1a014a63 100644
--- a/gnu/services/rsync.scm
+++ b/gnu/services/rsync.scm
@@ -32,61 +32,59 @@
rsync-configuration?
rsync-service-type))
+;;;; Commentary:
;;;
-;;; Rsync.
+;;; This module implements a service that to run instance of Rsync,
+;;; files synchronization tool.
;;;
+;;;; Code:
(define-record-type* <rsync-configuration>
rsync-configuration make-rsync-configuration
rsync-configuration?
- ;; <package>
- (package rsync-configuration-package
- (default rsync))
- ;; integer
- (port-number rsync-configuration-port-number
- (default 873))
- ;; string
- (pid-file rsync-configuration-pid-file
- (default "/var/run/rsyncd.pid"))
- ;; string
- (lock-file rsync-configuration-lock-file
- (default "/var/run/rsyncd.lock"))
- ;; string
- (log-file rsync-configuration-log-file
- (default "/var/log/rsyncd.log"))
- ;; Boolean
- (use-chroot? rsync-configuration-use-chroot?
- (default #f))
- ;; string
- (share-path rsync-configuration-share-path
- (default "/srv/rsync"))
- ;; string
- (share-comment rsync-configuration-share-comment
+ (package rsync-configuration-package ;package
+ (default rsync))
+ (port-number rsync-configuration-port-number ;integer
+ (default 873))
+ (pid-file rsync-configuration-pid-file ;string
+ (default "/var/run/rsyncd.pid"))
+ (lock-file rsync-configuration-lock-file ;string
+ (default "/var/run/rsyncd.lock"))
+ (log-file rsync-configuration-log-file ;string
+ (default "/var/log/rsyncd.log"))
+ (use-chroot? rsync-configuration-use-chroot? ;boolean
+ (default #f))
+ (share-path rsync-configuration-share-path ;string
+ (default "/srv/rsync"))
+ (share-comment rsync-configuration-share-comment ;string
(default "Rsync share"))
- ;; Boolean
- (read-only? rsync-configuration-read-only?
- (default #f))
- ;; integer
- (timeout rsync-configuration-timeout
- (default 300)))
+ (read-only? rsync-configuration-read-only? ;boolean
+ (default #f))
+ (timeout rsync-configuration-timeout ;integer
+ (default 300))
+ (user rsync-configuration-user ;string
+ (default "rsyncd"))
+ (group rsync-configuration-group ;string
+ (default "rsyncd")))
-(define %rsync-accounts
- ;; User account and group for rsync.
- (list (user-group (name "rsyncd") (system? #t))
- (user-account
- (name "rsyncd")
- (system? #t)
- (group "rsyncd")
- (comment "rsyncd privilege separation user")
- (home-directory "/var/run/rsyncd")
- (shell #~(string-append #$shadow "/sbin/nologin")))))
+(define (rsync-account config)
+ "Return the user accounts and user groups for CONFIG."
+ (let ((rsync-user (rsync-configuration-user config)))
+ (list (user-group (name "rsyncd") (system? #t))
+ (user-account
+ (name rsync-user)
+ (system? #t)
+ (group rsync-user)
+ (comment "rsyncd privilege separation user")
+ (home-directory "/var/run/rsyncd")
+ (shell #~(string-append #$shadow "/sbin/nologin"))))))
(define (rsync-activation config)
"Return the activation GEXP for CONFIG."
#~(begin
(use-modules (guix build utils))
(let ((share-directory #$(rsync-configuration-share-path config))
- (user (getpw "rsyncd")))
+ (user (getpw #$(rsync-configuration-user config))))
(and=> share-directory mkdir-p)
(chown share-directory
(passwd:uid user)
@@ -94,70 +92,47 @@
(define (rsync-config-file config)
"Return the rsync configuration file corresponding to CONFIG."
- (computed-file
- "rsync.conf"
- #~(begin
- (call-with-output-file #$output
- (lambda (port)
- (display "# Generated by 'rsync-service'.\n" port)
- (format port "pid file = ~a\n"
- #$(rsync-configuration-pid-file config))
- (format port "lock file = ~a\n"
- #$(rsync-configuration-lock-file config))
- (format port "log file = ~a\n"
- #$(rsync-configuration-log-file config))
- (format port "port = ~a\n"
- #$(number->string
- (rsync-configuration-port-number config)))
- (format port "use chroot = ~a\n"
- #$(if (rsync-configuration-use-chroot? config)
- "true" "false"))
- (display "gid = rsyncd\n" port)
- (display "[files]\n" port)
- (format port "path = ~a\n"
- #$(rsync-configuration-share-path config))
- (format port "comment = ~a\n"
- #$(rsync-configuration-share-comment config))
- (format port "read only = ~a\n"
- #$(if (rsync-configuration-read-only? config)
- "true" "false"))
- (format port "timeout = ~a\n"
- #$(number->string
- (rsync-configuration-timeout config)))
- #t)))))
+ (match config
+ (($ <rsync-configuration> package port-number pid-file
+ lock-file log-file use-chroot? share-path
+ share-comment read-only? timeout user group)
+ (mixed-text-file "rsync.conf"
+ "# Generated by 'rsync-service'.\n"
+ "pid file = " pid-file "\n"
+ "lock file = " lock-file "\n"
+ "log file = " log-file "\n"
+ "port = " (number->string port-number) "\n"
+ "use chroot = " (if use-chroot? "true" "false") "\n"
+ "gid = " group "\n"
+ "[files]\n"
+ "path = " share-path "\n"
+ "comment = " share-comment "\n"
+ "read only = " (if read-only? "true" "false") "\n"
+ "timeout = " (number->string timeout) "\n"))))
(define (rsync-shepherd-service config)
"Return a <shepherd-service> for rsync with CONFIG."
-
- (define rsync-command
- #~(list (string-append #$(rsync-configuration-package config) "/bin/rsync")
- "--daemon" "--config" #$(rsync-config-file config)))
-
- (define pid-file
- (rsync-configuration-pid-file config))
-
- (define user
- (let ((port (rsync-configuration-port-number config)))
- (if (> port 1024)
- "rsyncd"
- "root")))
-
- (list (shepherd-service
- (provision '(rsync))
- (documentation "Run rsync daemon.")
- (start #~(make-forkexec-constructor #$rsync-command
- #:pid-file #$pid-file
- #:user #$user
- #:group #$user))
- (stop #~(make-kill-destructor)))))
+ (let* ((rsync (rsync-configuration-package config))
+ (pid-file (rsync-configuration-pid-file config))
+ (port (rsync-configuration-port-number config))
+ (user (if (> port 1024) (rsync-configuration-user config) "root")))
+ (list (shepherd-service
+ (provision '(rsync))
+ (documentation "Run rsync daemon.")
+ (start #~(make-forkexec-constructor
+ (list (string-append #$rsync "/bin/rsync")
+ "--config" #$(rsync-config-file config)
+ "--daemon")
+ #:pid-file #$pid-file
+ #:user #$user
+ #:group #$user))
+ (stop #~(make-kill-destructor))))))
(define rsync-service-type
(service-type
(name 'rsync)
(extensions
- (list (service-extension shepherd-root-service-type
- rsync-shepherd-service)
- (service-extension account-service-type
- (const %rsync-accounts))
- (service-extension activation-service-type
- rsync-activation)))))
+ (list (service-extension shepherd-root-service-type rsync-shepherd-service)
+ (service-extension account-service-type rsync-account)
+ (service-extension activation-service-type rsync-activation)))
+ (default-value (rsync-configuration))))
--
2.13.3
- [bug#27855] [PATCH] gnu: Add rsync service.,
Oleg Pykhalov <=
- [bug#27855] [PATCH] gnu: Add rsync service., Oleg Pykhalov, 2017/08/03
- [bug#27855] [PATCH] gnu: Add rsync service., Christopher Baines, 2017/08/03
- [bug#27855] [PATCH] gnu: Add rsync service., Oleg Pykhalov, 2017/08/03
- [bug#27855] [PATCH] gnu: Add rsync service., Oleg Pykhalov, 2017/08/03
- [bug#27855] [PATCH] gnu: Add rsync service., Christopher Baines, 2017/08/10
- [bug#27855] [PATCH] gnu: Add rsync service., Christopher Baines, 2017/08/10
- [bug#27855] [PATCH] gnu: Add rsync service., Oleg Pykhalov, 2017/08/10
- [bug#27855] [PATCH] gnu: Add rsync service., Oleg Pykhalov, 2017/08/11
- [bug#27855] [PATCH] gnu: Add rsync service., Christopher Baines, 2017/08/12
- [bug#27855] [PATCH] gnu: Add rsync service., Oleg Pykhalov, 2017/08/12