mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-20 09:39:08 +00:00
service: use the logging system with runc
If external logging is enabled, this patch sets the stdout and stderr of the `runc` invocations to one end of a socketpair and the other end is sent to the logging service. Otherwise we log to files as before. Signed-off-by: David Scott <dave.scott@docker.com>
This commit is contained in:
parent
4dc75bc67b
commit
f4bbce7a6c
@ -62,6 +62,8 @@ func runcInit(rootPath, serviceType string) int {
|
|||||||
log.Fatalf("Cannot create log directory %s: %v", logDir, err)
|
log.Fatalf("Cannot create log directory %s: %v", logDir, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger := GetLog(logDir)
|
||||||
|
|
||||||
for _, file := range files {
|
for _, file := range files {
|
||||||
name := file.Name()
|
name := file.Name()
|
||||||
path := filepath.Join(rootPath, name)
|
path := filepath.Join(rootPath, name)
|
||||||
@ -76,23 +78,19 @@ func runcInit(rootPath, serviceType string) int {
|
|||||||
pidfile := filepath.Join(tmpdir, name)
|
pidfile := filepath.Join(tmpdir, name)
|
||||||
cmd := exec.Command(runcBinary, "create", "--bundle", path, "--pid-file", pidfile, name)
|
cmd := exec.Command(runcBinary, "create", "--bundle", path, "--pid-file", pidfile, name)
|
||||||
|
|
||||||
// stream stdout and stderr to respective files
|
stdoutLog := serviceType + "." + name + ".out"
|
||||||
// ideally we want to use io.MultiWriter here, sending one stream to stdout/stderr, another to the files
|
stdout, err := logger.Open(stdoutLog)
|
||||||
// however, this hangs if we do, due to a runc bug, see https://github.com/opencontainers/runc/issues/1721#issuecomment-366315563
|
|
||||||
// once that is fixed, this can be cleaned up
|
|
||||||
stdoutFile := filepath.Join(logDir, serviceType+"."+name+".out.log")
|
|
||||||
stdout, err := os.OpenFile(stdoutFile, os.O_WRONLY|os.O_CREATE, 0644)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error opening stdout log file: %v", err)
|
log.Printf("Error opening stdout log connection: %v", err)
|
||||||
status = 1
|
status = 1
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
defer stdout.Close()
|
defer stdout.Close()
|
||||||
|
|
||||||
stderrFile := filepath.Join(logDir, serviceType+"."+name+".err.log")
|
stderrLog := serviceType + "." + name + ".err"
|
||||||
stderr, err := os.OpenFile(stderrFile, os.O_WRONLY|os.O_CREATE, 0644)
|
stderr, err := logger.Open(stderrLog)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error opening stderr log file: %v", err)
|
log.Printf("Error opening stderr log connection: %v", err)
|
||||||
status = 1
|
status = 1
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -152,13 +150,11 @@ func runcInit(rootPath, serviceType string) int {
|
|||||||
cleanup(path)
|
cleanup(path)
|
||||||
_ = os.Remove(pidfile)
|
_ = os.Remove(pidfile)
|
||||||
|
|
||||||
// dump the log file outputs to os.Stdout/os.Stderr
|
// ideally we want to use io.MultiWriter here, sending one stream to stdout/stderr, another to the log
|
||||||
if err = dumpFile(os.Stdout, stdoutFile); err != nil {
|
// however, this hangs if we do, due to a runc bug, see https://github.com/opencontainers/runc/issues/1721#issuecomment-366315563
|
||||||
log.Printf("Error writing stdout of onboot service %s to console: %v", name, err)
|
// once that is fixed, this can be cleaned up
|
||||||
}
|
logger.Dump(stdoutLog)
|
||||||
if err = dumpFile(os.Stderr, stderrFile); err != nil {
|
logger.Dump(stderrLog)
|
||||||
log.Printf("Error writing stderr of onboot service %s to console: %v", name, err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_ = os.RemoveAll(tmpdir)
|
_ = os.RemoveAll(tmpdir)
|
||||||
|
Loading…
Reference in New Issue
Block a user