1
0
mirror of https://github.com/rancher/os.git synced 2025-04-27 11:10:56 +00:00

Move around code for better clarity

This commit is contained in:
Darren Shepherd 2018-09-15 21:55:26 -07:00 committed by niusmallnan
parent 2f50b7b178
commit 1f50386828
112 changed files with 992 additions and 859 deletions

View File

@ -7,8 +7,8 @@ import (
"strconv"
"strings"
"github.com/rancher/os/log"
"github.com/rancher/os/util"
"github.com/rancher/os/pkg/log"
"github.com/rancher/os/pkg/util"
)
const (

View File

@ -12,9 +12,9 @@ import (
rancherConfig "github.com/rancher/os/config"
"github.com/rancher/os/config/cloudinit/config"
"github.com/rancher/os/config/cloudinit/system"
"github.com/rancher/os/docker"
"github.com/rancher/os/log"
"github.com/rancher/os/util"
"github.com/rancher/os/pkg/docker"
"github.com/rancher/os/pkg/log"
"github.com/rancher/os/pkg/util"
"golang.org/x/net/context"
)

View File

@ -43,9 +43,9 @@ import (
"github.com/rancher/os/config/cloudinit/datasource/url"
"github.com/rancher/os/config/cloudinit/datasource/vmware"
"github.com/rancher/os/config/cloudinit/pkg"
"github.com/rancher/os/log"
"github.com/rancher/os/netconf"
"github.com/rancher/os/util"
"github.com/rancher/os/pkg/log"
"github.com/rancher/os/pkg/netconf"
"github.com/rancher/os/pkg/util"
)
const (

View File

@ -10,7 +10,7 @@ import (
"github.com/codegangsta/cli"
"github.com/rancher/os/config"
"github.com/rancher/os/log"
"github.com/rancher/os/pkg/log"
)
func AutologinMain() {

View File

@ -8,8 +8,8 @@ import (
"time"
"github.com/rancher/os/config"
"github.com/rancher/os/log"
"github.com/rancher/os/util"
"github.com/rancher/os/pkg/log"
"github.com/rancher/os/pkg/util"
)
func BootstrapMain() {

View File

@ -7,7 +7,7 @@ import (
"github.com/codegangsta/cli"
"github.com/rancher/os/cmd/control/service"
"github.com/rancher/os/config"
"github.com/rancher/os/log"
"github.com/rancher/os/pkg/log"
)
func Main() {

View File

@ -11,11 +11,11 @@ import (
"text/template"
yaml "github.com/cloudfoundry-incubator/candiedyaml"
"github.com/rancher/os/log"
"github.com/rancher/os/pkg/log"
"github.com/codegangsta/cli"
"github.com/rancher/os/config"
"github.com/rancher/os/util"
"github.com/rancher/os/pkg/util"
)
func configSubcommands() []cli.Command {

View File

@ -12,12 +12,12 @@ import (
composeConfig "github.com/docker/libcompose/config"
"github.com/docker/libcompose/project/options"
"github.com/rancher/os/cmd/control/service"
"github.com/rancher/os/compose"
"github.com/rancher/os/config"
"github.com/rancher/os/docker"
"github.com/rancher/os/log"
"github.com/rancher/os/util"
"github.com/rancher/os/util/network"
"github.com/rancher/os/pkg/compose"
"github.com/rancher/os/pkg/docker"
"github.com/rancher/os/pkg/log"
"github.com/rancher/os/pkg/util"
"github.com/rancher/os/pkg/util/network"
)
func consoleSubcommands() []cli.Command {

View File

@ -15,11 +15,11 @@ import (
"github.com/codegangsta/cli"
"github.com/rancher/os/cmd/cloudinitexecute"
"github.com/rancher/os/compose"
"github.com/rancher/os/config"
"github.com/rancher/os/config/cmdline"
"github.com/rancher/os/log"
"github.com/rancher/os/util"
"github.com/rancher/os/pkg/compose"
"github.com/rancher/os/pkg/log"
"github.com/rancher/os/pkg/util"
)
const (

View File

@ -4,7 +4,7 @@ import (
"fmt"
"github.com/codegangsta/cli"
"github.com/rancher/os/util"
"github.com/rancher/os/pkg/util"
)
func devAction(c *cli.Context) error {

View File

@ -10,8 +10,8 @@ import (
"time"
"github.com/codegangsta/cli"
"github.com/rancher/os/log"
"github.com/rancher/os/util"
"github.com/rancher/os/pkg/log"
"github.com/rancher/os/pkg/util"
)
const (

View File

@ -23,12 +23,12 @@ import (
"github.com/pkg/errors"
"github.com/rancher/os/cmd/control/service"
"github.com/rancher/os/cmd/control/service/app"
"github.com/rancher/os/compose"
"github.com/rancher/os/config"
"github.com/rancher/os/docker"
"github.com/rancher/os/log"
"github.com/rancher/os/util"
"github.com/rancher/os/util/network"
"github.com/rancher/os/pkg/compose"
"github.com/rancher/os/pkg/docker"
"github.com/rancher/os/pkg/log"
"github.com/rancher/os/pkg/util"
"github.com/rancher/os/pkg/util/network"
)
var (

View File

@ -6,13 +6,13 @@ import (
"syscall"
"github.com/codegangsta/cli"
"github.com/rancher/os/log"
"github.com/rancher/os/pkg/log"
"golang.org/x/net/context"
"github.com/rancher/os/cmd/cloudinitexecute"
"github.com/rancher/os/config"
"github.com/rancher/os/docker"
"github.com/rancher/os/util"
"github.com/rancher/os/pkg/docker"
"github.com/rancher/os/pkg/util"
)
const (

View File

@ -8,7 +8,7 @@ import (
"github.com/codegangsta/cli"
"github.com/rancher/os/config"
"github.com/rancher/os/util"
"github.com/rancher/os/pkg/util"
)
func envAction(c *cli.Context) error {

View File

@ -14,7 +14,7 @@ import (
"strconv"
"strings"
"github.com/rancher/os/log"
"github.com/rancher/os/pkg/log"
"github.com/codegangsta/cli"
"github.com/pkg/errors"
@ -22,8 +22,8 @@ import (
"github.com/rancher/os/cmd/control/install"
"github.com/rancher/os/cmd/power"
"github.com/rancher/os/config"
"github.com/rancher/os/dfs" // TODO: move CopyFile into util or something.
"github.com/rancher/os/util"
"github.com/rancher/os/pkg/dfs" // TODO: move CopyFile into util or something.
"github.com/rancher/os/pkg/util"
)
var installCommand = cli.Command{

View File

@ -6,7 +6,7 @@ import (
"os/exec"
"path/filepath"
"github.com/rancher/os/log"
"github.com/rancher/os/pkg/log"
)
func RunGrub(baseName, device string) error {

View File

@ -7,8 +7,8 @@ import (
"strings"
"github.com/rancher/os/config"
"github.com/rancher/os/log"
"github.com/rancher/os/util"
"github.com/rancher/os/pkg/log"
"github.com/rancher/os/pkg/util"
)
const BootDir = "boot/"

View File

@ -9,7 +9,7 @@ import (
"path/filepath"
"strings"
"github.com/rancher/os/log"
"github.com/rancher/os/pkg/log"
)
func syslinuxConfig(menu BootVars) error {

View File

@ -11,18 +11,18 @@ import (
"golang.org/x/net/context"
yaml "github.com/cloudfoundry-incubator/candiedyaml"
"github.com/rancher/os/log"
"github.com/rancher/os/pkg/log"
"github.com/codegangsta/cli"
dockerClient "github.com/docker/engine-api/client"
composeConfig "github.com/docker/libcompose/config"
"github.com/docker/libcompose/project/options"
"github.com/rancher/os/cmd/power"
"github.com/rancher/os/compose"
"github.com/rancher/os/config"
"github.com/rancher/os/docker"
"github.com/rancher/os/util"
"github.com/rancher/os/util/network"
"github.com/rancher/os/pkg/compose"
"github.com/rancher/os/pkg/docker"
"github.com/rancher/os/pkg/util"
"github.com/rancher/os/pkg/util/network"
)
type Images struct {

View File

@ -16,8 +16,8 @@ import (
dockerClient "github.com/docker/engine-api/client"
"github.com/docker/engine-api/types"
"github.com/rancher/os/config"
"github.com/rancher/os/docker"
"github.com/rancher/os/log"
"github.com/rancher/os/pkg/docker"
"github.com/rancher/os/pkg/log"
)
const (

View File

@ -6,7 +6,7 @@ import (
"syscall"
"github.com/codegangsta/cli"
"github.com/rancher/os/log"
"github.com/rancher/os/pkg/log"
)
func recoveryInitAction(c *cli.Context) error {

View File

@ -7,7 +7,7 @@ import (
"strings"
"syscall"
"github.com/rancher/os/log"
"github.com/rancher/os/pkg/log"
"golang.org/x/net/context"
"github.com/codegangsta/cli"

View File

@ -8,11 +8,11 @@ import (
dockerApp "github.com/docker/libcompose/cli/docker/app"
"github.com/docker/libcompose/project"
"github.com/rancher/os/cmd/control/service/command"
"github.com/rancher/os/compose"
"github.com/rancher/os/config"
"github.com/rancher/os/log"
"github.com/rancher/os/util"
"github.com/rancher/os/util/network"
"github.com/rancher/os/pkg/compose"
"github.com/rancher/os/pkg/log"
"github.com/rancher/os/pkg/util"
"github.com/rancher/os/pkg/util/network"
)
type projectFactory struct {

View File

@ -5,9 +5,9 @@ import (
"github.com/codegangsta/cli"
"github.com/docker/libcompose/project/options"
"github.com/rancher/os/compose"
"github.com/rancher/os/config"
"github.com/rancher/os/log"
"github.com/rancher/os/pkg/compose"
"github.com/rancher/os/pkg/log"
"golang.org/x/net/context"
)

View File

@ -5,12 +5,12 @@ import (
"os"
"path/filepath"
"github.com/rancher/os/log"
"github.com/rancher/os/pkg/log"
"github.com/codegangsta/cli"
machineUtil "github.com/docker/machine/utils"
"github.com/rancher/os/config"
"github.com/rancher/os/util"
"github.com/rancher/os/pkg/util"
)
const (

View File

@ -5,7 +5,7 @@ import (
"os/exec"
"github.com/codegangsta/cli"
"github.com/rancher/os/log"
"github.com/rancher/os/pkg/log"
)
func udevSettleAction(c *cli.Context) {

View File

@ -15,11 +15,11 @@ import (
"github.com/codegangsta/cli"
composeClient "github.com/docker/libcompose/docker/client"
"github.com/docker/libcompose/project"
"github.com/rancher/os/compose"
"github.com/rancher/os/config"
rosDocker "github.com/rancher/os/docker"
"github.com/rancher/os/log"
"github.com/rancher/os/util"
"github.com/rancher/os/pkg/compose"
rosDocker "github.com/rancher/os/pkg/docker"
"github.com/rancher/os/pkg/log"
"github.com/rancher/os/pkg/util"
)
const (

View File

@ -7,7 +7,7 @@ import (
"strings"
"github.com/rancher/os/config"
"github.com/rancher/os/log"
"github.com/rancher/os/pkg/log"
)
func yes(question string) bool {

92
cmd/init/init.go Normal file
View File

@ -0,0 +1,92 @@
// +build linux
package init
import (
"fmt"
"github.com/rancher/os/pkg/init/selinux"
"github.com/rancher/os/pkg/init/docker"
"github.com/rancher/os/pkg/init/one"
"github.com/rancher/os/config"
"github.com/rancher/os/pkg/dfs"
"github.com/rancher/os/pkg/init/b2d"
"github.com/rancher/os/pkg/init/cloudinit"
"github.com/rancher/os/pkg/init/configfiles"
"github.com/rancher/os/pkg/init/debug"
"github.com/rancher/os/pkg/init/env"
"github.com/rancher/os/pkg/init/fsmount"
"github.com/rancher/os/pkg/init/hypervisor"
"github.com/rancher/os/pkg/init/modules"
"github.com/rancher/os/pkg/init/prepare"
"github.com/rancher/os/pkg/init/recovery"
"github.com/rancher/os/pkg/init/sharedroot"
"github.com/rancher/os/pkg/init/switchroot"
"github.com/rancher/os/pkg/log"
"github.com/rancher/os/pkg/sysinit"
)
func MainInit() {
log.InitLogger()
// TODO: this breaks and does nothing if the cfg is invalid (or is it due to threading?)
defer func() {
if r := recover(); r != nil {
fmt.Printf("Starting Recovery console: %v\n", r)
recovery.Recovery(nil)
}
}()
if err := RunInit(); err != nil {
log.Fatal(err)
}
}
func RunInit() error {
initFuncs := config.CfgFuncs{
{"set env", env.Init},
{"preparefs", prepare.FS},
{"save init cmdline", prepare.SaveCmdline},
{"mount OEM", fsmount.OEM},
{"debug save cfg", debug.PrintAndLoadConfig},
{"load modules", modules.LoadModules},
{"recovery console", recovery.LoadRecoveryConsole},
{"cloud-init", cloudinit.CloudInit},
{"b2d env", b2d.B2D},
{"mount and bootstrap", fsmount.MountAndBootstrap},
{"read cfg and log files", configfiles.ReadConfigFiles},
{"switchroot", switchroot.SwitchRoot},
{"mount OEM2", fsmount.OEM},
{"write cfg and log files", configfiles.WriteConfigFiles},
{"hypervisor Env", hypervisor.Env},
{"b2d Env", b2d.Env},
{"hypervisor tools", hypervisor.Tools},
{"preparefs2", prepare.FS},
{"load modules2", modules.LoadModules},
{"set proxy env", env.Proxy},
{"init SELinux", selinux.Initialize},
{"setupSharedRoot", sharedroot.Setup},
{"sysinit", sysinit.RunSysInit},
}
cfg, err := config.ChainCfgFuncs(nil, initFuncs)
if err != nil {
recovery.Recovery(err)
}
launchConfig, args := docker.GetLaunchConfig(cfg, &cfg.Rancher.SystemDocker)
launchConfig.Fork = !cfg.Rancher.SystemDocker.Exec
//launchConfig.NoLog = true
log.Info("Launching System Docker")
_, err = dfs.LaunchDocker(launchConfig, config.SystemDockerBin, args...)
if err != nil {
log.Errorf("Error Launching System Docker: %s", err)
recovery.Recovery(err)
return err
}
// Code never gets here - rancher.system_docker.exec=true
return one.PidOne()
}

View File

@ -3,15 +3,15 @@ package network
import (
"golang.org/x/net/context"
"github.com/rancher/os/docker"
"github.com/rancher/os/log"
"github.com/rancher/os/pkg/docker"
"github.com/rancher/os/pkg/log"
"io/ioutil"
"github.com/docker/libnetwork/resolvconf"
"github.com/rancher/os/config"
"github.com/rancher/os/hostname"
"github.com/rancher/os/netconf"
"github.com/rancher/os/pkg/hostname"
"github.com/rancher/os/pkg/netconf"
)
func Main() {

View File

@ -17,10 +17,10 @@ import (
"github.com/docker/engine-api/types/filters"
"github.com/rancher/os/cmd/control/install"
"github.com/rancher/os/config"
"github.com/rancher/os/log"
"github.com/rancher/os/pkg/log"
"github.com/rancher/os/docker"
"github.com/rancher/os/util"
"github.com/rancher/os/pkg/docker"
"github.com/rancher/os/pkg/util"
)
// You can't shutdown the system from a process in console because we want to stop the console container.

View File

@ -10,7 +10,7 @@ import (
"github.com/codegangsta/cli"
"github.com/rancher/os/cmd/control/install"
"github.com/rancher/os/config"
"github.com/rancher/os/log"
"github.com/rancher/os/pkg/log"
)
var (

View File

@ -15,7 +15,7 @@ import (
"github.com/codegangsta/cli"
"github.com/rancher/os/config"
"github.com/rancher/os/log"
"github.com/rancher/os/pkg/log"
)
var (

View File

@ -4,8 +4,8 @@ import (
"io/ioutil"
"os"
initPkg "github.com/rancher/os/init"
"github.com/rancher/os/log"
"github.com/rancher/os/pkg/log"
"github.com/rancher/os/pkg/sysinit"
)
func Main() {
@ -15,7 +15,7 @@ func Main() {
log.Infof("Resolv.conf == [%s], %v", resolve, err)
log.Infof("Exec %v", os.Args)
if err := initPkg.SysInit(); err != nil {
if err := sysinit.SysInit(); err != nil {
log.Fatal(err)
}
}

View File

@ -4,8 +4,8 @@ import (
"os"
"github.com/rancher/os/config"
"github.com/rancher/os/docker"
"github.com/rancher/os/log"
"github.com/rancher/os/pkg/docker"
"github.com/rancher/os/pkg/log"
)
func Main() {

View File

@ -22,6 +22,6 @@ COVERPKG=${COVERPKG//./}
# generate arg for "go test"
export COVER="-coverprofile ${COVEROUT}/${COVERPKG}.out"
source ./test
source test
go tool cover -html=${COVEROUT}/${COVERPKG}.out

View File

@ -22,11 +22,11 @@ import (
"path"
"syscall"
"github.com/rancher/os/log"
"github.com/rancher/os/pkg/log"
"github.com/docker/docker/pkg/mount"
"github.com/rancher/os/config/cloudinit/datasource"
"github.com/rancher/os/util"
"github.com/rancher/os/pkg/util"
)
const (

View File

@ -17,7 +17,7 @@ package datasource
import (
"net"
"github.com/rancher/os/netconf"
"github.com/rancher/os/pkg/netconf"
)
type Datasource interface {

View File

@ -5,7 +5,7 @@ import (
"log"
"strings"
"github.com/rancher/os/netconf"
"github.com/rancher/os/pkg/netconf"
"github.com/rancher/os/config/cloudinit/datasource"
"github.com/rancher/os/config/cloudinit/datasource/metadata"

View File

@ -19,12 +19,12 @@ import (
"strconv"
"strings"
"github.com/rancher/os/netconf"
"github.com/rancher/os/pkg/netconf"
"github.com/rancher/os/config/cloudinit/datasource"
"github.com/rancher/os/config/cloudinit/datasource/metadata"
"github.com/rancher/os/config/cloudinit/pkg"
"github.com/rancher/os/log"
"github.com/rancher/os/pkg/log"
)
const (

View File

@ -19,7 +19,7 @@ import (
"fmt"
"strconv"
"github.com/rancher/os/netconf"
"github.com/rancher/os/pkg/netconf"
"net"

View File

@ -20,7 +20,7 @@ import (
"reflect"
"testing"
"github.com/rancher/os/netconf"
"github.com/rancher/os/pkg/netconf"
"github.com/rancher/os/config/cloudinit/datasource"
"github.com/rancher/os/config/cloudinit/datasource/metadata"

View File

@ -20,7 +20,7 @@ import (
"net"
"strings"
"github.com/rancher/os/netconf"
"github.com/rancher/os/pkg/netconf"
"github.com/rancher/os/config/cloudinit/datasource"
"github.com/rancher/os/config/cloudinit/datasource/metadata"

View File

@ -24,7 +24,7 @@ import (
"github.com/rancher/os/config/cloudinit/datasource/metadata"
"github.com/rancher/os/config/cloudinit/datasource/metadata/test"
"github.com/rancher/os/config/cloudinit/pkg"
"github.com/rancher/os/netconf"
"github.com/rancher/os/pkg/netconf"
)
func TestType(t *testing.T) {

View File

@ -22,7 +22,7 @@ import (
"strings"
"github.com/rancher/os/config/cloudinit/pkg"
"github.com/rancher/os/log"
"github.com/rancher/os/pkg/log"
)
type Service struct {

View File

@ -21,8 +21,8 @@ import (
"github.com/rancher/os/config/cloudinit/datasource"
"github.com/rancher/os/config/cloudinit/datasource/metadata"
"github.com/rancher/os/log"
"github.com/rancher/os/netconf"
"github.com/rancher/os/pkg/log"
"github.com/rancher/os/pkg/netconf"
yaml "github.com/cloudfoundry-incubator/candiedyaml"
packetMetadata "github.com/packethost/packngo/metadata"

View File

@ -20,7 +20,7 @@ import (
"io/ioutil"
"strings"
"github.com/rancher/os/log"
"github.com/rancher/os/pkg/log"
"github.com/rancher/os/config/cloudinit/datasource"
"github.com/rancher/os/config/cloudinit/pkg"

View File

@ -19,7 +19,7 @@ import (
"github.com/rancher/os/config/cloudinit/datasource"
"github.com/rancher/os/config/cloudinit/pkg"
"github.com/rancher/os/util/network"
"github.com/rancher/os/pkg/util/network"
)
type RemoteFile struct {

View File

@ -21,8 +21,8 @@ import (
"github.com/rancher/os/config/cloudinit/config"
"github.com/rancher/os/config/cloudinit/datasource"
"github.com/rancher/os/log"
"github.com/rancher/os/netconf"
"github.com/rancher/os/pkg/log"
"github.com/rancher/os/pkg/netconf"
)
type readConfigFunction func(key string) (string, error)

View File

@ -18,8 +18,8 @@ import (
"io/ioutil"
"os"
"github.com/rancher/os/log"
"github.com/rancher/os/util"
"github.com/rancher/os/pkg/log"
"github.com/rancher/os/pkg/util"
"github.com/rancher/os/config/cloudinit/pkg"

View File

@ -25,7 +25,7 @@ import (
"testing"
"github.com/rancher/os/config/cloudinit/datasource"
"github.com/rancher/os/netconf"
"github.com/rancher/os/pkg/netconf"
)
type MockHypervisor map[string]string

View File

@ -22,7 +22,7 @@ import (
"os"
"path"
"github.com/rancher/os/log"
"github.com/rancher/os/pkg/log"
"github.com/rancher/os/config/cloudinit/datasource"
)

View File

@ -17,7 +17,7 @@ package network
import (
"net"
"github.com/rancher/os/netconf"
"github.com/rancher/os/pkg/netconf"
)
func ProcessPacketNetconf(netdata netconf.NetworkConfig) ([]InterfaceGenerator, error) {

View File

@ -1,6 +1,6 @@
#!/bin/bash -e
source ./build
source build
SRC=$(find . -name '*.go' \
-not -path "./vendor/*")

View File

@ -5,7 +5,7 @@ import (
"strings"
yaml "github.com/cloudfoundry-incubator/candiedyaml"
"github.com/rancher/os/util"
"github.com/rancher/os/pkg/util"
)
func Read(parseAll bool) (m map[interface{}]interface{}, err error) {
@ -125,7 +125,7 @@ func UnmarshalOrReturnString(value string) (result interface{}) {
}
func Parse(cmdLine string, parseAll bool) map[interface{}]interface{} {
result := make(map[interface{}]interface{})
result := map[interface{}]interface{}{}
outer:
for _, part := range strings.Split(cmdLine, " ") {

View File

@ -6,7 +6,7 @@ import (
yaml "github.com/cloudfoundry-incubator/candiedyaml"
"github.com/rancher/os/config/cmdline"
"github.com/rancher/os/util"
"github.com/rancher/os/pkg/util"
)
const Banner = `

View File

@ -6,7 +6,7 @@ import (
yaml "github.com/cloudfoundry-incubator/candiedyaml"
"github.com/rancher/os/config/cmdline"
"github.com/rancher/os/util"
"github.com/rancher/os/pkg/util"
"github.com/stretchr/testify/require"
)

View File

@ -1,8 +1,8 @@
package config
import (
"github.com/rancher/os/log"
"github.com/rancher/os/util"
"github.com/rancher/os/pkg/log"
"github.com/rancher/os/pkg/util"
)
type CfgFunc func(*CloudConfig) (*CloudConfig, error)

View File

@ -15,8 +15,8 @@ import (
"github.com/rancher/os/config/cloudinit/datasource"
"github.com/rancher/os/config/cloudinit/initialize"
"github.com/rancher/os/config/cmdline"
"github.com/rancher/os/log"
"github.com/rancher/os/util"
"github.com/rancher/os/pkg/log"
"github.com/rancher/os/pkg/util"
)
func ReadConfig(bytes []byte, substituteMetadataVars bool, files ...string) (*CloudConfig, error) {

View File

@ -8,28 +8,22 @@ import (
composeConfig "github.com/docker/libcompose/config"
"github.com/rancher/os/config/cloudinit/config"
"github.com/rancher/os/config/yaml"
"github.com/rancher/os/netconf"
"github.com/rancher/os/pkg/netconf"
)
const (
OEM = "/usr/share/ros/oem"
DockerBin = "/usr/bin/docker"
DockerDistBin = "/usr/bin/docker.dist"
RosBin = "/usr/bin/ros"
SysInitBin = "/usr/bin/ros-sysinit"
SystemDockerHome = "/var/lib/system-docker"
SystemDockerHost = "unix:///var/run/system-docker.sock"
DockerHost = "unix:///var/run/docker.sock"
ImagesPath = "/usr/share/ros"
InitImages = "images-init.tar"
SystemImages = "images-system.tar"
ModulesArchive = "/modules.tar"
Debug = false
SystemDockerLog = "/var/log/system-docker.log"
SystemDockerBin = "/usr/bin/system-dockerd"
HashLabel = "io.rancher.os.hash"
IDLabel = "io.rancher.os.id"
DetachLabel = "io.rancher.os.detach"
CreateOnlyLabel = "io.rancher.os.createonly"
ReloadConfigLabel = "io.rancher.os.reloadconfig"
@ -53,6 +47,7 @@ const (
EtcResolvConfFile = "/etc/resolv.conf"
MultiDockerConfFile = "/var/lib/rancher/conf.d/m-user-docker.yml"
MultiDockerDataDir = "/var/lib/m-user-docker"
State = "/state"
)
var (

View File

@ -6,7 +6,7 @@ import (
"testing"
yaml "github.com/cloudfoundry-incubator/candiedyaml"
"github.com/rancher/os/util"
"github.com/rancher/os/pkg/util"
)
func testValidate(t *testing.T, cfg []byte, contains string) {

View File

@ -1,91 +0,0 @@
package init
import (
"syscall"
"github.com/rancher/os/compose"
"github.com/rancher/os/config"
"github.com/rancher/os/dfs"
"github.com/rancher/os/log"
"github.com/rancher/os/util"
)
func bootstrapServices(cfg *config.CloudConfig) (*config.CloudConfig, error) {
if util.ResolveDevice(cfg.Rancher.State.Dev) != "" && len(cfg.Bootcmd) == 0 {
log.Info("NOT Running Bootstrap")
return cfg, nil
}
log.Info("Running Bootstrap")
_, err := compose.RunServiceSet("bootstrap", cfg, cfg.Rancher.BootstrapContainers)
return cfg, err
}
func runCloudInitServiceSet(cfg *config.CloudConfig) (*config.CloudConfig, error) {
log.Info("Running cloud-init services")
_, err := compose.RunServiceSet("cloud-init", cfg, cfg.Rancher.CloudInitServices)
return cfg, err
}
func startDocker(cfg *config.CloudConfig) (chan interface{}, error) {
launchConfig, args := getLaunchConfig(cfg, &cfg.Rancher.BootstrapDocker)
launchConfig.Fork = true
launchConfig.LogFile = ""
launchConfig.NoLog = true
cmd, err := dfs.LaunchDocker(launchConfig, config.SystemDockerBin, args...)
if err != nil {
return nil, err
}
c := make(chan interface{})
go func() {
<-c
cmd.Process.Signal(syscall.SIGTERM)
cmd.Wait()
c <- struct{}{}
}()
return c, nil
}
func stopDocker(c chan interface{}) error {
c <- struct{}{}
<-c
return nil
}
func bootstrap(cfg *config.CloudConfig) error {
log.Info("Launching Bootstrap Docker")
c, err := startDocker(cfg)
if err != nil {
return err
}
defer stopDocker(c)
_, err = config.ChainCfgFuncs(cfg,
[]config.CfgFuncData{
config.CfgFuncData{"bootstrap loadImages", loadBootstrapImages},
config.CfgFuncData{"bootstrap Services", bootstrapServices},
})
return err
}
func runCloudInitServices(cfg *config.CloudConfig) error {
c, err := startDocker(cfg)
if err != nil {
return err
}
defer stopDocker(c)
_, err = config.ChainCfgFuncs(cfg,
[]config.CfgFuncData{
config.CfgFuncData{"cloudinit loadImages", loadBootstrapImages},
config.CfgFuncData{"cloudinit Services", runCloudInitServiceSet},
})
return err
}

View File

@ -1,564 +0,0 @@
// +build linux
package init
import (
"bufio"
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"strings"
"syscall"
"github.com/docker/docker/pkg/mount"
"github.com/rancher/os/config"
"github.com/rancher/os/dfs"
"github.com/rancher/os/log"
"github.com/rancher/os/util"
"github.com/rancher/os/util/network"
)
const (
state string = "/state"
boot2DockerMagic string = "boot2docker, please format-me"
tmpfsMagic int64 = 0x01021994
ramfsMagic int64 = 0x858458f6
)
var (
mountConfig = dfs.Config{
CgroupHierarchy: map[string]string{
"cpu": "cpu",
"cpuacct": "cpu",
"net_cls": "net_cls",
"net_prio": "net_cls",
},
}
)
func loadModules(cfg *config.CloudConfig) (*config.CloudConfig, error) {
mounted := map[string]bool{}
f, err := os.Open("/proc/modules")
if err != nil {
return cfg, err
}
defer f.Close()
reader := bufio.NewScanner(f)
for reader.Scan() {
mounted[strings.SplitN(reader.Text(), " ", 2)[0]] = true
}
if util.GetHypervisor() == "hyperv" {
cfg.Rancher.Modules = append(cfg.Rancher.Modules, "hv_utils")
}
for _, module := range cfg.Rancher.Modules {
if mounted[module] {
continue
}
log.Debugf("Loading module %s", module)
// split module and module parameters
cmdParam := strings.SplitN(module, " ", -1)
cmd := exec.Command("modprobe", cmdParam...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
log.Errorf("Could not load module %s, err %v", module, err)
}
}
return cfg, nil
}
func sysInit(c *config.CloudConfig) (*config.CloudConfig, error) {
args := append([]string{config.SysInitBin}, os.Args[1:]...)
cmd := &exec.Cmd{
Path: config.RosBin,
Args: args,
}
cmd.Stdin = os.Stdin
cmd.Stderr = os.Stderr
cmd.Stdout = os.Stdout
if err := cmd.Start(); err != nil {
return c, err
}
return c, os.Stdin.Close()
}
func MainInit() {
log.InitLogger()
// TODO: this breaks and does nothing if the cfg is invalid (or is it due to threading?)
defer func() {
if r := recover(); r != nil {
fmt.Printf("Starting Recovery console: %v\n", r)
recovery(nil)
}
}()
if err := RunInit(); err != nil {
log.Fatal(err)
}
}
func mountConfigured(display, dev, fsType, target string) error {
var err error
if dev == "" {
return nil
}
dev = util.ResolveDevice(dev)
if dev == "" {
return fmt.Errorf("Could not resolve device %q", dev)
}
if fsType == "auto" {
fsType, err = util.GetFsType(dev)
}
if err != nil {
return err
}
log.Debugf("FsType has been set to %s", fsType)
log.Infof("Mounting %s device %s to %s", display, dev, target)
return util.Mount(dev, target, fsType, "")
}
func mountState(cfg *config.CloudConfig) error {
return mountConfigured("state", cfg.Rancher.State.Dev, cfg.Rancher.State.FsType, state)
}
func mountOem(cfg *config.CloudConfig) (*config.CloudConfig, error) {
if cfg == nil {
cfg = config.LoadConfig()
}
if err := mountConfigured("oem", cfg.Rancher.State.OemDev, cfg.Rancher.State.OemFsType, config.OEM); err != nil {
log.Debugf("Not mounting OEM: %v", err)
} else {
log.Infof("Mounted OEM: %s", cfg.Rancher.State.OemDev)
}
return cfg, nil
}
func tryMountState(cfg *config.CloudConfig) error {
err := mountState(cfg)
if err == nil {
return nil
}
log.Infof("Skipped an error when first mounting: %v", err)
// If we failed to mount lets run bootstrap and try again
if err := bootstrap(cfg); err != nil {
return err
}
return mountState(cfg)
}
func tryMountAndBootstrap(cfg *config.CloudConfig) (*config.CloudConfig, bool, error) {
if !isInitrd() || cfg.Rancher.State.Dev == "" {
return cfg, false, nil
}
if err := tryMountState(cfg); !cfg.Rancher.State.Required && err != nil {
return cfg, false, nil
} else if err != nil {
return cfg, false, err
}
return cfg, true, nil
}
func getLaunchConfig(cfg *config.CloudConfig, dockerCfg *config.DockerConfig) (*dfs.Config, []string) {
var launchConfig dfs.Config
args := dfs.ParseConfig(&launchConfig, dockerCfg.FullArgs()...)
launchConfig.DNSConfig.Nameservers = cfg.Rancher.Defaults.Network.DNS.Nameservers
launchConfig.DNSConfig.Search = cfg.Rancher.Defaults.Network.DNS.Search
launchConfig.Environment = dockerCfg.Environment
if !cfg.Rancher.Debug {
launchConfig.LogFile = config.SystemDockerLog
}
return &launchConfig, args
}
func isInitrd() bool {
var stat syscall.Statfs_t
syscall.Statfs("/", &stat)
return int64(stat.Type) == tmpfsMagic || int64(stat.Type) == ramfsMagic
}
func setupSharedRoot(c *config.CloudConfig) (*config.CloudConfig, error) {
if c.Rancher.NoSharedRoot {
return c, nil
}
if isInitrd() {
for _, i := range []string{"/mnt", "/media", "/var/lib/system-docker"} {
if err := os.MkdirAll(i, 0755); err != nil {
return c, err
}
if err := mount.Mount("tmpfs", i, "tmpfs", "rw"); err != nil {
return c, err
}
if err := mount.MakeShared(i); err != nil {
return c, err
}
}
return c, nil
}
return c, mount.MakeShared("/")
}
func PrintConfig() {
cfgString, err := config.Export(false, true)
if err != nil {
log.WithFields(log.Fields{"err": err}).Error("Error serializing config")
} else {
log.Debugf("Config: %s", cfgString)
}
}
func RunInit() error {
os.Setenv("PATH", "/sbin:/usr/sbin:/usr/bin")
if isInitrd() {
log.Debug("Booting off an in-memory filesystem")
// Magic setting to tell Docker to do switch_root and not pivot_root
os.Setenv("DOCKER_RAMDISK", "true")
} else {
log.Debug("Booting off a persistent filesystem")
}
boot2DockerEnvironment := false
var shouldSwitchRoot bool
hypervisor := ""
configFiles := make(map[string][]byte)
initFuncs := []config.CfgFuncData{
config.CfgFuncData{"preparefs", func(c *config.CloudConfig) (*config.CloudConfig, error) {
return c, dfs.PrepareFs(&mountConfig)
}},
config.CfgFuncData{"save init cmdline", func(c *config.CloudConfig) (*config.CloudConfig, error) {
// the Kernel Patch added for RancherOS passes `--` (only) elided kernel boot params to the init process
cmdLineArgs := strings.Join(os.Args, " ")
config.SaveInitCmdline(cmdLineArgs)
cfg := config.LoadConfig()
log.Debugf("Cmdline debug = %t", cfg.Rancher.Debug)
if cfg.Rancher.Debug {
log.SetLevel(log.DebugLevel)
} else {
log.SetLevel(log.InfoLevel)
}
return cfg, nil
}},
config.CfgFuncData{"mount OEM", mountOem},
config.CfgFuncData{"debug save cfg", func(_ *config.CloudConfig) (*config.CloudConfig, error) {
PrintConfig()
cfg := config.LoadConfig()
return cfg, nil
}},
config.CfgFuncData{"load modules", loadModules},
config.CfgFuncData{"recovery console", func(cfg *config.CloudConfig) (*config.CloudConfig, error) {
if cfg.Rancher.Recovery {
recovery(nil)
}
return cfg, nil
}},
config.CfgFuncData{"cloud-init", func(cfg *config.CloudConfig) (*config.CloudConfig, error) {
cfg.Rancher.CloudInit.Datasources = config.LoadConfigWithPrefix(state).Rancher.CloudInit.Datasources
hypervisor = util.GetHypervisor()
if hypervisor == "" {
log.Infof("ros init: No Detected Hypervisor")
} else {
log.Infof("ros init: Detected Hypervisor: %s", hypervisor)
}
if hypervisor == "vmware" {
// 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)
}
if err := config.Set("rancher.cloud_init.datasources", cfg.Rancher.CloudInit.Datasources); err != nil {
log.Error(err)
}
log.Infof("init, runCloudInitServices(%v)", cfg.Rancher.CloudInit.Datasources)
if err := runCloudInitServices(cfg); err != nil {
log.Error(err)
}
// It'd be nice to push to rsyslog before this, but we don't have network
log.AddRSyslogHook()
return config.LoadConfig(), nil
}},
config.CfgFuncData{"b2d env", func(cfg *config.CloudConfig) (*config.CloudConfig, error) {
if _, err := os.Stat("/var/lib/boot2docker"); os.IsNotExist(err) {
err := os.Mkdir("/var/lib/boot2docker", 0755)
if err != nil {
log.Errorf("Failed to create boot2docker directory: %v", err)
}
}
if dev := util.ResolveDevice("LABEL=B2D_STATE"); dev != "" {
boot2DockerEnvironment = true
cfg.Rancher.State.Dev = "LABEL=B2D_STATE"
log.Infof("boot2DockerEnvironment %s: %s", cfg.Rancher.State.Dev, dev)
return cfg, nil
}
devices := []string{"/dev/sda", "/dev/vda"}
data := make([]byte, len(boot2DockerMagic))
for _, device := range devices {
f, err := os.Open(device)
if err == nil {
defer f.Close()
_, err = f.Read(data)
if err == nil && string(data) == boot2DockerMagic {
boot2DockerEnvironment = true
cfg.Rancher.State.Dev = "LABEL=B2D_STATE"
cfg.Rancher.State.Autoformat = []string{device}
log.Infof("boot2DockerEnvironment %s: Autoformat %s", cfg.Rancher.State.Dev, cfg.Rancher.State.Autoformat[0])
break
}
}
}
// save here so the bootstrap service can see it (when booting from iso, its very early)
if boot2DockerEnvironment {
if err := config.Set("rancher.state.dev", cfg.Rancher.State.Dev); err != nil {
log.Errorf("Failed to update rancher.state.dev: %v", err)
}
if err := config.Set("rancher.state.autoformat", cfg.Rancher.State.Autoformat); err != nil {
log.Errorf("Failed to update rancher.state.autoformat: %v", err)
}
}
return config.LoadConfig(), nil
}},
config.CfgFuncData{"mount and bootstrap", func(cfg *config.CloudConfig) (*config.CloudConfig, error) {
var err error
cfg, shouldSwitchRoot, err = tryMountAndBootstrap(cfg)
if err != nil {
return nil, err
}
return cfg, nil
}},
config.CfgFuncData{"read cfg and log files", func(cfg *config.CloudConfig) (*config.CloudConfig, error) {
filesToCopy := []string{
config.CloudConfigInitFile,
config.CloudConfigScriptFile,
config.CloudConfigBootFile,
config.CloudConfigNetworkFile,
config.MetaDataFile,
config.EtcResolvConfFile,
}
// 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/"
if files, err := ioutil.ReadDir(bootLog); err == nil {
for _, file := range files {
if !file.IsDir() {
filePath := filepath.Join(bootLog, file.Name())
filesToCopy = append(filesToCopy, filePath)
log.Debugf("Swizzle: Found %s to save", filePath)
}
}
}
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)
log.Debugf("Swizzle: Found %s to save", filePath)
}
}
for _, name := range filesToCopy {
if _, err := os.Lstat(name); !os.IsNotExist(err) {
content, err := ioutil.ReadFile(name)
if err != nil {
log.Errorf("read cfg file (%s) %s", name, err)
continue
}
log.Debugf("Swizzle: Saved %s to memory", name)
configFiles[name] = content
}
}
return cfg, nil
}},
config.CfgFuncData{"switchroot", func(cfg *config.CloudConfig) (*config.CloudConfig, error) {
if !shouldSwitchRoot {
return cfg, nil
}
log.Debugf("Switching to new root at %s %s", state, cfg.Rancher.State.Directory)
if err := switchRoot(state, cfg.Rancher.State.Directory, cfg.Rancher.RmUsr); err != nil {
return cfg, err
}
return cfg, nil
}},
config.CfgFuncData{"mount OEM2", mountOem},
config.CfgFuncData{"write cfg and log files", func(cfg *config.CloudConfig) (*config.CloudConfig, error) {
for name, content := range configFiles {
dirMode := os.ModeDir | 0755
fileMode := os.FileMode(0444)
if strings.HasPrefix(name, "/var/lib/rancher/conf/") {
// only make the conf files harder to get to
dirMode = os.ModeDir | 0700
if name == config.CloudConfigScriptFile {
fileMode = os.FileMode(0755)
} else {
fileMode = os.FileMode(0400)
}
}
if err := os.MkdirAll(filepath.Dir(name), dirMode); err != nil {
log.Error(err)
}
if err := util.WriteFileAtomic(name, content, fileMode); err != nil {
log.Error(err)
}
log.Infof("Swizzle: Wrote file to %s", name)
}
if err := os.MkdirAll(config.VarRancherDir, os.ModeDir|0755); err != nil {
log.Error(err)
}
if err := os.Chmod(config.VarRancherDir, os.ModeDir|0755); err != nil {
log.Error(err)
}
log.FsReady()
log.Debugf("WARNING: switchroot and mount OEM2 phases not written to log file")
return cfg, nil
}},
config.CfgFuncData{"b2d Env", func(cfg *config.CloudConfig) (*config.CloudConfig, error) {
log.Debugf("memory Resolve.conf == [%s]", configFiles["/etc/resolv.conf"])
// this code make sure the open-vm-tools service can be started correct when there is no network
if hypervisor == "vmware" {
// make sure the cache directory exist
if err := os.MkdirAll("/var/lib/rancher/cache/", os.ModeDir|0755); err != nil {
log.Errorf("Create service cache diretory error: %v", err)
}
// move os-services cache file
if _, err := os.Stat("/usr/share/ros/services-cache"); err == nil {
files, err := ioutil.ReadDir("/usr/share/ros/services-cache/")
if err != nil {
log.Errorf("Read file error: %v", err)
}
for _, f := range files {
err := os.Rename("/usr/share/ros/services-cache/"+f.Name(), "/var/lib/rancher/cache/"+f.Name())
if err != nil {
log.Errorf("Rename file error: %v", err)
}
}
if err := os.Remove("/usr/share/ros/services-cache"); err != nil {
log.Errorf("Remove file error: %v", err)
}
}
}
if boot2DockerEnvironment {
if err := config.Set("rancher.state.dev", cfg.Rancher.State.Dev); err != nil {
log.Errorf("Failed to update rancher.state.dev: %v", err)
}
if err := config.Set("rancher.state.autoformat", cfg.Rancher.State.Autoformat); err != nil {
log.Errorf("Failed to update rancher.state.autoformat: %v", err)
}
}
return config.LoadConfig(), nil
}},
config.CfgFuncData{"hypervisor tools", func(cfg *config.CloudConfig) (*config.CloudConfig, error) {
enableHypervisorService(cfg, hypervisor)
return config.LoadConfig(), nil
}},
config.CfgFuncData{"preparefs2", func(cfg *config.CloudConfig) (*config.CloudConfig, error) {
return cfg, dfs.PrepareFs(&mountConfig)
}},
config.CfgFuncData{"load modules2", loadModules},
config.CfgFuncData{"set proxy env", func(cfg *config.CloudConfig) (*config.CloudConfig, error) {
network.SetProxyEnvironmentVariables()
return cfg, nil
}},
config.CfgFuncData{"init SELinux", initializeSelinux},
config.CfgFuncData{"setupSharedRoot", setupSharedRoot},
config.CfgFuncData{"sysinit", sysInit},
}
cfg, err := config.ChainCfgFuncs(nil, initFuncs)
if err != nil {
recovery(err)
}
launchConfig, args := getLaunchConfig(cfg, &cfg.Rancher.SystemDocker)
launchConfig.Fork = !cfg.Rancher.SystemDocker.Exec
//launchConfig.NoLog = true
log.Info("Launching System Docker")
_, err = dfs.LaunchDocker(launchConfig, config.SystemDockerBin, args...)
if err != nil {
log.Errorf("Error Launching System Docker: %s", err)
recovery(err)
return err
}
// Code never gets here - rancher.system_docker.exec=true
return pidOne()
}
func enableHypervisorService(cfg *config.CloudConfig, hypervisorName string) {
if hypervisorName == "" {
return
}
// only enable open-vm-tools for vmware
// these services(xenhvm-vm-tools, kvm-vm-tools, hyperv-vm-tools and bhyve-vm-tools) don't exist yet
serviceName := ""
switch hypervisorName {
case "vmware":
serviceName = "open-vm-tools"
case "hyperv":
serviceName = "hyperv-vm-tools"
default:
log.Infof("no hypervisor matched")
}
if serviceName != "" {
if !cfg.Rancher.HypervisorService {
log.Infof("Skipping %s as `rancher.hypervisor_service` is set to false", serviceName)
return
}
// Check removed - there's an x509 cert failure on first boot of an installed system
// check quickly to see if there is a yml file available
// if service.ValidService(serviceName, cfg) {
log.Infof("Setting rancher.services_include. %s=true", serviceName)
if err := config.Set("rancher.services_include."+serviceName, "true"); err != nil {
log.Error(err)
}
}
}

View File

@ -1,24 +0,0 @@
// +build linux
package init
import (
"os"
"os/signal"
"syscall"
)
func pidOne() error {
c := make(chan os.Signal, 2048)
signal.Notify(c, syscall.SIGCHLD)
for range c {
for {
if pid, err := syscall.Wait4(-1, nil, syscall.WNOHANG, nil); err != nil || pid <= 0 {
break
}
}
}
return nil
}

View File

@ -9,13 +9,13 @@ import (
"github.com/rancher/os/cmd/cloudinitexecute"
"github.com/rancher/os/cmd/cloudinitsave"
"github.com/rancher/os/cmd/control"
osInit "github.com/rancher/os/cmd/init"
"github.com/rancher/os/cmd/network"
"github.com/rancher/os/cmd/power"
"github.com/rancher/os/cmd/respawn"
"github.com/rancher/os/cmd/sysinit"
"github.com/rancher/os/cmd/wait"
"github.com/rancher/os/dfs"
osInit "github.com/rancher/os/init"
"github.com/rancher/os/pkg/dfs"
)
var entrypoints = map[string]func(){

View File

@ -18,10 +18,10 @@ import (
"github.com/docker/libcompose/project/events"
"github.com/docker/libcompose/project/options"
"github.com/rancher/os/config"
rosDocker "github.com/rancher/os/docker"
"github.com/rancher/os/log"
"github.com/rancher/os/util"
"github.com/rancher/os/util/network"
rosDocker "github.com/rancher/os/pkg/docker"
"github.com/rancher/os/pkg/log"
"github.com/rancher/os/pkg/util"
"github.com/rancher/os/pkg/util/network"
)
func CreateService(cfg *config.CloudConfig, name string, serviceConfig *composeConfig.ServiceConfigV1) (project.Service, error) {

View File

@ -7,9 +7,9 @@ import (
composeConfig "github.com/docker/libcompose/config"
"github.com/docker/libcompose/project"
"github.com/rancher/os/config"
"github.com/rancher/os/docker"
"github.com/rancher/os/log"
"github.com/rancher/os/util/network"
"github.com/rancher/os/pkg/docker"
"github.com/rancher/os/pkg/log"
"github.com/rancher/os/pkg/util/network"
)
func LoadService(p *project.Project, cfg *config.CloudConfig, useNetwork bool, service string) error {

View File

@ -11,11 +11,13 @@ import (
"strings"
"syscall"
"github.com/rancher/os/pkg/init/one"
"github.com/docker/libnetwork/resolvconf"
"github.com/rancher/os/log"
"github.com/rancher/os/netconf"
"github.com/rancher/os/selinux"
"github.com/rancher/os/util"
"github.com/rancher/os/pkg/log"
"github.com/rancher/os/pkg/netconf"
"github.com/rancher/os/pkg/selinux"
"github.com/rancher/os/pkg/util"
)
const (
@ -205,7 +207,7 @@ func execDocker(config *Config, docker, cmd string, args []string) (*exec.Cmd, e
return cmd, err
}
if config.PidOne {
PidOne()
one.PidOne()
}
return cmd, err
}

View File

@ -9,7 +9,7 @@ import (
"github.com/docker/engine-api/types"
"github.com/docker/libcompose/docker"
"github.com/rancher/os/config"
"github.com/rancher/os/log"
"github.com/rancher/os/pkg/log"
)
// ConfigAuthLookup will lookup registry auth info from cloud config

View File

@ -10,8 +10,8 @@ import (
composeClient "github.com/docker/libcompose/docker/client"
"github.com/docker/libcompose/project"
"github.com/rancher/os/config"
"github.com/rancher/os/log"
"github.com/rancher/os/util"
"github.com/rancher/os/pkg/log"
"github.com/rancher/os/pkg/util"
)
type ClientFactory struct {

View File

@ -6,7 +6,7 @@ import (
composeConfig "github.com/docker/libcompose/config"
"github.com/rancher/os/config"
"github.com/rancher/os/log"
"github.com/rancher/os/pkg/log"
)
type ConfigEnvironment struct {

View File

@ -10,7 +10,7 @@ import (
"github.com/docker/libcompose/project"
"github.com/docker/libcompose/project/options"
"github.com/rancher/os/config"
"github.com/rancher/os/log"
"github.com/rancher/os/pkg/log"
"golang.org/x/net/context"
)

View File

@ -4,7 +4,7 @@ import (
composeConfig "github.com/docker/libcompose/config"
"github.com/docker/libcompose/docker"
"github.com/docker/libcompose/project"
"github.com/rancher/os/util"
"github.com/rancher/os/pkg/util"
)
type ServiceFactory struct {

81
pkg/init/b2d/b2d.go Normal file
View File

@ -0,0 +1,81 @@
package b2d
import (
"os"
"github.com/rancher/os/config"
"github.com/rancher/os/pkg/init/configfiles"
"github.com/rancher/os/pkg/log"
"github.com/rancher/os/pkg/util"
)
const (
boot2DockerMagic string = "boot2docker, please format-me"
)
var (
boot2DockerEnvironment bool
)
func B2D(cfg *config.CloudConfig) (*config.CloudConfig, error) {
if _, err := os.Stat("/var/lib/boot2docker"); os.IsNotExist(err) {
err := os.Mkdir("/var/lib/boot2docker", 0755)
if err != nil {
log.Errorf("Failed to create boot2docker directory: %v", err)
}
}
if dev := util.ResolveDevice("LABEL=B2D_STATE"); dev != "" {
boot2DockerEnvironment = true
cfg.Rancher.State.Dev = "LABEL=B2D_STATE"
log.Infof("boot2DockerEnvironment %s: %s", cfg.Rancher.State.Dev, dev)
return cfg, nil
}
devices := []string{"/dev/sda", "/dev/vda"}
data := make([]byte, len(boot2DockerMagic))
for _, device := range devices {
f, err := os.Open(device)
if err == nil {
defer f.Close()
_, err = f.Read(data)
if err == nil && string(data) == boot2DockerMagic {
boot2DockerEnvironment = true
cfg.Rancher.State.Dev = "LABEL=B2D_STATE"
cfg.Rancher.State.Autoformat = []string{device}
log.Infof("boot2DockerEnvironment %s: Autoformat %s", cfg.Rancher.State.Dev, cfg.Rancher.State.Autoformat[0])
break
}
}
}
// save here so the bootstrap service can see it (when booting from iso, its very early)
if boot2DockerEnvironment {
if err := config.Set("rancher.state.dev", cfg.Rancher.State.Dev); err != nil {
log.Errorf("Failed to update rancher.state.dev: %v", err)
}
if err := config.Set("rancher.state.autoformat", cfg.Rancher.State.Autoformat); err != nil {
log.Errorf("Failed to update rancher.state.autoformat: %v", err)
}
}
return config.LoadConfig(), nil
}
func Env(cfg *config.CloudConfig) (*config.CloudConfig, error) {
log.Debugf("memory Resolve.conf == [%s]", configfiles.ConfigFiles["/etc/resolv.conf"])
if boot2DockerEnvironment {
if err := config.Set("rancher.state.dev", cfg.Rancher.State.Dev); err != nil {
log.Errorf("Failed to update rancher.state.dev: %v", err)
}
if err := config.Set("rancher.state.autoformat", cfg.Rancher.State.Autoformat); err != nil {
log.Errorf("Failed to update rancher.state.autoformat: %v", err)
}
}
return config.LoadConfig(), nil
}

View File

@ -0,0 +1,39 @@
package bootstrap
import (
"github.com/rancher/os/config"
"github.com/rancher/os/pkg/compose"
"github.com/rancher/os/pkg/init/docker"
"github.com/rancher/os/pkg/log"
"github.com/rancher/os/pkg/sysinit"
"github.com/rancher/os/pkg/util"
)
func bootstrapServices(cfg *config.CloudConfig) (*config.CloudConfig, error) {
if util.ResolveDevice(cfg.Rancher.State.Dev) != "" && len(cfg.Bootcmd) == 0 {
log.Info("NOT Running Bootstrap")
return cfg, nil
}
log.Info("Running Bootstrap")
_, err := compose.RunServiceSet("bootstrap", cfg, cfg.Rancher.BootstrapContainers)
return cfg, err
}
func Bootstrap(cfg *config.CloudConfig) error {
log.Info("Launching Bootstrap Docker")
c, err := docker.Start(cfg)
if err != nil {
return err
}
defer docker.Stop(c)
_, err = config.ChainCfgFuncs(cfg,
[]config.CfgFuncData{
{"bootstrap loadImages", sysinit.LoadBootstrapImages},
{"bootstrap Services", bootstrapServices},
})
return err
}

View File

@ -0,0 +1,60 @@
package cloudinit
import (
"github.com/rancher/os/config"
"github.com/rancher/os/pkg/compose"
"github.com/rancher/os/pkg/init/docker"
"github.com/rancher/os/pkg/log"
"github.com/rancher/os/pkg/sysinit"
"github.com/rancher/os/pkg/util"
)
func CloudInit(cfg *config.CloudConfig) (*config.CloudConfig, error) {
cfg.Rancher.CloudInit.Datasources = config.LoadConfigWithPrefix(config.State).Rancher.CloudInit.Datasources
hypervisor := util.GetHypervisor()
if hypervisor == "" {
log.Infof("ros init: No Detected Hypervisor")
} else {
log.Infof("ros init: Detected Hypervisor: %s", hypervisor)
}
if hypervisor == "vmware" {
// 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)
}
if err := config.Set("rancher.cloud_init.datasources", cfg.Rancher.CloudInit.Datasources); err != nil {
log.Error(err)
}
log.Infof("init, runCloudInitServices(%v)", cfg.Rancher.CloudInit.Datasources)
if err := runCloudInitServices(cfg); err != nil {
log.Error(err)
}
// It'd be nice to push to rsyslog before this, but we don't have network
log.AddRSyslogHook()
return config.LoadConfig(), nil
}
func runCloudInitServices(cfg *config.CloudConfig) error {
c, err := docker.Start(cfg)
if err != nil {
return err
}
defer docker.Stop(c)
_, err = config.ChainCfgFuncs(cfg,
[]config.CfgFuncData{
{"cloudinit loadImages", sysinit.LoadBootstrapImages},
{"cloudinit Services", runCloudInitServiceSet},
})
return err
}
func runCloudInitServiceSet(cfg *config.CloudConfig) (*config.CloudConfig, error) {
log.Info("Running cloud-init services")
_, err := compose.RunServiceSet("cloud-init", cfg, cfg.Rancher.CloudInitServices)
return cfg, err
}

View File

@ -0,0 +1,92 @@
package configfiles
import (
"io/ioutil"
"os"
"path/filepath"
"strings"
"github.com/rancher/os/config"
"github.com/rancher/os/pkg/log"
"github.com/rancher/os/pkg/util"
)
var (
ConfigFiles = map[string][]byte{}
)
func ReadConfigFiles(cfg *config.CloudConfig) (*config.CloudConfig, error) {
filesToCopy := []string{
config.CloudConfigInitFile,
config.CloudConfigScriptFile,
config.CloudConfigBootFile,
config.CloudConfigNetworkFile,
config.MetaDataFile,
config.EtcResolvConfFile,
}
// 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/"
if files, err := ioutil.ReadDir(bootLog); err == nil {
for _, file := range files {
if !file.IsDir() {
filePath := filepath.Join(bootLog, file.Name())
filesToCopy = append(filesToCopy, filePath)
log.Debugf("Swizzle: Found %s to save", filePath)
}
}
}
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)
log.Debugf("Swizzle: Found %s to save", filePath)
}
}
for _, name := range filesToCopy {
if _, err := os.Lstat(name); !os.IsNotExist(err) {
content, err := ioutil.ReadFile(name)
if err != nil {
log.Errorf("read cfg file (%s) %s", name, err)
continue
}
log.Debugf("Swizzle: Saved %s to memory", name)
ConfigFiles[name] = content
}
}
return cfg, nil
}
func WriteConfigFiles(cfg *config.CloudConfig) (*config.CloudConfig, error) {
for name, content := range ConfigFiles {
dirMode := os.ModeDir | 0755
fileMode := os.FileMode(0444)
if strings.HasPrefix(name, "/var/lib/rancher/conf/") {
// only make the conf files harder to get to
dirMode = os.ModeDir | 0700
if name == config.CloudConfigScriptFile {
fileMode = os.FileMode(0755)
} else {
fileMode = os.FileMode(0400)
}
}
if err := os.MkdirAll(filepath.Dir(name), dirMode); err != nil {
log.Error(err)
}
if err := util.WriteFileAtomic(name, content, fileMode); err != nil {
log.Error(err)
}
log.Infof("Swizzle: Wrote file to %s", name)
}
if err := os.MkdirAll(config.VarRancherDir, os.ModeDir|0755); err != nil {
log.Error(err)
}
if err := os.Chmod(config.VarRancherDir, os.ModeDir|0755); err != nil {
log.Error(err)
}
log.FsReady()
log.Debugf("WARNING: switchroot and mount OEM2 phases not written to log file")
return cfg, nil
}

22
pkg/init/debug/debug.go Normal file
View File

@ -0,0 +1,22 @@
package debug
import (
"github.com/rancher/os/config"
"github.com/rancher/os/pkg/log"
)
func PrintAndLoadConfig(_ *config.CloudConfig) (*config.CloudConfig, error) {
PrintConfig()
cfg := config.LoadConfig()
return cfg, nil
}
func PrintConfig() {
cfgString, err := config.Export(false, true)
if err != nil {
log.WithFields(log.Fields{"err": err}).Error("Error serializing config")
} else {
log.Debugf("Config: %s", cfgString)
}
}

53
pkg/init/docker/docker.go Normal file
View File

@ -0,0 +1,53 @@
package docker
import (
"syscall"
"github.com/rancher/os/config"
"github.com/rancher/os/pkg/dfs"
)
func Start(cfg *config.CloudConfig) (chan interface{}, error) {
launchConfig, args := GetLaunchConfig(cfg, &cfg.Rancher.BootstrapDocker)
launchConfig.Fork = true
launchConfig.LogFile = ""
launchConfig.NoLog = true
cmd, err := dfs.LaunchDocker(launchConfig, config.SystemDockerBin, args...)
if err != nil {
return nil, err
}
c := make(chan interface{})
go func() {
<-c
cmd.Process.Signal(syscall.SIGTERM)
cmd.Wait()
c <- struct{}{}
}()
return c, nil
}
func Stop(c chan interface{}) error {
c <- struct{}{}
<-c
return nil
}
func GetLaunchConfig(cfg *config.CloudConfig, dockerCfg *config.DockerConfig) (*dfs.Config, []string) {
var launchConfig dfs.Config
args := dfs.ParseConfig(&launchConfig, dockerCfg.FullArgs()...)
launchConfig.DNSConfig.Nameservers = cfg.Rancher.Defaults.Network.DNS.Nameservers
launchConfig.DNSConfig.Search = cfg.Rancher.Defaults.Network.DNS.Search
launchConfig.Environment = dockerCfg.Environment
if !cfg.Rancher.Debug {
launchConfig.LogFile = config.SystemDockerLog
}
return &launchConfig, args
}

29
pkg/init/env/env.go vendored Normal file
View File

@ -0,0 +1,29 @@
package env
import (
"os"
"github.com/rancher/os/config"
"github.com/rancher/os/pkg/init/fsmount"
"github.com/rancher/os/pkg/log"
"github.com/rancher/os/pkg/util/network"
)
func Init(c *config.CloudConfig) (*config.CloudConfig, error) {
os.Setenv("PATH", "/sbin:/usr/sbin:/usr/bin")
if fsmount.IsInitrd() {
log.Debug("Booting off an in-memory filesystem")
// Magic setting to tell Docker to do switch_root and not pivot_root
os.Setenv("DOCKER_RAMDISK", "true")
} else {
log.Debug("Booting off a persistent filesystem")
}
return c, nil
}
func Proxy(cfg *config.CloudConfig) (*config.CloudConfig, error) {
network.SetProxyEnvironmentVariables()
return cfg, nil
}

105
pkg/init/fsmount/fsmount.go Normal file
View File

@ -0,0 +1,105 @@
package fsmount
import (
"fmt"
"syscall"
"github.com/rancher/os/config"
"github.com/rancher/os/pkg/init/bootstrap"
"github.com/rancher/os/pkg/log"
"github.com/rancher/os/pkg/util"
)
const (
tmpfsMagic int64 = 0x01021994
ramfsMagic int64 = 0x858458f6
)
var (
ShouldSwitchRoot bool
)
func OEM(cfg *config.CloudConfig) (*config.CloudConfig, error) {
if cfg == nil {
cfg = config.LoadConfig()
}
if err := mountConfigured("oem", cfg.Rancher.State.OemDev, cfg.Rancher.State.OemFsType, config.OEM); err != nil {
log.Debugf("Not mounting OEM: %v", err)
} else {
log.Infof("Mounted OEM: %s", cfg.Rancher.State.OemDev)
}
return cfg, nil
}
func mountConfigured(display, dev, fsType, target string) error {
var err error
if dev == "" {
return nil
}
dev = util.ResolveDevice(dev)
if dev == "" {
return fmt.Errorf("Could not resolve device %q", dev)
}
if fsType == "auto" {
fsType, err = util.GetFsType(dev)
}
if err != nil {
return err
}
log.Debugf("FsType has been set to %s", fsType)
log.Infof("Mounting %s device %s to %s", display, dev, target)
return util.Mount(dev, target, fsType, "")
}
func mountState(cfg *config.CloudConfig) error {
return mountConfigured("state", cfg.Rancher.State.Dev, cfg.Rancher.State.FsType, config.State)
}
func tryMountState(cfg *config.CloudConfig) error {
err := mountState(cfg)
if err == nil {
return nil
}
log.Infof("Skipped an error when first mounting: %v", err)
// If we failed to mount lets run bootstrap and try again
if err := bootstrap.Bootstrap(cfg); err != nil {
return err
}
return mountState(cfg)
}
func tryMountAndBootstrap(cfg *config.CloudConfig) (*config.CloudConfig, bool, error) {
if !IsInitrd() || cfg.Rancher.State.Dev == "" {
return cfg, false, nil
}
if err := tryMountState(cfg); !cfg.Rancher.State.Required && err != nil {
return cfg, false, nil
} else if err != nil {
return cfg, false, err
}
return cfg, true, nil
}
func IsInitrd() bool {
var stat syscall.Statfs_t
syscall.Statfs("/", &stat)
return int64(stat.Type) == tmpfsMagic || int64(stat.Type) == ramfsMagic
}
func MountAndBootstrap(cfg *config.CloudConfig) (*config.CloudConfig, error) {
var err error
cfg, ShouldSwitchRoot, err = tryMountAndBootstrap(cfg)
if err != nil {
return nil, err
}
return cfg, nil
}

View File

@ -0,0 +1,80 @@
package hypervisor
import (
"io/ioutil"
"os"
"github.com/rancher/os/config"
"github.com/rancher/os/pkg/log"
"github.com/rancher/os/pkg/util"
)
func Tools(cfg *config.CloudConfig) (*config.CloudConfig, error) {
enableHypervisorService(cfg, util.GetHypervisor())
return config.LoadConfig(), nil
}
func Env(cfg *config.CloudConfig) (*config.CloudConfig, error) {
hypervisor := util.GetHypervisor()
// this code make sure the open-vm-tools service can be started correct when there is no network
if hypervisor == "vmware" {
// make sure the cache directory exist
if err := os.MkdirAll("/var/lib/rancher/cache/", os.ModeDir|0755); err != nil {
log.Errorf("Create service cache diretory error: %v", err)
}
// move os-services cache file
if _, err := os.Stat("/usr/share/ros/services-cache"); err == nil {
files, err := ioutil.ReadDir("/usr/share/ros/services-cache/")
if err != nil {
log.Errorf("Read file error: %v", err)
}
for _, f := range files {
err := os.Rename("/usr/share/ros/services-cache/"+f.Name(), "/var/lib/rancher/cache/"+f.Name())
if err != nil {
log.Errorf("Rename file error: %v", err)
}
}
if err := os.Remove("/usr/share/ros/services-cache"); err != nil {
log.Errorf("Remove file error: %v", err)
}
}
}
return cfg, nil
}
func enableHypervisorService(cfg *config.CloudConfig, hypervisorName string) {
if hypervisorName == "" {
return
}
// only enable open-vm-tools for vmware
// these services(xenhvm-vm-tools, kvm-vm-tools, hyperv-vm-tools and bhyve-vm-tools) don't exist yet
serviceName := ""
switch hypervisorName {
case "vmware":
serviceName = "open-vm-tools"
case "hyperv":
serviceName = "hyperv-vm-tools"
default:
log.Infof("no hypervisor matched")
}
if serviceName != "" {
if !cfg.Rancher.HypervisorService {
log.Infof("Skipping %s as `rancher.hypervisor_service` is set to false", serviceName)
return
}
// Check removed - there's an x509 cert failure on first boot of an installed system
// check quickly to see if there is a yml file available
// if service.ValidService(serviceName, cfg) {
log.Infof("Setting rancher.services_include. %s=true", serviceName)
if err := config.Set("rancher.services_include."+serviceName, "true"); err != nil {
log.Error(err)
}
}
}

View File

@ -0,0 +1,49 @@
package modules
import (
"bufio"
"os"
"os/exec"
"strings"
"github.com/rancher/os/config"
"github.com/rancher/os/pkg/log"
"github.com/rancher/os/pkg/util"
)
func LoadModules(cfg *config.CloudConfig) (*config.CloudConfig, error) {
mounted := map[string]bool{}
f, err := os.Open("/proc/modules")
if err != nil {
return cfg, err
}
defer f.Close()
reader := bufio.NewScanner(f)
for reader.Scan() {
mounted[strings.SplitN(reader.Text(), " ", 2)[0]] = true
}
if util.GetHypervisor() == "hyperv" {
cfg.Rancher.Modules = append(cfg.Rancher.Modules, "hv_utils")
}
for _, module := range cfg.Rancher.Modules {
if mounted[module] {
continue
}
log.Debugf("Loading module %s", module)
// split module and module parameters
cmdParam := strings.SplitN(module, " ", -1)
cmd := exec.Command("modprobe", cmdParam...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
log.Errorf("Could not load module %s, err %v", module, err)
}
}
return cfg, reader.Err()
}

View File

@ -1,6 +1,6 @@
// +build linux
package dfs
package one
import (
"os"

View File

@ -0,0 +1,41 @@
package prepare
import (
"os"
"strings"
"github.com/rancher/os/config"
"github.com/rancher/os/pkg/dfs"
"github.com/rancher/os/pkg/log"
)
var (
mountConfig = dfs.Config{
CgroupHierarchy: map[string]string{
"cpu": "cpu",
"cpuacct": "cpu",
"net_cls": "net_cls",
"net_prio": "net_cls",
},
}
)
func FS(c *config.CloudConfig) (*config.CloudConfig, error) {
return c, dfs.PrepareFs(&mountConfig)
}
func SaveCmdline(c *config.CloudConfig) (*config.CloudConfig, error) {
// the Kernel Patch added for RancherOS passes `--` (only) elided kernel boot params to the init process
cmdLineArgs := strings.Join(os.Args, " ")
config.SaveInitCmdline(cmdLineArgs)
cfg := config.LoadConfig()
log.Debugf("Cmdline debug = %t", cfg.Rancher.Debug)
if cfg.Rancher.Debug {
log.SetLevel(log.DebugLevel)
} else {
log.SetLevel(log.InfoLevel)
}
return cfg, nil
}

View File

@ -1,16 +1,17 @@
package init
package recovery
import (
composeConfig "github.com/docker/libcompose/config"
"github.com/docker/libcompose/yaml"
"github.com/rancher/os/compose"
"github.com/rancher/os/config"
"github.com/rancher/os/log"
"github.com/rancher/os/netconf"
"github.com/rancher/os/pkg/compose"
"github.com/rancher/os/pkg/init/docker"
"github.com/rancher/os/pkg/log"
"github.com/rancher/os/pkg/netconf"
"github.com/rancher/os/pkg/sysinit"
)
var (
// TODO: move this into the os-config file so it can be customised.
recoveryDockerService = composeConfig.ServiceConfigV1{
Image: config.OsBase,
@ -44,14 +45,14 @@ var (
}
)
func recoveryServices(cfg *config.CloudConfig) (*config.CloudConfig, error) {
_, err := compose.RunServiceSet("recovery", cfg, map[string]*composeConfig.ServiceConfigV1{
"recovery": &recoveryDockerService,
})
return nil, err
func LoadRecoveryConsole(cfg *config.CloudConfig) (*config.CloudConfig, error) {
if cfg.Rancher.Recovery {
Recovery(nil)
}
return cfg, nil
}
func recovery(initFailure error) {
func Recovery(initFailure error) {
if initFailure != nil {
log.Errorf("RancherOS has failed to boot: %v", initFailure)
}
@ -80,17 +81,24 @@ func recovery(initFailure error) {
},
}
_, err := startDocker(&recoveryConfig)
_, err := docker.Start(&recoveryConfig)
if err != nil {
log.Fatal(err)
}
_, err = config.ChainCfgFuncs(&recoveryConfig,
[]config.CfgFuncData{
config.CfgFuncData{"loadSystemImages", loadSystemImages},
config.CfgFuncData{"recovery console", recoveryServices},
{"loadSystemImages", sysinit.LoadSystemImages},
{"recovery console", recoveryServices},
})
if err != nil {
log.Fatal(err)
}
}
func recoveryServices(cfg *config.CloudConfig) (*config.CloudConfig, error) {
_, err := compose.RunServiceSet("recovery", cfg, map[string]*composeConfig.ServiceConfigV1{
"recovery": &recoveryDockerService,
})
return nil, err
}

View File

@ -1,15 +1,16 @@
// +build linux
package init
package selinux
import (
"github.com/rancher/os/config"
"github.com/rancher/os/log"
"github.com/rancher/os/selinux"
"io/ioutil"
"github.com/rancher/os/config"
"github.com/rancher/os/pkg/log"
"github.com/rancher/os/pkg/selinux"
)
func initializeSelinux(c *config.CloudConfig) (*config.CloudConfig, error) {
func Initialize(c *config.CloudConfig) (*config.CloudConfig, error) {
ret, _ := selinux.InitializeSelinux()
if ret != 0 {

View File

@ -0,0 +1,32 @@
package sharedroot
import (
"os"
"github.com/docker/docker/pkg/mount"
"github.com/rancher/os/config"
"github.com/rancher/os/pkg/init/fsmount"
)
func Setup(c *config.CloudConfig) (*config.CloudConfig, error) {
if c.Rancher.NoSharedRoot {
return c, nil
}
if fsmount.IsInitrd() {
for _, i := range []string{"/mnt", "/media", "/var/lib/system-docker"} {
if err := os.MkdirAll(i, 0755); err != nil {
return c, err
}
if err := mount.Mount("tmpfs", i, "tmpfs", "rw"); err != nil {
return c, err
}
if err := mount.MakeShared(i); err != nil {
return c, err
}
}
return c, nil
}
return c, mount.MakeShared("/")
}

View File

@ -1,4 +1,4 @@
package init
package switchroot
import (
"fmt"
@ -10,10 +10,22 @@ import (
"github.com/docker/docker/pkg/archive"
"github.com/rancher/os/config"
"github.com/rancher/os/dfs"
"github.com/rancher/os/log"
"github.com/rancher/os/pkg/dfs"
"github.com/rancher/os/pkg/init/fsmount"
"github.com/rancher/os/pkg/log"
)
func SwitchRoot(cfg *config.CloudConfig) (*config.CloudConfig, error) {
if !fsmount.ShouldSwitchRoot {
return cfg, nil
}
log.Debugf("Switching to new root at %s %s", config.State, cfg.Rancher.State.Directory)
if err := switchRoot(config.State, cfg.Rancher.State.Directory, cfg.Rancher.RmUsr); err != nil {
return cfg, err
}
return cfg, nil
}
func cleanupTarget(rootfs, targetUsr, usr, usrVer, tmpDir string) (bool, error) {
log.Debugf("Deleting %s", targetUsr)
if err := os.Remove(targetUsr); err != nil && !os.IsNotExist(err) {

View File

@ -0,0 +1 @@
package switchroot

View File

@ -7,7 +7,7 @@ import (
"strings"
"time"
"github.com/rancher/os/log"
"github.com/rancher/os/pkg/log"
"github.com/vishvananda/netlink"
)

View File

@ -6,7 +6,7 @@ import (
"math/rand"
"net"
"github.com/rancher/os/log"
"github.com/rancher/os/pkg/log"
"github.com/j-keck/arping"
"github.com/vishvananda/netlink"

View File

@ -11,7 +11,7 @@ import (
"syscall"
shlex "github.com/flynn/go-shlex"
"github.com/rancher/os/log"
"github.com/rancher/os/pkg/log"
glob "github.com/ryanuber/go-glob"
"github.com/vishvananda/netlink"

Some files were not shown because too many files have changed in this diff Show More