all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Oleg Pykhalov <go.wigust@gmail.com>
To: Christopher Baines <mail@cbaines.net>
Cc: 27855@debbugs.gnu.org
Subject: [bug#27855] [PATCH] gnu: Add rsync service.
Date: Sat, 29 Jul 2017 14:03:49 +0300	[thread overview]
Message-ID: <874ltvh5d6.fsf@gmail.com> (raw)
In-Reply-To: <20170728231747.5eae3af9@cbaines.net> (Christopher Baines's message of "Fri, 28 Jul 2017 23:17:47 +0100")

Hello Christopher,

Christopher Baines <mail@cbaines.net> writes:

> Hello Oleg,
>
> I've had a quick read through the patch, and I've made a few hopefully
> helpful comments below.
>
> On Fri, 28 Jul 2017 01:01:51 +0300
> Oleg Pykhalov <go.wigust@gmail.com> wrote:
>
>> * doc/guix.texi (Incremental file transfer): Add documentation.
>> * gnu/services/rsync.scm (<rsync-configuration>): New record type.
>> (rsync-accounts, rsync-shepherd-service): New service extensions.
>> (rsync-service-type): New service type.
>> ---
>>  doc/guix.texi          |  58 ++++++++++++++++++
>>  gnu/local.mk           |   1 +
>>  gnu/services/rsync.scm | 162
>> +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed,
>> 221 insertions(+) create mode 100644 gnu/services/rsync.scm
>> 
>> diff --git a/doc/guix.texi b/doc/guix.texi
>> index e8c4e0eaf..a3745ae01 100644
>> --- a/doc/guix.texi
>> +++ b/doc/guix.texi
>> @@ -15661,6 +15661,64 @@ Extra options will be passed to @code{git
>> daemon}, please run @end table
>>  @end deftp
>>  
>> +@subsubsection Incremental file transfer
>> +
>> +The @code{(gnu services rsync)} module provides the following
>> services: +
>> +@subsubheading Rsync service
>
> It would be great to give a really short explanation of what this
> service can be used for here. I know what Rsync does, but I'm not quite
> sure what this service does.

OK, I add a little description.

    You might want an rsync daemon if you have files that you want
    available so anyone (or just yourself) can download existing files
    or upload new files.

>> +@deffn {Scheme Variable} rsync-service-type
>> +This is the type for the @uref{https://rsync.samba.org} rsync daemon,
>> +@command{rsync-configuration} record as in this example:
>> +
>> +@example
>> +(service rsync-service-type
>> +         (rsync-configuration))
>> +@end example
>> +
>> +See below for details about @code{rsync-configuration}.
>> +@end deffn
>> +
>> +@deftp {Data Type} rsync-configuration
>> +Data type representing the configuration for @code{rsync-service}.
>> +
>> +@table @asis
>> +@item @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.

>> +@item @code{port-number} (default: @code{873})
>> +TCP port on which @command{rsync} listens for incoming connections.
>> If +port is less than @code{1024} @command{rsync} will be started as
>> the +@code{root} user and group.
>> +
>> +@item @code{pid-file} (default: @code{"/var/run/rsyncd.pid"})
>> +Name of the file where @command{rsync} writes its PID.
>> +
>> +@item @code{lock-file} (default: @code{"/var/run/rsyncd.lock"})
>> +Name of the file where @command{rsync} writes its lock file.
>> +
>> +@item @code{log-file} (default: @code{"/var/log/rsyncd.log"})
>> +Name of the file where @command{rsync} writes its log file.
>> +
>> +@item @code{use-choot?} (default: @var{#f})
>> +Whether to use chroot for @command{rsync} shared directory.
>> +
>> +@item @code{share-path} (default: @file{/srv/rsync})
>> +Location of the @command{rsync} shared directory.
>> +
>> +@item @code{share-comment} (default: @code{"Rsync share"})
>> +Comment of the @command{rsync} shared directory.
>> +
>> +@item @code{read-only?} (default: @var{#f})
>> +Read-write permissions to shared directory.
>> +
>> +@item @code{timeout} (default: @code{300})
>> +I/O timeout in seconds.
>> +
>> +@end table
>> +@end deftp
>> +
>>  @node Setuid Programs
>>  @subsection Setuid Programs
>>  
>> diff --git a/gnu/local.mk b/gnu/local.mk
>> index 724c6b675..fa514b278 100644
>> --- a/gnu/local.mk
>> +++ b/gnu/local.mk
>> @@ -444,6 +444,7 @@ GNU_SYSTEM_MODULES
>> =				\
>> %D%/services/shepherd.scm			\
>> %D%/services/herd.scm				\
>> %D%/services/pm.scm				\
>> +  %D%/services/rsync.scm			\
>>    %D%/services/sddm.scm				\
>>    %D%/services/spice.scm				\
>>    %D%/services/ssh.scm				\
>> diff --git a/gnu/services/rsync.scm b/gnu/services/rsync.scm
>> new file mode 100644
>> index 000000000..49c4cb7e2
>> --- /dev/null
>> +++ b/gnu/services/rsync.scm
>> @@ -0,0 +1,162 @@
>> +;;; GNU Guix --- Functional package management for GNU
>> +;;; Copyright © 2017 Oleg Pykhalov <go.wigust@gmail.com>
>> +;;;
>> +;;; This file is part of GNU Guix.
>> +;;;
>> +;;; GNU Guix is free software; you can redistribute it and/or modify
>> it +;;; under the terms of the GNU General Public License as
>> published by +;;; the Free Software Foundation; either version 3 of
>> the License, or (at +;;; your option) any later version.
>> +;;;
>> +;;; GNU Guix is distributed in the hope that it will be useful, but
>> +;;; WITHOUT ANY WARRANTY; without even the implied warranty of
>> +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
>> +;;; GNU General Public License for more details.
>> +;;;
>> +;;; You should have received a copy of the GNU General Public License
>> +;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.
>> +
>> +(define-module (gnu services rsync)
>> +  #:use-module (gnu services)
>> +  #:use-module (gnu services base)
>> +  #:use-module (gnu services shepherd)
>> +  #:use-module (gnu system shadow)
>> +  #:use-module (gnu packages rsync)
>> +  #:use-module (gnu packages admin)
>> +  #:use-module (guix records)
>> +  #:use-module (guix gexp)
>> +  #:use-module (srfi srfi-1)
>> +  #:use-module (srfi srfi-26)
>> +  #:use-module (ice-9 match)
>> +  #:export (rsync-configuration
>> +            rsync-configuration?
>> +            rsync-service-type))
>> +
>> +;;;
>> +;;; Rsync.
>> +;;;
>> +
>> +(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
>> +                 (default "Rsync share"))
>> +  ;; Boolean
>> +  (read-only? rsync-configuration-read-only?
>> +              (default #f))
>> +  ;; integer
>> +  (timeout rsync-configuration-timeout
>> +           (default 300)))
>> +
>> +(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-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")))
>> +        (and=> share-directory mkdir-p)
>> +        (chown share-directory
>> +               (passwd:uid user)
>> +               (group:gid user)))))
>> +
>> +(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"))))
>      
>
> 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.

> Here however, I can see that you are using some values from the
> configuration (the port-number, package and share-path), which don't
> make that possible. The use of the port-number and package could
> probably be elegantly separated out, but I can't figure out what could
> be done about the share path, and its use in the service activation.

I made rsync service inspired by openssh service.

* “package” is not really needs to be configurable.
* “port-number” needs.  It specifies will service be run by “root”.
* “share-path” needs to be configurable ofcourse.

>> +
>> +(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)))))
>> +
>> +(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)))))
>
> As I understand it, the service might not use the rsyncd user, if it is
> configured to bind to a low port? If that is the case, then it might be
> neater to include a check for this in the account-service-type
> extension, so that these only get created if they are needed?

