1
0
mirror of https://github.com/rancher/os.git synced 2025-06-24 14:01:34 +00:00

Leave dhcpcd (and netconf) running in the background.

Add wait-for-network.
This commit is contained in:
Ivan Mikushin 2015-11-06 21:53:00 +05:00
parent 4d798edd1b
commit 56b1aa67ac
4 changed files with 61 additions and 5 deletions

View File

@ -3,6 +3,7 @@ package network
import (
"fmt"
"os"
"os/exec"
log "github.com/Sirupsen/logrus"
@ -11,19 +12,36 @@ import (
"github.com/rancher/os/config"
)
const (
NETWORK_DONE = "/var/run/network.done"
WAIT_FOR_NETWORK = "wait-for-network"
)
func sendTerm(proc string) {
cmd := exec.Command("killall", "-TERM", proc)
cmd.Stderr = os.Stderr
cmd.Stdout = os.Stdout
cmd.Run()
}
func Main() {
args := os.Args
if len(args) > 1 {
fmt.Println("call " + args[0] + " to load network config from cloud-config.yml")
return
}
os.Remove(NETWORK_DONE) // ignore error
cfg, err := config.LoadConfig()
if err != nil {
log.Fatal(err)
}
// Purposely ignore error
cloudinit.SetHostname(cfg)
cloudinit.SetHostname(cfg) // ignore error
if err := netconf.ApplyNetworkConfigs(&cfg.Rancher.Network); err != nil {
log.Fatal(err)
}
if _, err := os.Create(NETWORK_DONE); err != nil {
log.Error(err)
}
sendTerm(WAIT_FOR_NETWORK)
select {}
}

View File

@ -0,0 +1,23 @@
package waitfornetwork
import (
"github.com/rancher/os/cmd/network"
"os"
"os/signal"
"syscall"
)
func handleTerm() {
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGTERM)
<-c
os.Exit(0)
}
func Main() {
go handleTerm()
if _, err := os.Stat(network.NETWORK_DONE); err == nil {
os.Exit(0)
}
select {}
}

View File

@ -16,6 +16,7 @@ import (
"github.com/rancher/os/cmd/systemdocker"
"github.com/rancher/os/cmd/userdocker"
"github.com/rancher/os/cmd/wait"
"github.com/rancher/os/cmd/waitfornetwork"
"github.com/rancher/os/config"
osInit "github.com/rancher/os/init"
)
@ -53,6 +54,7 @@ func main() {
registerCmd("/usr/sbin/ros", control.Main)
registerCmd("/usr/bin/cloud-init", cloudinit.Main)
registerCmd("/usr/sbin/netconf", network.Main)
registerCmd("/usr/sbin/wait-for-network", waitfornetwork.Main)
registerCmd("/usr/sbin/wait-for-docker", wait.Main)
if !reexec.Init() {

View File

@ -89,7 +89,7 @@ rancher:
io.rancher.os.detach: false
io.rancher.os.reloadconfig: true
io.rancher.os.scope: system
io.rancher.os.after: cloud-init-pre,network
io.rancher.os.after: cloud-init-pre, wait-for-network
net: host
uts: host
privileged: true
@ -124,6 +124,7 @@ rancher:
- /usr/bin/docker:/usr/bin/docker.dist:ro
- /usr/bin/ros:/sbin/halt:ro
- /usr/bin/ros:/sbin/netconf:ro
- /usr/bin/ros:/sbin/wait-for-network:ro
- /usr/bin/ros:/sbin/poweroff:ro
- /usr/bin/ros:/sbin/reboot:ro
- /usr/bin/ros:/sbin/shutdown:ro
@ -166,11 +167,23 @@ rancher:
network:
image: rancher/os-network:v0.4.1-dev
labels:
io.rancher.os.detach: false
io.rancher.os.scope: system
io.rancher.os.after: cloud-init-pre
net: host
uts: host
pid: host
privileged: true
volumes_from:
- command-volumes
- system-volumes
wait-for-network:
image: rancher/os-network:v0.4.1-dev
command: wait-for-network
labels:
io.rancher.os.detach: false
io.rancher.os.scope: system
io.rancher.os.after: network
pid: host
privileged: true
volumes_from:
- command-volumes
@ -179,7 +192,7 @@ rancher:
image: rancher/os-ntp:v0.4.1-dev
labels:
io.rancher.os.scope: system
io.rancher.os.after: cloud-init, network
io.rancher.os.after: cloud-init, wait-for-network
net: host
uts: host
privileged: true