fix(boot)
This commit is contained in:
@ -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() {
|
||||
|
@ -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) })
|
||||
}
|
||||
}
|
||||
|
||||
|
48
pkg/cmd/init/boot/state.go
Normal file
48
pkg/cmd/init/boot/state.go
Normal 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)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user