Yes, if port lower than 1024 only “root” can bind.

I though about it.  I will try to emplement it.


Thanks!

  reply	other threads:[~2017-07-29 11:05 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-27 22:01 [bug#27855] [PATCH] gnu: Add rsync service Oleg Pykhalov
2017-07-27 22:22 ` [bug#27855] ERROR: rsync rsync://localhost/files Oleg Pykhalov
2017-07-28  6:45 ` [bug#27855] [PATCH] services: rsync: Fix invalid gid nobody Oleg Pykhalov
2017-07-28 22:17 ` [bug#27855] [PATCH] gnu: Add rsync service Christopher Baines
2017-07-29 11:03   ` Oleg Pykhalov [this message]
2017-07-29 11:55     ` Christopher Baines
2017-08-03 15:20       ` Oleg Pykhalov
2017-08-03 15:29         ` Oleg Pykhalov
2017-08-03 15:33         ` Christopher Baines
2017-08-03 16:20           ` Oleg Pykhalov
2017-08-03 16:34             ` Oleg Pykhalov
2017-08-10  7:18             ` Christopher Baines
2017-08-10 18:21               ` Christopher Baines
2017-08-10 18:56                 ` Oleg Pykhalov
2017-08-11 19:28                   ` Oleg Pykhalov
2017-08-12  6:59                     ` Christopher Baines
2017-08-12 13:13                       ` Oleg Pykhalov
2017-08-12 17:46                         ` Christopher Baines
2017-08-12 20:19                           ` Oleg Pykhalov
2017-08-12 21:19                             ` Christopher Baines
2017-08-19 20:34                               ` Oleg Pykhalov
2017-08-19 22:19                                 ` Christopher Baines
2017-08-24 22:40                                   ` Oleg Pykhalov
2017-08-30 23:59                                     ` Christopher Baines
2017-08-31 13:04                                       ` Ludovic Courtès
2017-09-16 22:44                                         ` Oleg Pykhalov
2017-09-16 22:49                                           ` Oleg Pykhalov
2017-09-17  8:40 ` [bug#27855] Status: " Oleg Pykhalov
2017-09-18  6:20 ` [bug#27855] " Christopher Baines
2017-09-23  1:47   ` Oleg Pykhalov
2017-09-23  2:38     ` Oleg Pykhalov
2017-09-23 20:12     ` bug#27855: " Christopher Baines

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=874ltvh5d6.fsf@gmail.com \
    --to=go.wigust@gmail.com \
    --cc=27855@debbugs.gnu.org \
    --cc=mail@cbaines.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.