unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: David Thompson <dthompson2@worcester.edu>
To: guix-devel@gnu.org
Subject: [PATCH] services: Add transmission-service.
Date: Fri, 27 Nov 2015 20:46:25 -0500	[thread overview]
Message-ID: <87vb8mj3pq.fsf@izanagi.i-did-not-set--mail-host-address--so-tickle-me> (raw)

[-- Attachment #1: Type: text/plain, Size: 68 bytes --]

My first service since the big service API rewrite.  How did I do?


[-- Attachment #2: 0001-services-Add-transmission-service.patch --]
[-- Type: text/x-patch, Size: 7814 bytes --]

From 6f483d37bf157ee0d253d2aaa919d6900d23453c Mon Sep 17 00:00:00 2001
From: David Thompson <dthompson2@worcester.edu>
Date: Fri, 27 Nov 2015 20:40:59 -0500
Subject: [PATCH] services: Add transmission-service.

* gnu/services/bittorrent.scm: New file.
* gnu-system.am (GNU_SYSTEM_MODULES): Add it.
* doc/guix.texi ("BitTorrent Services"): Document it.
---
 doc/guix.texi               |  19 +++++++
 gnu-system.am               |   1 +
 gnu/services/bittorrent.scm | 122 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 142 insertions(+)
 create mode 100644 gnu/services/bittorrent.scm

diff --git a/doc/guix.texi b/doc/guix.texi
index b404453..847d196 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -6292,6 +6292,7 @@ declaration.
 * Desktop Services::            D-Bus and desktop services.
 * Database Services::           SQL databases.
 * Web Services::                Web servers.
+* BitTorrent Services::         BitTorrent services.
 * Various Services::            Other services.
 @end menu
 
@@ -7013,6 +7014,24 @@ directories are created when the service is activated.
 
 @end deffn
 
+@node BitTorrent Services
+@subsubsection BitTorrent Services
+
+The @code{(gnu services bittorrent)} module provides the following service:
+
+@deffn {Scheme Procedure} transmission-service [#:transmission transmission] @
+       [#:port 9091] [#:peer-port 51413]@
+       [#:download-directory ``/var/lib/transmission/downloads'']
+
+Return a service that runs @var{transmission}, a daemon that downloads
+and shares files via the BitTorrent protocol.
+
+The daemon will serve the web user interface over @var{port}, handle
+BitTorrent tasks over @var{peer-port}, and save downloaded files to
+@var{download-directory}.
+
+@end deffn
+
 @node Various Services
 @subsubsection Various Services
 
diff --git a/gnu-system.am b/gnu-system.am
index f69645b..da1b359 100644
--- a/gnu-system.am
+++ b/gnu-system.am
@@ -354,6 +354,7 @@ GNU_SYSTEM_MODULES =				\
   gnu/services.scm				\
   gnu/services/avahi.scm			\
   gnu/services/base.scm				\
+  gnu/services/bittorrent.scm			\
   gnu/services/databases.scm			\
   gnu/services/dbus.scm				\
   gnu/services/desktop.scm			\
diff --git a/gnu/services/bittorrent.scm b/gnu/services/bittorrent.scm
new file mode 100644
index 0000000..140df53
--- /dev/null
+++ b/gnu/services/bittorrent.scm
@@ -0,0 +1,122 @@
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2015 David Thompson <davet@gnu.org>
+;;;
+;;; 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 bittorrent)
+  #:use-module (gnu services)
+  #:use-module (gnu services dmd)
+  #:use-module (gnu system shadow)
+  #:use-module (gnu packages admin)
+  #:use-module (gnu packages bittorrent)
+  #:use-module (guix records)
+  #:use-module (guix gexp)
+  #:use-module (ice-9 match)
+  #:export (%transmission-state-directory
+
+            transmission-configuration
+            transmission-configuration?
+            transmission-configuration-transmission
+            transmission-configuration-port
+            transmission-configuration-peer-port
+            transmission-configuration-download-directory
+
+            transmission-service-type
+            transmission-service))
+
+;;; Commentary:
+;;;
+;;; BitTorrent services.
+;;;
+;;; Code:
+
+(define %transmission-state-directory "/var/lib/transmission")
+
+(define-record-type* <transmission-configuration>
+  transmission-configuration make-transmission-configuration
+  transmission-configuration?
+  (transmission       transmission-configuration-transmission) ; <package>
+  (port               transmission-configuration-port) ; integer
+  (peer-port          transmission-configuration-peer-port) ; integer
+  (download-directory transmission-configuration-download-directory)) ; string
+
+(define %transmission-accounts
+  (list (user-group (name "transmission") (system? #t))
+        (user-account
+         (name "transmission")
+         (group "transmission")
+         (system? #t)
+         (comment "transmission daemon user")
+         (home-directory "/var/empty")
+         (shell #~(string-append #$shadow "/sbin/nologin")))))
+
+(define (transmission-activation config)
+  (let ((download-dir (transmission-configuration-download-directory config)))
+    #~(begin
+        (use-modules (guix build utils))
+
+        (display "creating transmission state directory\n")
+        (mkdir-p #$%transmission-state-directory)
+        (format #t "creating transmission download directory '~a'~%"
+                #$download-dir)
+        (mkdir-p #$download-dir))))
+
+(define transmission-dmd-service
+  (match-lambda
+    (($ <transmission-configuration> transmission port peer-port download-dir)
+     (let* ((daemon #~(string-append #$transmission "/bin/transmission-daemon"))
+            (start-action
+             #~(make-forkexec-constructor
+                (list #$daemon "--foreground"
+                      (string-append "--port=" (number->string #$port))
+                      (string-append "--peerport="
+                                     (number->string #$peer-port))
+                      (string-append "--download-dir=" #$download-dir)
+                      (string-append "--config-dir="
+                                     #$%transmission-state-directory)))))
+       (list (dmd-service
+              (provision '(transmission))
+              (documentation "Run the transmission daemon.")
+              (requirement '(user-processes loopback))
+              (start start-action)
+              (stop #~(make-kill-destructor))))))))
+
+(define transmission-service-type
+  (service-type (name 'transmission)
+                (extensions
+                 (list (service-extension dmd-root-service-type
+                                          transmission-dmd-service)
+                       (service-extension activation-service-type
+                                          transmission-activation)
+                       (service-extension account-service-type
+                                          (const %transmission-accounts))))))
+
+(define* (transmission-service #:key (transmission transmission)
+                               (port 9091) (peer-port 51413)
+                               (download-directory
+                                (string-append %transmission-state-directory
+                                               "/downloads")))
+  "Return a service that runs TRANSMISSION, a daemon that downloads and shares
+files via the BitTorrent protocol.
+
+The daemon will serve the web user interface over PORT, handle BitTorrent
+tasks over PEER-PORT, and save downloaded files to DOWNLOAD-DIRECTORY."
+  (service transmission-service-type
+           (transmission-configuration
+            (transmission transmission)
+            (port port)
+            (peer-port peer-port)
+            (download-directory download-directory))))
-- 
2.5.0


[-- Attachment #3: Type: text/plain, Size: 38 bytes --]


-- 
David Thompson
GPG Key: 0FF1D807

             reply	other threads:[~2015-11-28  1:46 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-28  1:46 David Thompson [this message]
2015-11-28 14:07 ` [PATCH] services: Add transmission-service Ludovic Courtès

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

  List information: https://guix.gnu.org/

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

  git send-email \
    --in-reply-to=87vb8mj3pq.fsf@izanagi.i-did-not-set--mail-host-address--so-tickle-me \
    --to=dthompson2@worcester.edu \
    --cc=guix-devel@gnu.org \
    /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 public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).