mirror of
https://github.com/rancher/os.git
synced 2025-07-18 09:01:03 +00:00
Copy init and cloud-init-save logs from before switchroot
Signed-off-by: Sven Dowideit <SvenDowideit@home.org.au>
This commit is contained in:
parent
32061238aa
commit
cbfe50c5ee
@ -258,7 +258,11 @@ func getDatasources(datasources []string) []datasource.Datasource {
|
|||||||
case "packet":
|
case "packet":
|
||||||
dss = append(dss, packet.NewDatasource(root))
|
dss = append(dss, packet.NewDatasource(root))
|
||||||
case "vmware":
|
case "vmware":
|
||||||
dss = append(dss, vmware.NewDatasource(root))
|
// made vmware datasource dependent on detecting vmware independently, as it crashes things otherwise
|
||||||
|
v := vmware.NewDatasource(root)
|
||||||
|
if v != nil {
|
||||||
|
dss = append(dss, v)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -295,7 +299,7 @@ func selectDatasource(sources []datasource.Datasource) datasource.Datasource {
|
|||||||
|
|
||||||
duration := datasourceInterval
|
duration := datasourceInterval
|
||||||
for {
|
for {
|
||||||
log.Infof("cloud-init: Checking availability of %q\n", s.Type())
|
log.Infof("cloud-init: Checking availability of %q", s.Type())
|
||||||
if s.IsAvailable() {
|
if s.IsAvailable() {
|
||||||
log.Infof("cloud-init: Datasource available: %s", s)
|
log.Infof("cloud-init: Datasource available: %s", s)
|
||||||
ds <- s
|
ds <- s
|
||||||
|
@ -19,6 +19,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/rancher/os/log"
|
"github.com/rancher/os/log"
|
||||||
|
"github.com/rancher/os/util"
|
||||||
|
|
||||||
"github.com/rancher/os/config/cloudinit/pkg"
|
"github.com/rancher/os/config/cloudinit/pkg"
|
||||||
|
|
||||||
@ -36,6 +37,9 @@ func (ovf ovfWrapper) readConfig(key string) (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewDatasource(fileName string) *VMWare {
|
func NewDatasource(fileName string) *VMWare {
|
||||||
|
if util.GetHypervisor() != "vmware" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
// read from provided ovf environment document (typically /media/ovfenv/ovf-env.xml)
|
// read from provided ovf environment document (typically /media/ovfenv/ovf-env.xml)
|
||||||
if fileName != "" {
|
if fileName != "" {
|
||||||
log.Printf("Using OVF environment from %s\n", fileName)
|
log.Printf("Using OVF environment from %s\n", fileName)
|
||||||
@ -69,6 +73,9 @@ func NewDatasource(fileName string) *VMWare {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (v VMWare) IsAvailable() bool {
|
func (v VMWare) IsAvailable() bool {
|
||||||
|
if util.GetHypervisor() != "vmware" {
|
||||||
|
return false
|
||||||
|
}
|
||||||
if v.ovfFileName != "" {
|
if v.ovfFileName != "" {
|
||||||
_, v.lastError = os.Stat(v.ovfFileName)
|
_, v.lastError = os.Stat(v.ovfFileName)
|
||||||
return !os.IsNotExist(v.lastError)
|
return !os.IsNotExist(v.lastError)
|
||||||
|
33
init/init.go
33
init/init.go
@ -19,8 +19,6 @@ import (
|
|||||||
"github.com/rancher/os/log"
|
"github.com/rancher/os/log"
|
||||||
"github.com/rancher/os/util"
|
"github.com/rancher/os/util"
|
||||||
"github.com/rancher/os/util/network"
|
"github.com/rancher/os/util/network"
|
||||||
|
|
||||||
"github.com/SvenDowideit/cpuid"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -93,7 +91,7 @@ func sysInit(c *config.CloudConfig) (*config.CloudConfig, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func MainInit() {
|
func MainInit() {
|
||||||
log.InitDeferedLogger()
|
log.InitLogger()
|
||||||
// TODO: this breaks and does nothing if the cfg is invalid (or is it due to threading?)
|
// TODO: this breaks and does nothing if the cfg is invalid (or is it due to threading?)
|
||||||
defer func() {
|
defer func() {
|
||||||
if r := recover(); r != nil {
|
if r := recover(); r != nil {
|
||||||
@ -327,7 +325,7 @@ func RunInit() error {
|
|||||||
}},
|
}},
|
||||||
config.CfgFuncData{"cloud-init", func(cfg *config.CloudConfig) (*config.CloudConfig, error) {
|
config.CfgFuncData{"cloud-init", func(cfg *config.CloudConfig) (*config.CloudConfig, error) {
|
||||||
cfg.Rancher.CloudInit.Datasources = config.LoadConfigWithPrefix(state).Rancher.CloudInit.Datasources
|
cfg.Rancher.CloudInit.Datasources = config.LoadConfigWithPrefix(state).Rancher.CloudInit.Datasources
|
||||||
hypervisor = checkHypervisor(cfg)
|
hypervisor = util.GetHypervisor()
|
||||||
if hypervisor == "vmware" {
|
if hypervisor == "vmware" {
|
||||||
// add vmware to the end - we don't want to over-ride an choices the user has made
|
// add vmware to the end - we don't want to over-ride an choices the user has made
|
||||||
cfg.Rancher.CloudInit.Datasources = append(cfg.Rancher.CloudInit.Datasources, hypervisor)
|
cfg.Rancher.CloudInit.Datasources = append(cfg.Rancher.CloudInit.Datasources, hypervisor)
|
||||||
@ -343,13 +341,22 @@ func RunInit() error {
|
|||||||
|
|
||||||
return config.LoadConfig(), nil
|
return config.LoadConfig(), nil
|
||||||
}},
|
}},
|
||||||
config.CfgFuncData{"read cfg files", func(cfg *config.CloudConfig) (*config.CloudConfig, error) {
|
config.CfgFuncData{"read cfg and log files", func(cfg *config.CloudConfig) (*config.CloudConfig, error) {
|
||||||
filesToCopy := []string{
|
filesToCopy := []string{
|
||||||
config.CloudConfigInitFile,
|
config.CloudConfigInitFile,
|
||||||
config.CloudConfigBootFile,
|
config.CloudConfigBootFile,
|
||||||
config.CloudConfigNetworkFile,
|
config.CloudConfigNetworkFile,
|
||||||
config.MetaDataFile,
|
config.MetaDataFile,
|
||||||
}
|
}
|
||||||
|
// And all the files in /var/log/boot/
|
||||||
|
// TODO: I wonder if we can put this code into the log module, and have things write to the buffer until we FsReady()
|
||||||
|
bootLog := "/var/log/boot/"
|
||||||
|
if files, err := ioutil.ReadDir(bootLog); err == nil {
|
||||||
|
for _, file := range files {
|
||||||
|
filePath := filepath.Join(bootLog, file.Name())
|
||||||
|
filesToCopy = append(filesToCopy, filePath)
|
||||||
|
}
|
||||||
|
}
|
||||||
for _, name := range filesToCopy {
|
for _, name := range filesToCopy {
|
||||||
if _, err := os.Lstat(name); !os.IsNotExist(err) {
|
if _, err := os.Lstat(name); !os.IsNotExist(err) {
|
||||||
content, err := ioutil.ReadFile(name)
|
content, err := ioutil.ReadFile(name)
|
||||||
@ -357,6 +364,7 @@ func RunInit() error {
|
|||||||
log.Errorf("read cfg file (%s) %s", name, err)
|
log.Errorf("read cfg file (%s) %s", name, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
log.Debugf("Saved %s to memory", name)
|
||||||
configFiles[name] = content
|
configFiles[name] = content
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -373,8 +381,7 @@ func RunInit() error {
|
|||||||
return cfg, nil
|
return cfg, nil
|
||||||
}},
|
}},
|
||||||
config.CfgFuncData{"mount OEM2", mountOem},
|
config.CfgFuncData{"mount OEM2", mountOem},
|
||||||
config.CfgFuncData{"write cfg files", func(cfg *config.CloudConfig) (*config.CloudConfig, error) {
|
config.CfgFuncData{"write cfg and log files", func(cfg *config.CloudConfig) (*config.CloudConfig, error) {
|
||||||
log.FsReady()
|
|
||||||
for name, content := range configFiles {
|
for name, content := range configFiles {
|
||||||
if err := os.MkdirAll(filepath.Dir(name), os.ModeDir|0700); err != nil {
|
if err := os.MkdirAll(filepath.Dir(name), os.ModeDir|0700); err != nil {
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
@ -382,6 +389,7 @@ func RunInit() error {
|
|||||||
if err := util.WriteFileAtomic(name, content, 400); err != nil {
|
if err := util.WriteFileAtomic(name, content, 400); err != nil {
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
}
|
}
|
||||||
|
log.Infof("Wrote log to %s", name)
|
||||||
}
|
}
|
||||||
if err := os.MkdirAll(config.VarRancherDir, os.ModeDir|0755); err != nil {
|
if err := os.MkdirAll(config.VarRancherDir, os.ModeDir|0755); err != nil {
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
@ -389,6 +397,8 @@ func RunInit() error {
|
|||||||
if err := os.Chmod(config.VarRancherDir, os.ModeDir|0755); err != nil {
|
if err := os.Chmod(config.VarRancherDir, os.ModeDir|0755); err != nil {
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
}
|
}
|
||||||
|
log.FsReady()
|
||||||
|
log.Debugf("WARNING: switchroot and mount OEM2 phases not written to log file")
|
||||||
|
|
||||||
return cfg, nil
|
return cfg, nil
|
||||||
}},
|
}},
|
||||||
@ -442,15 +452,6 @@ func RunInit() error {
|
|||||||
return pidOne()
|
return pidOne()
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkHypervisor(cfg *config.CloudConfig) string {
|
|
||||||
if cpuid.CPU.HypervisorName == "" {
|
|
||||||
log.Infof("ros init: No Detected Hypervisor")
|
|
||||||
} else {
|
|
||||||
log.Infof("ros init: Detected Hypervisor: %s", cpuid.CPU.HypervisorName)
|
|
||||||
}
|
|
||||||
return cpuid.CPU.HypervisorName
|
|
||||||
}
|
|
||||||
|
|
||||||
func enableHypervisorService(cfg *config.CloudConfig, hypervisorName string) {
|
func enableHypervisorService(cfg *config.CloudConfig, hypervisorName string) {
|
||||||
if hypervisorName == "" {
|
if hypervisorName == "" {
|
||||||
return
|
return
|
||||||
|
13
log/log.go
13
log/log.go
@ -5,8 +5,6 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"io/ioutil"
|
|
||||||
|
|
||||||
"github.com/Sirupsen/logrus"
|
"github.com/Sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -132,8 +130,8 @@ func InitLogger() {
|
|||||||
func logTheseApps() bool {
|
func logTheseApps() bool {
|
||||||
// TODO: mmm, not very functional.
|
// TODO: mmm, not very functional.
|
||||||
if filepath.Base(os.Args[0]) == "ros" ||
|
if filepath.Base(os.Args[0]) == "ros" ||
|
||||||
filepath.Base(os.Args[0]) == "host_ros" ||
|
// filepath.Base(os.Args[0]) == "system-docker" ||
|
||||||
filepath.Base(os.Args[0]) == "system-docker" {
|
filepath.Base(os.Args[0]) == "host_ros" {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
@ -145,7 +143,12 @@ func logTheseApps() bool {
|
|||||||
func InitDeferedLogger() {
|
func InitDeferedLogger() {
|
||||||
if logTheseApps() {
|
if logTheseApps() {
|
||||||
innerInit(true)
|
innerInit(true)
|
||||||
logrus.SetOutput(ioutil.Discard)
|
//logrus.SetOutput(ioutil.Discard)
|
||||||
|
// write to dmesg until we can write to file. (maybe we can do this if rancher.debug=true?)
|
||||||
|
f, err := os.OpenFile("/dev/kmsg", os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0644)
|
||||||
|
if err == nil {
|
||||||
|
logrus.SetOutput(f)
|
||||||
|
}
|
||||||
|
|
||||||
pwd, err := os.Getwd()
|
pwd, err := os.Getwd()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -34,6 +34,7 @@ rancher:
|
|||||||
- /usr/bin/ros:/usr/bin/ros:ro
|
- /usr/bin/ros:/usr/bin/ros:ro
|
||||||
- /usr/share/ros:/usr/share/ros:ro
|
- /usr/share/ros:/usr/share/ros:ro
|
||||||
- /var/lib/rancher:/var/lib/rancher:ro
|
- /var/lib/rancher:/var/lib/rancher:ro
|
||||||
|
- /var/log:/var/log
|
||||||
cloud_init_services:
|
cloud_init_services:
|
||||||
cloud-init:
|
cloud-init:
|
||||||
image: {{.OS_REPO}}/os-base:{{.VERSION}}{{.SUFFIX}}
|
image: {{.OS_REPO}}/os-base:{{.VERSION}}{{.SUFFIX}}
|
||||||
@ -57,6 +58,7 @@ rancher:
|
|||||||
- /usr/share/ros:/usr/share/ros:ro
|
- /usr/share/ros:/usr/share/ros:ro
|
||||||
- /var/lib/rancher:/var/lib/rancher
|
- /var/lib/rancher:/var/lib/rancher
|
||||||
- /var/lib/rancher/conf:/var/lib/rancher/conf
|
- /var/lib/rancher/conf:/var/lib/rancher/conf
|
||||||
|
- /var/log:/var/log
|
||||||
bootstrap_docker:
|
bootstrap_docker:
|
||||||
bridge: none
|
bridge: none
|
||||||
storage_driver: overlay
|
storage_driver: overlay
|
||||||
|
@ -11,6 +11,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
|
"github.com/SvenDowideit/cpuid"
|
||||||
"github.com/docker/docker/pkg/mount"
|
"github.com/docker/docker/pkg/mount"
|
||||||
"github.com/rancher/os/log"
|
"github.com/rancher/os/log"
|
||||||
)
|
)
|
||||||
@ -121,3 +122,13 @@ func Blkid(label string) (deviceName, deviceType string) {
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetHypervisor tries to detect if we're running in a VM, and returns a string for its type
|
||||||
|
func GetHypervisor() string {
|
||||||
|
if cpuid.CPU.HypervisorName == "" {
|
||||||
|
log.Infof("ros init: No Detected Hypervisor")
|
||||||
|
} else {
|
||||||
|
log.Infof("ros init: Detected Hypervisor: %s", cpuid.CPU.HypervisorName)
|
||||||
|
}
|
||||||
|
return cpuid.CPU.HypervisorName
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user