fix(boot)

This commit is contained in:
Mikaël Cluseau
2019-03-13 16:01:34 +11:00
parent 71d9c52a99
commit 6d5caeb71f
579 changed files with 123 additions and 200073 deletions

View File

@ -19,20 +19,14 @@ func Command() (c *cobra.Command) {
Run: run,
}
c.Flags().BoolVar(&doNetwork, "do-network", true, "setup network")
return
}
func run(c *cobra.Command, args []string) {
setupFiles()
setupModules()
if doNetwork {
setupNetworking()
}
setupLVM()
step("files", setupFiles)
step("modules", setupModules)
step("network", setupNetworking)
step("lvm", setupLVM)
}
func setupModules() {

View File

@ -2,6 +2,7 @@ package initboot
import (
"bytes"
"fmt"
"log"
"net"
"os"
@ -21,7 +22,7 @@ var networkStarted = map[string]bool{}
func setupNetworking() {
cfg := sys.Config()
for idx, network := range cfg.Networks {
setupNetwork(idx, network)
step(fmt.Sprintf("network:%d", idx), func() { setupNetwork(idx, network) })
}
}

View File

@ -0,0 +1,48 @@
package initboot
import (
"encoding/json"
"io/ioutil"
"log"
"os"
)
var stateFile = "/run/dkl-boot.state"
func readState() (state map[string]bool) {
state = map[string]bool{}
ba, err := ioutil.ReadFile(stateFile)
if err != nil {
if os.IsNotExist(err) {
return
}
log.Fatal("failed to read state: ", err)
}
err = json.Unmarshal(ba, &state)
if err != nil {
log.Fatal("failed to parse state: ", err)
}
return
}
func writeState(state map[string]bool) {
ba, err := json.Marshal(state)
if err != nil {
log.Fatal("failed to serialize state: ", err)
}
ioutil.WriteFile(stateFile, ba, 0600)
}
func step(step string, operation func()) {
state := readState()
if !state[step] {
operation()
state[step] = true
writeState(state)
}
}