Skip to content

Commit

Permalink
Do not use (and overwrite) bootlocal.sh to setup mounts anymore
Browse files Browse the repository at this point in the history
Instead, simply prepare and execute the `mount` commands directly with `driver.RunSSHCommandFromDriver()` when `Start()` is called.

When reading https://github.com/boot2docker/boot2docker/blob/master/doc/FAQ.md#local-customisation-with-persistent-partition it appears that the intent of the `bootlocal.sh` script is to be a script created and managed by the user.

Which means that this driver, by overwriting the `bootlocal.sh` script, is going against what has been defined as the way of using this file.

This commit fixes this issue.
  • Loading branch information
huguesalary authored and zchee committed Aug 17, 2017
1 parent 3d48882 commit a2060c0
Showing 1 changed file with 15 additions and 19 deletions.
34 changes: 15 additions & 19 deletions xhyve/xhyve.go
Original file line number Diff line number Diff line change
Expand Up @@ -484,10 +484,6 @@ func (d *Driver) Create() error {
return err
}

if err := d.setupMounts(); err != nil {
return fmt.Errorf("Error setting up mounts: %v", err)
}

return nil
}

Expand Down Expand Up @@ -537,6 +533,10 @@ func (d *Driver) Start() error {
return err
}

if err := d.setupMounts(); err != nil {
return err
}

return nil
}

Expand Down Expand Up @@ -838,6 +838,7 @@ func (d *Driver) setupMounts() error {
err := d.setupNFSShare()
if err != nil {
log.Errorf("NFS setup failed: %s", err.Error())
return err
}
}
return nil
Expand Down Expand Up @@ -992,20 +993,18 @@ func (d *Driver) setupVirt9pShare() error {
if err != nil {
return err
}
bootScriptName := "/var/lib/boot2docker/bootlocal.sh"

bootScript := fmt.Sprintf("#/bin/bash\\n")
mountCommands := fmt.Sprintf("#/bin/bash\\n")
i := 0
for _, virtioShare := range d.Virtio9p {
bootScript = fmt.Sprintf("%s\\n", bootScript)
mountCommands = fmt.Sprintf("%s\\n", mountCommands)
fullMountPath := path.Clean(d.Virtio9pRoot + "/" + virtioShare)
bootScript += fmt.Sprintf("sudo mkdir -p %s\\n", fullMountPath)
bootScript += fmt.Sprintf("sudo mount -t 9p -o version=9p2000 -o trans=virtio -o uname=%s -o dfltuid=$(id -u docker) -o dfltgid=50 -o access=any host-%d %s", user.Username, i, fullMountPath)
mountCommands += fmt.Sprintf("sudo mkdir -p %s\\n", fullMountPath)
mountCommands += fmt.Sprintf("sudo mount -t 9p -o version=9p2000 -o trans=virtio -o uname=%s -o dfltuid=$(id -u docker) -o dfltgid=50 -o access=any host-%d %s", user.Username, i, fullMountPath)
i++
}

writeScriptCmd := fmt.Sprintf("echo -e \"%s\" | sudo tee -a %s && sudo chmod +x %s",
bootScript, bootScriptName, bootScriptName)
writeScriptCmd := fmt.Sprintf("echo -e \"%s\" | sh", mountCommands)

if _, err := drivers.RunSSHCommandFromDriver(d, writeScriptCmd); err != nil {
return err
Expand All @@ -1026,10 +1025,8 @@ func (d *Driver) setupNFSShare() error {
return err
}

bootScriptName := "/var/lib/boot2docker/bootlocal.sh"
bootScript := fmt.Sprintf("#/bin/bash\\n")

bootScript += "sudo /usr/local/etc/init.d/nfs-client start\\n"
mountCommands := fmt.Sprintf("#/bin/bash\\n")
mountCommands += "sudo /usr/local/etc/init.d/nfs-client start\\n"

for _, share := range d.NFSShares {
if !path.IsAbs(share) {
Expand All @@ -1046,16 +1043,15 @@ func (d *Driver) setupNFSShare() error {
}

root := path.Clean(d.NFSSharesRoot)
bootScript += fmt.Sprintf("sudo mkdir -p %s/%s\\n", root, share)
bootScript += fmt.Sprintf("sudo mount -t nfs -o noacl,async %s:%s %s/%s\\n", hostIP, share, root, share)
mountCommands += fmt.Sprintf("sudo mkdir -p %s/%s\\n", root, share)
mountCommands += fmt.Sprintf("sudo mount -t nfs -o noacl,async %s:%s %s/%s\\n", hostIP, share, root, share)
}

if err := nfsexports.ReloadDaemon(); err != nil {
return err
}

writeScriptCmd := fmt.Sprintf("echo -e \"%s\" | sudo tee -a %s && sudo chmod +x %s",
bootScript, bootScriptName, bootScriptName)
writeScriptCmd := fmt.Sprintf("echo -e \"%s\" | sh", mountCommands)

if _, err := drivers.RunSSHCommandFromDriver(d, writeScriptCmd); err != nil {
return err
Expand Down

0 comments on commit a2060c0

Please sign in to comment.