diff options
| author | pinoaffe <pinoaffe@airmail.cc> | 2020-05-05 09:31:11 +0200 |
|---|---|---|
| committer | Oleg Pykhalov <go.wigust@gmail.com> | 2020-05-05 15:32:40 +0300 |
| commit | 051f3254cd56aa8f3cb65a7e35ef8578af2cd3c5 (patch) | |
| tree | 99e57fc51523aec3beacf2e9263e85c550536961 /gnu/services/ssh.scm | |
| parent | 4c4ae8b595e85e62496b4fa8ff2587eb74a1262b (diff) | |
gnu: Add AutoSSH service.
* gnu/services/ssh.scm (<autossh-configuration>): New record type.
(autossh-service-type): New variable.
(autossh-service-activation, autossh-file-name): New procedures.
* doc/guix.texi (Networking Services): Document this.
Signed-off-by: Oleg Pykhalov <go.wigust@gmail.com>
Diffstat (limited to 'gnu/services/ssh.scm')
| -rw-r--r-- | gnu/services/ssh.scm | 106 |
1 files changed, 105 insertions, 1 deletions
diff --git a/gnu/services/ssh.scm b/gnu/services/ssh.scm index d2dbb8f80df..ced21c0742b 100644 --- a/gnu/services/ssh.scm +++ b/gnu/services/ssh.scm | |||
| @@ -4,6 +4,7 @@ | |||
| 4 | ;;; Copyright © 2016 Julien Lepiller <julien@lepiller.eu> | 4 | ;;; Copyright © 2016 Julien Lepiller <julien@lepiller.eu> |
| 5 | ;;; Copyright © 2017 Clément Lassieur <clement@lassieur.org> | 5 | ;;; Copyright © 2017 Clément Lassieur <clement@lassieur.org> |
| 6 | ;;; Copyright © 2019 Ricardo Wurmus <rekado@elephly.net> | 6 | ;;; Copyright © 2019 Ricardo Wurmus <rekado@elephly.net> |
| 7 | ;;; Copyright © 2020 pinoaffe <pinoaffe@airmail.cc> | ||
| 7 | ;;; | 8 | ;;; |
| 8 | ;;; This file is part of GNU Guix. | 9 | ;;; This file is part of GNU Guix. |
| 9 | ;;; | 10 | ;;; |
| @@ -45,7 +46,11 @@ | |||
| 45 | dropbear-configuration | 46 | dropbear-configuration |
| 46 | dropbear-configuration? | 47 | dropbear-configuration? |
| 47 | dropbear-service-type | 48 | dropbear-service-type |
| 48 | dropbear-service)) | 49 | dropbear-service |
| 50 | |||
| 51 | autossh-configuration | ||
| 52 | autossh-configuration? | ||
| 53 | autossh-service-type)) | ||
| 49 | 54 | ||
| 50 | ;;; Commentary: | 55 | ;;; Commentary: |
| 51 | ;;; | 56 | ;;; |
| @@ -628,4 +633,103 @@ daemon} with the given @var{config}, a @code{<dropbear-configuration>} | |||
| 628 | object." | 633 | object." |
| 629 | (service dropbear-service-type config)) | 634 | (service dropbear-service-type config)) |
| 630 | 635 | ||
| 636 | |||
| 637 | ;;; | ||
| 638 | ;;; AutoSSH. | ||
| 639 | ;;; | ||
| 640 | |||
| 641 | |||
| 642 | (define-record-type* <autossh-configuration> | ||
| 643 | autossh-configuration make-autossh-configuration | ||
| 644 | autossh-configuration? | ||
| 645 | (user autossh-configuration-user | ||
| 646 | (default "autossh")) | ||
| 647 | (poll autossh-configuration-poll | ||
| 648 | (default 600)) | ||
| 649 | (first-poll autossh-configuration-first-poll | ||
| 650 | (default #f)) | ||
| 651 | (gate-time autossh-configuration-gate-time | ||
| 652 | (default 30)) | ||
| 653 | (log-level autossh-configuration-log-level | ||
| 654 | (default 1)) | ||
| 655 | (max-start autossh-configuration-max-start | ||
| 656 | (default #f)) | ||
| 657 | (message autossh-configuration-message | ||
| 658 | (default "")) | ||
| 659 | (port autossh-configuration-port | ||
| 660 | (default "0")) | ||
| 661 | (ssh-options autossh-configuration-ssh-options | ||
| 662 | (default '()))) | ||
| 663 | |||
| 664 | (define (autossh-file-name config file) | ||
| 665 | "Return a path in /var/run/autossh/ that is writable | ||
| 666 | by @code{user} from @code{config}." | ||
| 667 | (string-append "/var/run/autossh/" | ||
| 668 | (autossh-configuration-user config) | ||
| 669 | "/" file)) | ||
| 670 | |||
| 671 | (define (autossh-shepherd-service config) | ||
| 672 | (shepherd-service | ||
| 673 | (documentation "Automatically set up ssh connections (and keep them alive).") | ||
| 674 | (provision '(autossh)) | ||
| 675 | (start #~(make-forkexec-constructor | ||
| 676 | (list #$(file-append autossh "/bin/autossh") | ||
| 677 | #$@(autossh-configuration-ssh-options config)) | ||
| 678 | #:user #$(autossh-configuration-user config) | ||
| 679 | #:group (passwd:gid (getpw #$(autossh-configuration-user config))) | ||
| 680 | #:pid-file #$(autossh-file-name config "pid") | ||
| 681 | #:log-file #$(autossh-file-name config "log") | ||
| 682 | #:environment-variables | ||
| 683 | '(#$(string-append "AUTOSSH_PIDFILE=" | ||
| 684 | (autossh-file-name config "pid")) | ||
| 685 | #$(string-append "AUTOSSH_LOGFILE=" | ||
| 686 | (autossh-file-name config "log")) | ||
| 687 | #$(string-append "AUTOSSH_POLL=" | ||
| 688 | (number->string | ||
| 689 | (autossh-configuration-poll config))) | ||
| 690 | #$(string-append "AUTOSSH_FIRST_POLL=" | ||
| 691 | (number->string | ||
| 692 | (or | ||
| 693 | (autossh-configuration-first-poll config) | ||
| 694 | (autossh-configuration-poll config)))) | ||
| 695 | #$(string-append "AUTOSSH_GATETIME=" | ||
| 696 | (number->string | ||
| 697 | (autossh-configuration-gate-time config))) | ||
| 698 | #$(string-append "AUTOSSH_LOGLEVEL=" | ||
| 699 | (number->string | ||
| 700 | (autossh-configuration-log-level config))) | ||
| 701 | #$(string-append "AUTOSSH_MAXSTART=" | ||
| 702 | (number->string | ||
| 703 | (or (autossh-configuration-max-start config) | ||
| 704 | -1))) | ||
| 705 | #$(string-append "AUTOSSH_MESSAGE=" | ||
| 706 | (autossh-configuration-message config)) | ||
| 707 | #$(string-append "AUTOSSH_PORT=" | ||
| 708 | (autossh-configuration-port config))))) | ||
| 709 | (stop #~(make-kill-destructor)))) | ||
| 710 | |||
| 711 | (define (autossh-service-activation config) | ||
| 712 | (with-imported-modules '((guix build utils)) | ||
| 713 | #~(begin | ||
| 714 | (use-modules (guix build utils)) | ||
| 715 | (define %user | ||
| 716 | (getpw #$(autossh-configuration-user config))) | ||
| 717 | (let* ((directory #$(autossh-file-name config "")) | ||
| 718 | (log (string-append directory "/log"))) | ||
| 719 | (mkdir-p directory) | ||
| 720 | (chown directory (passwd:uid %user) (passwd:gid %user)) | ||
| 721 | (call-with-output-file log (const #t)) | ||
| 722 | (chown log (passwd:uid %user) (passwd:gid %user)))))) | ||
| 723 | |||
| 724 | (define autossh-service-type | ||
| 725 | (service-type | ||
| 726 | (name 'autossh) | ||
| 727 | (description "Automatically set up ssh connections (and keep them alive).") | ||
| 728 | (extensions | ||
| 729 | (list (service-extension shepherd-root-service-type | ||
| 730 | (compose list autossh-shepherd-service)) | ||
| 731 | (service-extension activation-service-type | ||
| 732 | autossh-service-activation))) | ||
| 733 | (default-value (autossh-configuration)))) | ||
| 734 | |||
| 631 | ;;; ssh.scm ends here | 735 | ;;; ssh.scm ends here |
