Skip to content

Commit 8c289e5

Browse files
committed
Write startup script logs to fs dir
1 parent fbb1bdb commit 8c289e5

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

agent/agent.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,11 @@ func (a *agent) runStartupScript(ctx context.Context, script string) error {
376376
}
377377

378378
a.logger.Info(ctx, "running startup script", slog.F("script", script))
379-
writer, err := os.OpenFile(filepath.Join(os.TempDir(), "coder-startup-script.log"), os.O_CREATE|os.O_RDWR, 0o600)
379+
tempDir, err := afero.TempDir(a.filesystem, "", "")
380+
if err != nil {
381+
return xerrors.Errorf("create temp dir: %w", err)
382+
}
383+
writer, err := a.filesystem.OpenFile(filepath.Join(tempDir, "coder-startup-script.log"), os.O_CREATE|os.O_RDWR, 0o600)
380384
if err != nil {
381385
return xerrors.Errorf("open startup script log file: %w", err)
382386
}

agent/agent_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,7 @@ func setupAgent(t *testing.T, metadata codersdk.WorkspaceAgentMetadata, ptyTimeo
681681
statsChan: statsCh,
682682
coordinator: coordinator,
683683
},
684+
Filesystem: afero.NewMemMapFs(),
684685
Logger: slogtest.Make(t, nil).Leveled(slog.LevelDebug),
685686
ReconnectingPTYTimeout: ptyTimeout,
686687
})

0 commit comments

Comments
 (0)