mirror of
https://github.com/rancher/os.git
synced 2025-06-26 23:06:51 +00:00
Leave dhcpcd (and netconf) running in the background.
Add wait-for-network.
This commit is contained in:
parent
4d798edd1b
commit
56b1aa67ac
@ -3,6 +3,7 @@ package network
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
|
||||||
log "github.com/Sirupsen/logrus"
|
log "github.com/Sirupsen/logrus"
|
||||||
|
|
||||||
@ -11,19 +12,36 @@ import (
|
|||||||
"github.com/rancher/os/config"
|
"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() {
|
func Main() {
|
||||||
args := os.Args
|
args := os.Args
|
||||||
if len(args) > 1 {
|
if len(args) > 1 {
|
||||||
fmt.Println("call " + args[0] + " to load network config from cloud-config.yml")
|
fmt.Println("call " + args[0] + " to load network config from cloud-config.yml")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
os.Remove(NETWORK_DONE) // ignore error
|
||||||
cfg, err := config.LoadConfig()
|
cfg, err := config.LoadConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
// Purposely ignore error
|
cloudinit.SetHostname(cfg) // ignore error
|
||||||
cloudinit.SetHostname(cfg)
|
|
||||||
if err := netconf.ApplyNetworkConfigs(&cfg.Rancher.Network); err != nil {
|
if err := netconf.ApplyNetworkConfigs(&cfg.Rancher.Network); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
if _, err := os.Create(NETWORK_DONE); err != nil {
|
||||||
|
log.Error(err)
|
||||||
|
}
|
||||||
|
sendTerm(WAIT_FOR_NETWORK)
|
||||||
|
select {}
|
||||||
}
|
}
|
||||||
|
23
cmd/waitfornetwork/waitfornetwork.go
Normal file
23
cmd/waitfornetwork/waitfornetwork.go
Normal 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 {}
|
||||||
|
}
|
2
main.go
2
main.go
@ -16,6 +16,7 @@ import (
|
|||||||
"github.com/rancher/os/cmd/systemdocker"
|
"github.com/rancher/os/cmd/systemdocker"
|
||||||
"github.com/rancher/os/cmd/userdocker"
|
"github.com/rancher/os/cmd/userdocker"
|
||||||
"github.com/rancher/os/cmd/wait"
|
"github.com/rancher/os/cmd/wait"
|
||||||
|
"github.com/rancher/os/cmd/waitfornetwork"
|
||||||
"github.com/rancher/os/config"
|
"github.com/rancher/os/config"
|
||||||
osInit "github.com/rancher/os/init"
|
osInit "github.com/rancher/os/init"
|
||||||
)
|
)
|
||||||
@ -53,6 +54,7 @@ func main() {
|
|||||||
registerCmd("/usr/sbin/ros", control.Main)
|
registerCmd("/usr/sbin/ros", control.Main)
|
||||||
registerCmd("/usr/bin/cloud-init", cloudinit.Main)
|
registerCmd("/usr/bin/cloud-init", cloudinit.Main)
|
||||||
registerCmd("/usr/sbin/netconf", network.Main)
|
registerCmd("/usr/sbin/netconf", network.Main)
|
||||||
|
registerCmd("/usr/sbin/wait-for-network", waitfornetwork.Main)
|
||||||
registerCmd("/usr/sbin/wait-for-docker", wait.Main)
|
registerCmd("/usr/sbin/wait-for-docker", wait.Main)
|
||||||
|
|
||||||
if !reexec.Init() {
|
if !reexec.Init() {
|
||||||
|
@ -89,7 +89,7 @@ rancher:
|
|||||||
io.rancher.os.detach: false
|
io.rancher.os.detach: false
|
||||||
io.rancher.os.reloadconfig: true
|
io.rancher.os.reloadconfig: true
|
||||||
io.rancher.os.scope: system
|
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
|
net: host
|
||||||
uts: host
|
uts: host
|
||||||
privileged: true
|
privileged: true
|
||||||
@ -124,6 +124,7 @@ rancher:
|
|||||||
- /usr/bin/docker:/usr/bin/docker.dist:ro
|
- /usr/bin/docker:/usr/bin/docker.dist:ro
|
||||||
- /usr/bin/ros:/sbin/halt:ro
|
- /usr/bin/ros:/sbin/halt:ro
|
||||||
- /usr/bin/ros:/sbin/netconf: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/poweroff:ro
|
||||||
- /usr/bin/ros:/sbin/reboot:ro
|
- /usr/bin/ros:/sbin/reboot:ro
|
||||||
- /usr/bin/ros:/sbin/shutdown:ro
|
- /usr/bin/ros:/sbin/shutdown:ro
|
||||||
@ -166,11 +167,23 @@ rancher:
|
|||||||
network:
|
network:
|
||||||
image: rancher/os-network:v0.4.1-dev
|
image: rancher/os-network:v0.4.1-dev
|
||||||
labels:
|
labels:
|
||||||
io.rancher.os.detach: false
|
|
||||||
io.rancher.os.scope: system
|
io.rancher.os.scope: system
|
||||||
io.rancher.os.after: cloud-init-pre
|
io.rancher.os.after: cloud-init-pre
|
||||||
net: host
|
net: host
|
||||||
uts: 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
|
privileged: true
|
||||||
volumes_from:
|
volumes_from:
|
||||||
- command-volumes
|
- command-volumes
|
||||||
@ -179,7 +192,7 @@ rancher:
|
|||||||
image: rancher/os-ntp:v0.4.1-dev
|
image: rancher/os-ntp:v0.4.1-dev
|
||||||
labels:
|
labels:
|
||||||
io.rancher.os.scope: system
|
io.rancher.os.scope: system
|
||||||
io.rancher.os.after: cloud-init, network
|
io.rancher.os.after: cloud-init, wait-for-network
|
||||||
net: host
|
net: host
|
||||||
uts: host
|
uts: host
|
||||||
privileged: true
|
privileged: true
|
||||||
|
Loading…
Reference in New Issue
Block a user