@@ -295,9 +295,10 @@ func (a *agent) run(ctx context.Context) error {
295
295
}
296
296
}
297
297
298
+ lifecycleState := codersdk .WorkspaceAgentLifecycleReady
298
299
scriptDone := make (chan error , 1 )
299
300
scriptStart := time .Now ()
300
- err : = a .trackConnGoroutine (func () {
301
+ err = a .trackConnGoroutine (func () {
301
302
defer close (scriptDone )
302
303
scriptDone <- a .runStartupScript (ctx , metadata .StartupScript )
303
304
})
@@ -325,15 +326,16 @@ func (a *agent) run(ctx context.Context) error {
325
326
if errors .Is (err , context .Canceled ) {
326
327
return
327
328
}
328
- execTime := time .Since (scriptStart )
329
- lifecycleState := codersdk .WorkspaceAgentLifecycleReady
330
- if err != nil {
331
- a .logger .Warn (ctx , "startup script failed" , slog .F ("execution_time" , execTime ), slog .Error (err ))
332
- lifecycleState = codersdk .WorkspaceAgentLifecycleStartError
333
- } else {
334
- a .logger .Info (ctx , "startup script completed" , slog .F ("execution_time" , execTime ))
329
+ // Only log if there was a startup script.
330
+ if metadata .StartupScript != "" {
331
+ execTime := time .Since (scriptStart )
332
+ if err != nil {
333
+ a .logger .Warn (ctx , "startup script failed" , slog .F ("execution_time" , execTime ), slog .Error (err ))
334
+ lifecycleState = codersdk .WorkspaceAgentLifecycleStartError
335
+ } else {
336
+ a .logger .Info (ctx , "startup script completed" , slog .F ("execution_time" , execTime ))
337
+ }
335
338
}
336
-
337
339
a .setLifecycle (ctx , lifecycleState )
338
340
}()
339
341
}
@@ -1230,7 +1232,7 @@ func (a *agent) Close() error {
1230
1232
// TODO(mafredri): Only run shutdown script if the agent is 'ready'?
1231
1233
1232
1234
lifecycleState := codersdk .WorkspaceAgentLifecycleOff
1233
- if metadata , ok := a .metadata .Load ().(agentsdk.Metadata ); ok {
1235
+ if metadata , ok := a .metadata .Load ().(agentsdk.Metadata ); ok && metadata . ShutdownScript != "" {
1234
1236
scriptDone := make (chan error , 1 )
1235
1237
scriptStart := time .Now ()
1236
1238
go func () {
0 commit comments