Skip to content
This repository has been archived by the owner on Jul 28, 2021. It is now read-only.

Commit

Permalink
Moves runc logs to per container id
Browse files Browse the repository at this point in the history
Resolves: #130
  • Loading branch information
jterry75 committed Sep 15, 2017
1 parent de29646 commit d95551f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
18 changes: 9 additions & 9 deletions service/gcs/runtime/runc/runc.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (r *runcRuntime) CreateContainer(id string, bundlePath string, stdioSet *st
// Start unblocks the container's init process created by the call to
// CreateContainer.
func (c *container) Start() error {
logPath := c.r.getLogPath()
logPath := c.r.getLogPath(c.id)
cmd := exec.Command("runc", "--log", logPath, "start", c.id)
out, err := cmd.CombinedOutput()
if err != nil {
Expand All @@ -127,7 +127,7 @@ func (c *container) ExecProcess(process oci.Process, stdioSet *stdio.ConnectionS

// Kill sends the specified signal to the container's init process.
func (c *container) Kill(signal oslayer.Signal) error {
logPath := c.r.getLogPath()
logPath := c.r.getLogPath(c.id)
cmd := exec.Command("runc", "--log", logPath, "kill", c.id, strconv.Itoa(int(signal)))
out, err := cmd.CombinedOutput()
if err != nil {
Expand All @@ -139,7 +139,7 @@ func (c *container) Kill(signal oslayer.Signal) error {
// Delete deletes any state created for the container by either this wrapper or
// runC itself.
func (c *container) Delete() error {
logPath := c.r.getLogPath()
logPath := c.r.getLogPath(c.id)
cmd := exec.Command("runc", "--log", logPath, "delete", c.id)
out, err := cmd.CombinedOutput()
if err != nil {
Expand All @@ -162,7 +162,7 @@ func (p *process) Delete() error {

// Pause suspends all processes running in the container.
func (c *container) Pause() error {
logPath := c.r.getLogPath()
logPath := c.r.getLogPath(c.id)
cmd := exec.Command("runc", "--log", logPath, "pause", c.id)
out, err := cmd.CombinedOutput()
if err != nil {
Expand All @@ -173,7 +173,7 @@ func (c *container) Pause() error {

// Resume unsuspends processes running in the container.
func (c *container) Resume() error {
logPath := c.r.getLogPath()
logPath := c.r.getLogPath(c.id)
cmd := exec.Command("runc", "--log", logPath, "resume", c.id)
out, err := cmd.CombinedOutput()
if err != nil {
Expand All @@ -184,7 +184,7 @@ func (c *container) Resume() error {

// GetState returns information about the given container.
func (c *container) GetState() (*runtime.ContainerState, error) {
logPath := c.r.getLogPath()
logPath := c.r.getLogPath(c.id)
cmd := exec.Command("runc", "--log", logPath, "state", c.id)
out, err := cmd.CombinedOutput()
if err != nil {
Expand Down Expand Up @@ -219,7 +219,7 @@ func (c *container) Exists() (bool, error) {
// ListContainerStates returns ContainerState structs for all existing
// containers, whether they're running or not.
func (r *runcRuntime) ListContainerStates() ([]runtime.ContainerState, error) {
logPath := r.getLogPath()
logPath := "/tmp/gcs/global-runc.log"
cmd := exec.Command("runc", "--log", logPath, "list", "-f", "json")
out, err := cmd.CombinedOutput()
if err != nil {
Expand Down Expand Up @@ -327,7 +327,7 @@ func (c *container) GetAllProcesses() ([]runtime.ContainerProcessState, error) {
// getRunningPids gets the pids of all processes which runC recognizes as
// running.
func (r *runcRuntime) getRunningPids(id string) ([]int, error) {
logPath := r.getLogPath()
logPath := r.getLogPath(id)
cmd := exec.Command("runc", "--log", logPath, "ps", "-f", "json", id)
out, err := cmd.CombinedOutput()
if err != nil {
Expand Down Expand Up @@ -496,7 +496,7 @@ func (c *container) startProcess(tempProcessDir string, hasTerminal bool, stdioS
return nil, errors.Wrapf(err, "failed to set process as subreaper for process in container %s", c.id)
}

logPath := c.r.getLogPath()
logPath := c.r.getLogPath(c.id)
args = append([]string{"--log", logPath}, args...)

args = append(args, "--pid-file", filepath.Join(tempProcessDir, "pid"))
Expand Down
4 changes: 2 additions & 2 deletions service/gcs/runtime/runc/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ func (r *runcRuntime) makeContainerDir(id string) error {
}

// getLogPath returns the path to the log file used by the runC wrapper.
func (r *runcRuntime) getLogPath() string {
return filepath.Join(containerFilesDir, "log.log")
func (r *runcRuntime) getLogPath(id string) string {
return filepath.Join("/tmp/gcs", id, "runc.log")
}

// processExists returns true if the given process exists in /proc, false if
Expand Down
5 changes: 3 additions & 2 deletions service/gcs/runtime/runc/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,12 @@ var _ = Describe("Utils", func() {
expectedPath string
actualPath string
)
id := "atestid"
BeforeEach(func() {
expectedPath = "/var/run/gcsrunc/log.log"
expectedPath = "/tmp/gcs/" + id + "runc.log"
})
JustBeforeEach(func() {
actualPath = rtime.getLogPath()
actualPath = rtime.getLogPath(id)
})
It("should return the correct log path", func() {
Expect(actualPath).To(Equal(expectedPath))
Expand Down

0 comments on commit d95551f

Please sign in to comment.