@@ -313,9 +313,10 @@ func (a *agent) run(ctx context.Context) error {
313
313
}
314
314
}
315
315
316
+ lifecycleState := codersdk .WorkspaceAgentLifecycleReady
316
317
scriptDone := make (chan error , 1 )
317
318
scriptStart := time .Now ()
318
- err : = a .trackConnGoroutine (func () {
319
+ err = a .trackConnGoroutine (func () {
319
320
defer close (scriptDone )
320
321
scriptDone <- a .runStartupScript (ctx , metadata .StartupScript )
321
322
})
@@ -343,15 +344,16 @@ func (a *agent) run(ctx context.Context) error {
343
344
if errors .Is (err , context .Canceled ) {
344
345
return
345
346
}
346
- execTime := time .Since (scriptStart )
347
- lifecycleState := codersdk .WorkspaceAgentLifecycleReady
348
- if err != nil {
349
- a .logger .Warn (ctx , "startup script failed" , slog .F ("execution_time" , execTime ), slog .Error (err ))
350
- lifecycleState = codersdk .WorkspaceAgentLifecycleStartError
351
- } else {
352
- a .logger .Info (ctx , "startup script completed" , slog .F ("execution_time" , execTime ))
347
+ // Only log if there was a startup script.
348
+ if metadata .StartupScript != "" {
349
+ execTime := time .Since (scriptStart )
350
+ if err != nil {
351
+ a .logger .Warn (ctx , "startup script failed" , slog .F ("execution_time" , execTime ), slog .Error (err ))
352
+ lifecycleState = codersdk .WorkspaceAgentLifecycleStartError
353
+ } else {
354
+ a .logger .Info (ctx , "startup script completed" , slog .F ("execution_time" , execTime ))
355
+ }
353
356
}
354
-
355
357
a .setLifecycle (ctx , lifecycleState )
356
358
}()
357
359
}
@@ -1325,7 +1327,7 @@ func (a *agent) Close() error {
1325
1327
// TODO(mafredri): Only run shutdown script if the agent is 'ready'?
1326
1328
1327
1329
lifecycleState := codersdk .WorkspaceAgentLifecycleOff
1328
- if metadata , ok := a .metadata .Load ().(agentsdk.Metadata ); ok {
1330
+ if metadata , ok := a .metadata .Load ().(agentsdk.Metadata ); ok && metadata . ShutdownScript != "" {
1329
1331
scriptDone := make (chan error , 1 )
1330
1332
scriptStart := time .Now ()
1331
1333
go func () {
0 commit comments