summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel J Walsh <dwalsh@redhat.com>2018-01-30 06:23:58 +0100
committerAtomic Bot <atomic-devel@projectatomic.io>2018-02-03 19:49:14 +0000
commit095aaaa639ab57c594bb80bfefbfaed2a2fdff92 (patch)
tree55db4600d1fe284fb591ee810d490b179afe16ad
parent6ba6ecf59b9204d36388de07b866f157a4d13957 (diff)
downloadpodman-095aaaa639ab57c594bb80bfefbfaed2a2fdff92.tar.gz
podman-095aaaa639ab57c594bb80bfefbfaed2a2fdff92.tar.bz2
podman-095aaaa639ab57c594bb80bfefbfaed2a2fdff92.zip
Allow users to specify logpath
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com> Closes: #135 Approved by: mheon
-rw-r--r--cmd/podman/parse.go12
-rw-r--r--cmd/podman/spec.go4
-rw-r--r--docs/podman-run.1.md2
-rw-r--r--libpod/container.go8
-rw-r--r--libpod/container_inspect.go2
-rw-r--r--libpod/container_internal.go5
-rw-r--r--libpod/oci.go2
-rw-r--r--libpod/options.go16
-rw-r--r--libpod/runtime_ctr.go5
-rw-r--r--libpod/sql_state.go5
-rw-r--r--libpod/sql_state_internal.go4
-rw-r--r--libpod/test_common.go1
-rw-r--r--test/e2e/run_test.go12
13 files changed, 63 insertions, 15 deletions
diff --git a/cmd/podman/parse.go b/cmd/podman/parse.go
index 33988a3b6..0d1a0b925 100644
--- a/cmd/podman/parse.go
+++ b/cmd/podman/parse.go
@@ -773,3 +773,15 @@ func stringSlicetoUint32Slice(inputSlice []string) ([]uint32, error) {
}
return outputSlice, nil
}
+
+func getLoggingPath(opts []string) string {
+ for _, opt := range opts {
+ arr := strings.SplitN(opt, "=", 2)
+ if len(arr) == 2 {
+ if strings.TrimSpace(arr[0]) == "path" {
+ return strings.TrimSpace(arr[1])
+ }
+ }
+ }
+ return ""
+}
diff --git a/cmd/podman/spec.go b/cmd/podman/spec.go
index a14bd7dfb..d21d8b6da 100644
--- a/cmd/podman/spec.go
+++ b/cmd/podman/spec.go
@@ -608,6 +608,10 @@ func (c *createConfig) GetContainerCreateOptions() ([]libpod.CtrCreateOption, er
if len(c.HostAdd) > 0 {
options = append(options, libpod.WithHosts(c.HostAdd))
}
+ logPath := getLoggingPath(c.LogDriverOpt)
+ if logPath != "" {
+ options = append(options, libpod.WithLogPath(logPath))
+ }
options = append(options, libpod.WithPrivileged(c.Privileged))
return options, nil
diff --git a/docs/podman-run.1.md b/docs/podman-run.1.md
index 7290a5bd5..3a7a2954a 100644
--- a/docs/podman-run.1.md
+++ b/docs/podman-run.1.md
@@ -260,6 +260,8 @@ millions of trillions.
**--log-opt**=[]
Logging driver specific options.
+ "path=/var/log/container/mycontainer.json" : Set the path to the container log file.
+
**--mac-address**=""
Container MAC address (e.g. 92:d0:c6:0a:29:33)
diff --git a/libpod/container.go b/libpod/container.go
index 27042de39..ccf864826 100644
--- a/libpod/container.go
+++ b/libpod/container.go
@@ -236,8 +236,9 @@ type ContainerConfig struct {
CreatedTime time.Time `json:"createdTime"`
// Cgroup parent of the container
CgroupParent string `json:"cgroupParent"`
-
- // TODO log options - logpath for plaintext, others for log drivers
+ // LogPath log location
+ LogPath string `json:"logPath"`
+ // TODO log options for log drivers
}
// ContainerStatus returns a string representation for users
@@ -360,8 +361,7 @@ func (c *Container) RuntimeName() string {
// This file will only be present after Init() is called to create the container
// in runc
func (c *Container) LogPath() string {
- // TODO store this in state and allow overriding
- return c.logPath()
+ return c.config.LogPath
}
// IPAddress returns the IP address of the container
diff --git a/libpod/container_inspect.go b/libpod/container_inspect.go
index b07dafa00..124126708 100644
--- a/libpod/container_inspect.go
+++ b/libpod/container_inspect.go
@@ -44,7 +44,7 @@ func (c *Container) getContainerInspectData(size bool, driverData *inspect.Data)
HostnamePath: spec.Annotations["io.kubernetes.cri-o.HostnamePath"], // not sure
HostsPath: "", // can't get yet
StaticDir: config.StaticDir,
- LogPath: c.LogPath(),
+ LogPath: config.LogPath,
Name: config.Name,
Driver: driverData.Name,
MountLabel: config.MountLabel,
diff --git a/libpod/container_internal.go b/libpod/container_internal.go
index fd8e826ba..77e456fe1 100644
--- a/libpod/container_internal.go
+++ b/libpod/container_internal.go
@@ -91,11 +91,6 @@ func (c *Container) bundlePath() string {
return c.config.StaticDir
}
-// The path to the container's logs file
-func (c *Container) logPath() string {
- return filepath.Join(c.config.StaticDir, "ctr.log")
-}
-
// Retrieves the path of the container's attach socket
func (c *Container) attachSocketPath() string {
return filepath.Join(c.runtime.ociRuntime.socketsDir, c.ID(), "attach")
diff --git a/libpod/oci.go b/libpod/oci.go
index 155b23640..4183267b8 100644
--- a/libpod/oci.go
+++ b/libpod/oci.go
@@ -174,7 +174,7 @@ func (r *OCIRuntime) createContainer(ctr *Container, cgroupParent string) (err e
args = append(args, "-r", r.path)
args = append(args, "-b", ctr.bundlePath())
args = append(args, "-p", filepath.Join(ctr.state.RunDir, "pidfile"))
- args = append(args, "-l", ctr.logPath())
+ args = append(args, "-l", ctr.LogPath())
args = append(args, "--exit-dir", r.exitsDir)
args = append(args, "--socket-dir-path", r.socketsDir)
if ctr.config.Spec.Process.Terminal {
diff --git a/libpod/options.go b/libpod/options.go
index 28962b4b5..965eb8cc5 100644
--- a/libpod/options.go
+++ b/libpod/options.go
@@ -602,6 +602,22 @@ func WithNetNS(portMappings []ocicni.PortMapping) CtrCreateOption {
}
}
+// WithLogPath sets the path to the log file
+func WithLogPath(path string) CtrCreateOption {
+ return func(ctr *Container) error {
+ if ctr.valid {
+ return ErrCtrFinalized
+ }
+ if path == "" {
+ return errors.Wrapf(ErrInvalidArg, "log path must be set")
+ }
+
+ ctr.config.LogPath = path
+
+ return nil
+ }
+}
+
// WithCgroupParent sets the Cgroup Parent of the new container
func WithCgroupParent(parent string) CtrCreateOption {
return func(ctr *Container) error {
diff --git a/libpod/runtime_ctr.go b/libpod/runtime_ctr.go
index 42f3dd892..6d55a9438 100644
--- a/libpod/runtime_ctr.go
+++ b/libpod/runtime_ctr.go
@@ -62,6 +62,9 @@ func (r *Runtime) NewContainer(rSpec *spec.Spec, options ...CtrCreateOption) (c
}
}()
+ if ctr.config.LogPath == "" {
+ ctr.config.LogPath = filepath.Join(ctr.config.StaticDir, "ctr.log")
+ }
if ctr.config.ShmDir == "" {
ctr.config.ShmDir = filepath.Join(ctr.bundlePath(), "shm")
if err := os.MkdirAll(ctr.config.ShmDir, 0700); err != nil {
@@ -71,7 +74,6 @@ func (r *Runtime) NewContainer(rSpec *spec.Spec, options ...CtrCreateOption) (c
}
ctr.config.Mounts = append(ctr.config.Mounts, ctr.config.ShmDir)
}
-
// Add the container to the state
// TODO: May be worth looking into recovering from name/ID collisions here
if ctr.config.Pod != "" {
@@ -89,7 +91,6 @@ func (r *Runtime) NewContainer(rSpec *spec.Spec, options ...CtrCreateOption) (c
return nil, err
}
}
-
return ctr, nil
}
diff --git a/libpod/sql_state.go b/libpod/sql_state.go
index 42f5fe11e..c10975d47 100644
--- a/libpod/sql_state.go
+++ b/libpod/sql_state.go
@@ -15,7 +15,7 @@ import (
// DBSchema is the current DB schema version
// Increments every time a change is made to the database's tables
-const DBSchema = 8
+const DBSchema = 9
// SQLState is a state implementation backed by a persistent SQLite3 database
type SQLState struct {
@@ -285,7 +285,7 @@ func (s *SQLState) AddContainer(ctr *Container) (err error) {
?, ?, ?, ?, ?,
?, ?, ?, ?, ?,
?, ?, ?, ?, ?,
- ?, ?, ?, ?
+ ?, ?, ?, ?, ?
);`
addCtrState = `INSERT INTO containerState VALUES (
?, ?, ?, ?, ?,
@@ -376,6 +376,7 @@ func (s *SQLState) AddContainer(ctr *Container) (err error) {
ctr.config.ShmSize,
ctr.config.StaticDir,
string(mounts),
+ ctr.LogPath(),
boolToSQL(ctr.config.Privileged),
boolToSQL(ctr.config.NoNewPrivs),
diff --git a/libpod/sql_state_internal.go b/libpod/sql_state_internal.go
index 24d5d8bd4..6523bb589 100644
--- a/libpod/sql_state_internal.go
+++ b/libpod/sql_state_internal.go
@@ -178,6 +178,7 @@ func prepareDB(db *sql.DB) (err error) {
ShmSize INTEGER NOT NULL,
StaticDir TEXT NOT NULL,
Mounts TEXT NOT NULL,
+ LogPath TEXT NOT NULL,
Privileged INTEGER NOT NULL,
NoNewPrivs INTEGER NOT NULL,
@@ -362,6 +363,7 @@ func (s *SQLState) ctrFromScannable(row scannable) (*Container, error) {
shmSize int64
staticDir string
mounts string
+ logPath string
privileged int
noNewPrivs int
@@ -417,6 +419,7 @@ func (s *SQLState) ctrFromScannable(row scannable) (*Container, error) {
&shmSize,
&staticDir,
&mounts,
+ &logPath,
&privileged,
&noNewPrivs,
@@ -480,6 +483,7 @@ func (s *SQLState) ctrFromScannable(row scannable) (*Container, error) {
ctr.config.ShmDir = shmDir
ctr.config.ShmSize = shmSize
ctr.config.StaticDir = staticDir
+ ctr.config.LogPath = logPath
ctr.config.Privileged = boolFromSQL(privileged)
ctr.config.NoNewPrivs = boolFromSQL(noNewPrivs)
diff --git a/libpod/test_common.go b/libpod/test_common.go
index 131a44d0f..95a77d266 100644
--- a/libpod/test_common.go
+++ b/libpod/test_common.go
@@ -23,6 +23,7 @@ func getTestContainer(id, name, locksDir string) (*Container, error) {
ImageVolumes: true,
ReadOnly: true,
StaticDir: "/does/not/exist/",
+ LogPath: "/does/not/exist/",
Stdin: true,
Labels: make(map[string]string),
StopSignal: 0,
diff --git a/test/e2e/run_test.go b/test/e2e/run_test.go
index 8f1aa0053..f364b6952 100644
--- a/test/e2e/run_test.go
+++ b/test/e2e/run_test.go
@@ -184,4 +184,16 @@ var _ = Describe("Podman run", func() {
Expect(session.ExitCode()).To(Equal(0))
Expect(session.OutputToString()).To(ContainSubstring("15"))
})
+
+ It("podman run log-opt", func() {
+ log := filepath.Join(podmanTest.TempDir, "/container.log")
+ session := podmanTest.Podman([]string{"run", "--rm", "--log-opt", fmt.Sprintf("path=%s", log), ALPINE, "ls"})
+ session.Wait(10)
+ fmt.Println(session.OutputToString())
+ Expect(session.ExitCode()).To(Equal(0))
+ _, err := os.Stat(log)
+ Expect(err).To(BeNil())
+ _ = os.Remove(log)
+ })
+
})