Skip to content

Commit 5c690de

Browse files
committed
wsl2: attempt to fix dos2unix and quotation issues
The script was failing prior to this commit ``` time="2023-09-28T17:18:46Z" level=info msg="[hostagent] Driver stopped due to error: \"error running wslCommand that executes boot.sh: exit status 127, check /var/log/lima-init.log for more details (out=\\\"bash: line 1: $'\\\\\\\\r': command not found\\\\n\\\")\"" ``` Signed-off-by: Akihiro Suda <[email protected]>
1 parent 27772e4 commit 5c690de

File tree

3 files changed

+35
-11
lines changed

3 files changed

+35
-11
lines changed

.github/workflows/test.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@ jobs:
106106
run: |
107107
.\_output\bin\limactl.exe start template://experimental/wsl2
108108
# TODO: run the full integration tests
109+
- name: Debug
110+
if: always()
111+
run: type C:\Users\runneradmin\.lima\wsl2\ha.stdout.log
112+
- name: Debug
113+
if: always()
114+
run: type C:\Users\runneradmin\.lima\wsl2\ha.stderr.log
109115
- name: Unit tests
110116
run: go test -v ./...
111117

pkg/wsl2/lima-init.TEMPLATE

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
set -eu; \
2-
export LOG_FILE=/var/log/lima-init.log; \
3-
exec > >(tee \$LOG_FILE) 2>&1; \
4-
export LIMA_CIDATA_MNT="$(/usr/bin/wslpath '{{.CIDataPath}}')"; \
5-
exec "\$LIMA_CIDATA_MNT/boot.sh";
1+
#!/bin/bash
2+
set -eu
3+
export LOG_FILE=/var/log/lima-init.log
4+
exec > >(tee $LOG_FILE) 2>&1
5+
export LIMA_CIDATA_MNT="$(/usr/bin/wslpath '{{.CIDataPath}}')"
6+
exec "$LIMA_CIDATA_MNT/boot.sh"

pkg/wsl2/vm_windows.go

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import (
77
"context"
88
_ "embed"
99
"fmt"
10+
"os"
1011
"os/exec"
1112
"path/filepath"
12-
"strings"
1313

1414
"github.com/lima-vm/lima/pkg/executil"
1515
"github.com/lima-vm/lima/pkg/store"
@@ -73,11 +73,27 @@ func provisionVM(ctx context.Context, instanceDir, instanceName, distroName stri
7373
m := map[string]string{
7474
"CIDataPath": ciDataPath,
7575
}
76-
out, err := textutil.ExecuteTemplate(limaBoot, m)
76+
limaBootB, err := textutil.ExecuteTemplate(limaBoot, m)
7777
if err != nil {
7878
return fmt.Errorf("failed to construct wsl boot.sh script: %w", err)
7979
}
80-
outString := strings.Replace(string(out), `\r\n`, `\n`, -1)
80+
limaBootFile, err := os.CreateTemp("", "lima-wsl2-boot-*.sh")
81+
if err != nil {
82+
return err
83+
}
84+
if _, err = limaBootFile.Write(limaBootB); err != nil {
85+
return err
86+
}
87+
limaBootFilePathOnWindows := limaBootFile.Name()
88+
if err = limaBootFile.Close(); err != nil {
89+
return err
90+
}
91+
defer os.RemoveAll(limaBootFilePathOnWindows)
92+
limaBootFilePathOnLinuxB, err := exec.Command("wsl.exe", "wslpath", "-u", limaBootFilePathOnWindows).Output()
93+
if err != nil {
94+
return err
95+
}
96+
limaBootFilePathOnLinux := string(limaBootFilePathOnLinuxB)
8197

8298
go func() {
8399
cmd := exec.CommandContext(
@@ -86,10 +102,11 @@ func provisionVM(ctx context.Context, instanceDir, instanceName, distroName stri
86102
"-d",
87103
distroName,
88104
"bash",
89-
"-c",
90-
outString,
105+
limaBootFilePathOnLinux,
91106
)
92-
if out, err := cmd.CombinedOutput(); err != nil {
107+
out, err := cmd.CombinedOutput()
108+
logrus.Infof("%v: %q", cmd.Args, string(out))
109+
if err != nil {
93110
*errCh <- fmt.Errorf(
94111
"error running wslCommand that executes boot.sh (%v): %w, "+
95112
"check /var/log/lima-init.log for more details (out=%q)", cmd.Args, err, string(out))

0 commit comments

Comments
 (0)