Skip to content
This repository has been archived by the owner on Dec 4, 2020. It is now read-only.

Commit

Permalink
Fix a slew of issues when doing boot-strap updating and in particular
Browse files Browse the repository at this point in the history
when using an offline update file. Also make sure we only mdconfig the
filename single time
  • Loading branch information
kmoore134 committed Dec 10, 2018
1 parent c3ffd3f commit 3b95ece
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 8 deletions.
51 changes: 43 additions & 8 deletions doupdate.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ func doupdate(message []byte) {
//
// Skip if the disablebsflag is set
if ( details.SysUp && disablebsflag != true) {
logtofile("Performing bootstrap")
dosysupbootstrap()
dopassthroughupdate()
return
Expand Down Expand Up @@ -154,7 +155,21 @@ func dopassthroughupdate() {
wsflag = "-addr=127.0.0.1:8135"

// Start the newly updated sysup binary, passing along our previous flags
cmd := exec.Command("sysup", wsflag, "-update", fuflag, upflag, beflag, ukeyflag)
//upflags := fuflag + " " + upflag + " " + beflag + " " + ukeyflag
cmd := exec.Command("sysup", wsflag, "-update")
if ( fuflag != "" ) {
cmd.Args = append(cmd.Args, fuflag)
}
if ( upflag != "" ) {
cmd.Args = append(cmd.Args, upflag)
}
if ( beflag != "" ) {
cmd.Args = append(cmd.Args, beflag)
}
if ( ukeyflag != "" ) {
cmd.Args = append(cmd.Args, ukeyflag)
}
logtofile("Running bootstrap with flags: " + strings.Join(cmd.Args, " "))
stdout, err := cmd.StdoutPipe()
if err != nil {
log.Fatal(err)
Expand All @@ -172,18 +187,21 @@ func dopassthroughupdate() {
if err := cmd.Wait(); err != nil {
sendfatalmsg("Failed update!")
}

// Let our local clients know they can finish up
sendshutdownmsg("")
}

func doupdatefileumnt() {
func doupdatefileumnt(prefix string) {
if ( updatefileflag == "" ) {
return
}

logtofile("Unmount nullfs")
cmd := exec.Command("umount", "-f", STAGEDIR + localimgmnt)
cmd := exec.Command("umount", "-f", prefix + localimgmnt)
err := cmd.Run()
if ( err != nil ) {
log.Println("WARNING: Failed to umount " + STAGEDIR + localimgmnt)
log.Println("WARNING: Failed to umount " + prefix + localimgmnt)
}
}

Expand All @@ -199,14 +217,13 @@ func doupdatefilemnt() {
if ( err != nil ) {
log.Fatal(err)
}
logtofile("Nullfs mounted at: " + localimgmnt)
}

// When we have a new version of sysup to upgrade to, we perform
// that update first, and then continue with the regular update
func dosysupbootstrap() {

doupdatefilemnt()

// Start by updating the sysup PKG
sendinfomsg("Starting Sysup boot-strap")
logtofile("SysUp Stage 1\n-----------------------")
Expand Down Expand Up @@ -235,10 +252,26 @@ func dosysupbootstrap() {
if err := cmd.Wait(); err != nil {
sendfatalmsg("Failed sysup update!")
}

cmd = exec.Command("rm", "-rf", "/var/db/pkg")
err = cmd.Run()
if ( err != nil ) {
log.Fatal(err)
}

// Copy over the existing local database
srcDir := localpkgdb
destDir := "/var/db/pkg"
cpCmd := exec.Command("mv", srcDir, destDir)
err = cpCmd.Run()
if ( err != nil ) {
log.Fatal(err)
}

sendinfomsg("Finished stage 1 Sysup boot-strap")
logtofile("FinishedSysUp Stage 1\n-----------------------")

doupdatefileumnt()
doupdatefileumnt("")
}

func cleanupbe() {
Expand Down Expand Up @@ -452,7 +485,7 @@ func startupgrade(twostage bool) {
}

// Cleanup nullfs mount
doupdatefileumnt()
doupdatefileumnt(STAGEDIR)

// Unmount the devfs point
cmd := exec.Command("umount", "-f", STAGEDIR + "/dev")
Expand Down Expand Up @@ -675,6 +708,7 @@ func startfetch() error {

func haveosverchange() bool {
// Check the host OS version
logtofile("Checking OS version")
OSINT, oerr := syscall.SysctlUint32("kern.osreldate")
if ( oerr != nil ) {
log.Fatal(oerr)
Expand All @@ -685,6 +719,7 @@ func haveosverchange() bool {
}

OSVER := fmt.Sprint(OSINT)
logtofile("OS Version: " + OSVER + " -> " + REMOTEVER)
if ( OSVER != REMOTEVER ) {
sendinfomsg("Remote ABI change detected: " +OSVER+ " -> " + REMOTEVER )
logtofile("Remote ABI change detected: " +OSVER+ " -> " + REMOTEVER )
Expand Down
11 changes: 11 additions & 0 deletions pkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,21 @@ func getremoteosver() (string, error) {
}

func mountofflineupdate() {

// If offline update is already mounted, return
if ( localmddev != "" ) {
logtofile("Using already mounted: " + updatefileflag)
return
}

if _, err := os.Stat(updatefileflag) ; os.IsNotExist(err) {
sendfatalmsg("ERROR: Offline update file " + updatefileflag + " does not exist!")
closews()
os.Exit(1)
}

logtofile("Mounting offline update: " + updatefileflag)

output, cmderr := exec.Command("mdconfig", "-a", "-t", "vnode", "-f", updatefileflag).Output()
if ( cmderr != nil ) {
exitcleanup(cmderr, "Failed mdconfig of offline update file: " + updatefileflag)
Expand All @@ -80,6 +89,7 @@ func mountofflineupdate() {
cmd := exec.Command("mdconfig", "-d", "-u", localmddev)
cmd.Run()
sendfatalmsg("ERROR: Offline update file " + updatefileflag + " cannot be mounted")
localmddev=""
closews()
os.Exit(1)
}
Expand All @@ -93,6 +103,7 @@ func destroymddev() {
cmd.Run()
cmd = exec.Command("mdconfig", "-d", "-u", localmddev)
cmd.Run()
localmddev=""
}

func mkreposfile(prefix string, pkgdb string) string {
Expand Down

0 comments on commit 3b95ece

Please sign in to comment.