summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <davet@gnu.org>2015-07-01 20:32:07 -0400
committerDavid Thompson <dthompson2@worcester.edu>2015-10-25 20:27:19 -0400
commit054ee2038e942de75f71c1c8d6a4767a1b0dbf1d (patch)
tree6c287c2060959cb161e9d75447f59e726493e3a1
parente086dcfcf9b18cb7b4619d9ee5aaa2f1ab1aef1e (diff)
scripts: Add 'container' subcommand.
* guix/scripts/container.scm: New file. * guix/scripts/container/exec.scm: New file. * po/guix/POTFILES.in: Add them. * Makefile.am (MODULES): Add them. * doc/guix.texi (Invoking guix container): New section.
-rw-r--r--Makefile.am2
-rw-r--r--doc/guix.texi51
-rw-r--r--guix/scripts/container.scm63
-rw-r--r--guix/scripts/container/exec.scm84
-rw-r--r--po/guix/POTFILES.in2
5 files changed, 202 insertions, 0 deletions
diff --git a/Makefile.am b/Makefile.am
index 4f90b1d15b5..1582af3e8a6 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -128,6 +128,8 @@ MODULES = \
128 guix/scripts/edit.scm \ 128 guix/scripts/edit.scm \
129 guix/scripts/size.scm \ 129 guix/scripts/size.scm \
130 guix/scripts/graph.scm \ 130 guix/scripts/graph.scm \
131 guix/scripts/container.scm \
132 guix/scripts/container/exec.scm \
131 guix.scm \ 133 guix.scm \
132 $(GNU_SYSTEM_MODULES) 134 $(GNU_SYSTEM_MODULES)
133 135
diff --git a/doc/guix.texi b/doc/guix.texi
index 9e15cbd6011..e107b698da8 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -144,6 +144,7 @@ Utilities
144* Invoking guix environment:: Setting up development environments. 144* Invoking guix environment:: Setting up development environments.
145* Invoking guix publish:: Sharing substitutes. 145* Invoking guix publish:: Sharing substitutes.
146* Invoking guix challenge:: Challenging substitute servers. 146* Invoking guix challenge:: Challenging substitute servers.
147* Invoking guix container:: Process isolation.
147 148
148GNU Distribution 149GNU Distribution
149 150
@@ -3582,6 +3583,7 @@ programming interface of Guix in a convenient way.
3582* Invoking guix environment:: Setting up development environments. 3583* Invoking guix environment:: Setting up development environments.
3583* Invoking guix publish:: Sharing substitutes. 3584* Invoking guix publish:: Sharing substitutes.
3584* Invoking guix challenge:: Challenging substitute servers. 3585* Invoking guix challenge:: Challenging substitute servers.
3586* Invoking guix container:: Process isolation.
3585@end menu 3587@end menu
3586 3588
3587@node Invoking guix build 3589@node Invoking guix build
@@ -4985,6 +4987,55 @@ URLs to compare to.
4985@end table 4987@end table
4986 4988
4987 4989
4990@node Invoking guix container
4991@section Invoking @command{guix container}
4992@cindex container
4993
4994The purpose of @command{guix container} is to manipulate processes
4995running within an isolated environment, commonly known as a
4996``container,'' typically created by the @command{guix environment}
4997(@pxref{Invoking guix environment}) and @command{guix system container}
4998(@pxref{Invoking guix system}) commands.
4999
5000The general syntax is:
5001
5002@example
5003guix container @var{action} @var{options}@dots{}
5004@end example
5005
5006@var{action} specifies the operation to perform with a container, and
5007@var{options} specifies the context-specific arguments for the action.
5008
5009The following actions are available:
5010
5011@table @code
5012@item exec
5013Execute a command within the context of a running container.
5014
5015The syntax is:
5016
5017@example
5018guix container exec @var{pid} @var{program} @var{arguments}@dots{}
5019@end example
5020
5021@var{pid} specifies the process ID of the running container.
5022@var{program} specifies an executable file name within the container's
5023root file system. @var{arguments} are the additional options that will
5024be passed to @var{program}.
5025
5026The following command launches an interactive login shell inside a
5027GuixSD container, started by @command{guix system container}, and whose
5028process ID is 9001:
5029
5030@example
5031guix container exec 9001 /run/current-system/profile/bin/bash --login
5032@end example
5033
5034Note that the @var{pid} cannot be the parent process of a container. It
5035must be the container's PID 1 or one of its child processes.
5036
5037@end table
5038
4988@c ********************************************************************* 5039@c *********************************************************************
4989@node GNU Distribution 5040@node GNU Distribution
4990@chapter GNU Distribution 5041@chapter GNU Distribution
diff --git a/guix/scripts/container.scm b/guix/scripts/container.scm
new file mode 100644
index 00000000000..cd9f345b682
--- /dev/null
+++ b/guix/scripts/container.scm
@@ -0,0 +1,63 @@
1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2015 David Thompson <davet@gnu.org>
3;;;
4;;; This file is part of GNU Guix.
5;;;
6;;; GNU Guix is free software; you can redistribute it and/or modify it
7;;; under the terms of the GNU General Public License as published by
8;;; the Free Software Foundation; either version 3 of the License, or (at
9;;; your option) any later version.
10;;;
11;;; GNU Guix is distributed in the hope that it will be useful, but
12;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14;;; GNU General Public License for more details.
15;;;
16;;; You should have received a copy of the GNU General Public License
17;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
18
19(define-module (guix scripts container)
20 #:use-module (ice-9 match)
21 #:use-module (guix ui)
22 #:export (guix-container))
23
24(define (show-help)
25 (display (_ "Usage: guix container ACTION ARGS...
26Build and manipulate Linux containers.\n"))
27 (newline)
28 (display (_ "The valid values for ACTION are:\n"))
29 (newline)
30 (display (_ "\
31 exec execute a command inside of an existing container\n"))
32 (newline)
33 (display (_ "
34 -h, --help display this help and exit"))
35 (display (_ "
36 -V, --version display version information and exit"))
37 (newline)
38 (show-bug-report-information))
39
40(define %actions '("exec"))
41
42(define (resolve-action name)
43 (let ((module (resolve-interface
44 `(guix scripts container ,(string->symbol name))))
45 (proc (string->symbol (string-append "guix-container-" name))))
46 (module-ref module proc)))
47
48(define (guix-container . args)
49 (with-error-handling
50 (match args
51 (()
52 (format (current-error-port)
53 (_ "guix container: missing action~%")))
54 ((or ("-h") ("--help"))
55 (show-help)
56 (exit 0))
57 (("--version")
58 (show-version-and-exit "guix container"))
59 ((action args ...)
60 (if (member action %actions)
61 (apply (resolve-action action) args)
62 (format (current-error-port)
63 (_ "guix container: invalid action~%")))))))
diff --git a/guix/scripts/container/exec.scm b/guix/scripts/container/exec.scm
new file mode 100644
index 00000000000..40186be85d6
--- /dev/null
+++ b/guix/scripts/container/exec.scm
@@ -0,0 +1,84 @@
1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2015 David Thompson <davet@gnu.org>
3;;;
4;;; This file is part of GNU Guix.
5;;;
6;;; GNU Guix is free software; you can redistribute it and/or modify it
7;;; under the terms of the GNU General Public License as published by
8;;; the Free Software Foundation; either version 3 of the License, or (at
9;;; your option) any later version.
10;;;
11;;; GNU Guix is distributed in the hope that it will be useful, but
12;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14;;; GNU General Public License for more details.
15;;;
16;;; You should have received a copy of the GNU General Public License
17;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
18
19(define-module (guix scripts container exec)
20 #:use-module (ice-9 match)
21 #:use-module (srfi srfi-1)
22 #:use-module (srfi srfi-11)
23 #:use-module (srfi srfi-37)
24 #:use-module (guix ui)
25 #:use-module (guix utils)
26 #:use-module (gnu build linux-container)
27 #:export (guix-container-exec))
28
29(define %options
30 (list (option '(#\h "help") #f #f
31 (lambda args
32 (show-help)
33 (exit 0)))
34 (option '(#\V "version") #f #f
35 (lambda args
36 (show-version-and-exit "guix container exec")))))
37
38(define (show-help)
39 (display (_ "Usage: guix container exec PID COMMAND [ARGS...]
40Execute COMMMAND within the container process PID.\n"))
41 (newline)
42 (display (_ "
43 -h, --help display this help and exit"))
44 (display (_ "
45 -V, --version display version information and exit"))
46 (newline)
47 (show-bug-report-information))
48
49(define (partition-args args)
50 "Split ARGS into two lists; one containing the arguments for this program,
51and the other containing arguments for the command to be executed."
52 (break (lambda (arg)
53 ;; Split after the pid argument.
54 (not (false-if-exception (string->number arg))))
55 args))
56
57(define (guix-container-exec . args)
58 (define (handle-argument arg result)
59 (if (assoc-ref result 'pid)
60 (leave (_ "~a: extraneous argument~%") arg)
61 (alist-cons 'pid (string->number* arg) result)))
62
63 (let-values (((args command) (partition-args args)))
64 (let* ((opts (parse-command-line args %options '(())
65 #:argument-handler
66 handle-argument))
67 (pid (assoc-ref opts 'pid)))
68
69 (unless pid
70 (leave (_ "no pid specified~%")))
71
72 (when (null? command)
73 (leave (_ "no command specified~%")))
74
75 (unless (file-exists? (string-append "/proc/" (number->string pid)))
76 (leave (_ "no such process ~d~%") pid))
77
78 (let ((result (container-excursion pid
79 (lambda ()
80 (match command
81 ((program . program-args)
82 (apply execlp program program program-args)))))))
83 (unless (zero? result)
84 (leave (_ "exec failed with status ~d~%") result))))))
diff --git a/po/guix/POTFILES.in b/po/guix/POTFILES.in
index 0c4e4f84437..6197529b44e 100644
--- a/po/guix/POTFILES.in
+++ b/po/guix/POTFILES.in
@@ -23,6 +23,8 @@ guix/scripts/edit.scm
23guix/scripts/size.scm 23guix/scripts/size.scm
24guix/scripts/graph.scm 24guix/scripts/graph.scm
25guix/scripts/challenge.scm 25guix/scripts/challenge.scm
26guix/scripts/container.scm
27guix/scripts/container/exec.scm
26guix/upstream.scm 28guix/upstream.scm
27guix/ui.scm 29guix/ui.scm
28guix/http-client.scm 30guix/http-client.scm