mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-21 10:09:07 +00:00
pkg/init: only create /var/log/onboot symlink if not using memlogd
When logging directly to files (the not-using-memlogd case) the onboot services must log to /run/log because /var/log might be overmounted by a persistent disk. Therefore we create a symlink at the end of the onboot section. When logging via memlogd, all logs are buffered until a logwrite service starts, so no symlink is needed. Signed-off-by: David Scott <dave.scott@docker.com>
This commit is contained in:
parent
5201049f2c
commit
7c243a8e8b
@ -29,6 +29,7 @@ type Log interface {
|
|||||||
Path(string) string // Path of the log file (may be a FIFO)
|
Path(string) string // Path of the log file (may be a FIFO)
|
||||||
Open(string) (io.WriteCloser, error) // Opens a log stream
|
Open(string) (io.WriteCloser, error) // Opens a log stream
|
||||||
Dump(string) // Copies logs to the console
|
Dump(string) // Copies logs to the console
|
||||||
|
Symlink(string) // Symlinks to the log directory (if there is one)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetLog returns the log destination we should use.
|
// GetLog returns the log destination we should use.
|
||||||
@ -82,6 +83,16 @@ func (f *fileLog) Dump(n string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Symlinks to the log directory. This is useful if we are logging directly to tmpfs and now need to symlink from a permanent disk.
|
||||||
|
func (f *fileLog) Symlink(path string) {
|
||||||
|
parent := filepath.Dir(path)
|
||||||
|
if err := os.MkdirAll(parent, 0755); err != nil {
|
||||||
|
log.Printf("Error creating secondary log directory %s: %v", parent, err)
|
||||||
|
} else if err := os.Symlink(f.dir, path); err != nil && !os.IsExist(err) {
|
||||||
|
log.Printf("Error creating symlink from %s to %s: %v", path, f.dir, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type remoteLog struct {
|
type remoteLog struct {
|
||||||
fifoDir string
|
fifoDir string
|
||||||
}
|
}
|
||||||
@ -164,6 +175,11 @@ func (r *remoteLog) Dump(n string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Symlinks to the log directory. This is a no-op because there is no log directory.
|
||||||
|
func (r *remoteLog) Symlink(path string) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func sendToLogger(name string, fd int) error {
|
func sendToLogger(name string, fd int) error {
|
||||||
var ctlSocket int
|
var ctlSocket int
|
||||||
var err error
|
var err error
|
||||||
|
@ -160,11 +160,7 @@ func runcInit(rootPath, serviceType string) int {
|
|||||||
_ = os.RemoveAll(tmpdir)
|
_ = os.RemoveAll(tmpdir)
|
||||||
|
|
||||||
// make sure the link exists from /var/log/onboot -> /run/log/onboot
|
// make sure the link exists from /var/log/onboot -> /run/log/onboot
|
||||||
if err := os.MkdirAll(varLogDir, 0755); err != nil {
|
logger.Symlink(varLogLink)
|
||||||
log.Printf("Error creating secondary log directory %s: %v", varLogDir, err)
|
|
||||||
} else if err := os.Symlink(logDir, varLogLink); err != nil && !os.IsExist(err) {
|
|
||||||
log.Printf("Error creating symlink from %s to %s: %v", varLogLink, logDir, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return status
|
return status
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user