aboutsummaryrefslogtreecommitdiff
path: root/libpod
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 /libpod
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
Diffstat (limited to 'libpod')
-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
9 files changed, 33 insertions, 15 deletions
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,