You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
for the full list of supported arguments for the `coder_agent`.
147
147
148
-
#### startup_script
148
+
#### `startup_script`
149
149
150
150
Use the Coder agent's `startup_script` to run additional commands like
151
151
installing IDEs, [cloning dotfiles](../dotfiles.md#templates), and cloning
152
152
project repos.
153
153
154
+
**Note:** By default, the startup script is executed in the background allowing users to access the workspace before the script completes. If you want to change this, see `startup_script_behavior` below.
We recommend that startup scripts always have an end, meaning that long running
194
+
processes should be run in the background. This is usually achieved by adding
195
+
`&` to the end of the command. For example, `sleep 10 &` will run the command in
196
+
the background and allow the startup script to complete.
197
+
198
+
If a backgrounded command (`&`) writes to stdout or stderr, the startup script
199
+
will not complete until the command completes or closes the file descriptors.
200
+
To avoid this, you can redirect the stdout and stderr to a file. For example,
201
+
`sleep 10 >/dev/null 2>&1 &` will redirect the stdout and stderr to `/dev/null`
202
+
(discard) and run the command in the background.
203
+
204
+
PS. Notice how each step starts with `echo "..."` to provide feedback to the user
205
+
about what is happening? This is especially useful when the startup script
206
+
behavior is set to blocking because the user will be informed about why they're
207
+
waiting to access their workspace.
208
+
209
+
#### `startup_script_behavior`
210
+
211
+
Use the Coder agent's `startup_script_behavior` to change the behavior between
212
+
`blocking` and `non-blocking` (default). The blocking behavior is recommended
213
+
for most use cases because it allows the startup script to complete before the
214
+
user accesses the workspace. For example, let's say you want to check out a very
215
+
large repo in the startup script. If the startup script is non-blocking, the
216
+
user may log in via SSH or open the IDE before the repo is fully checked out.
217
+
This can lead to a poor user experience.
218
+
219
+
Whichever behavior is enabled, the user can still choose to override it by
220
+
specifying the appropriate flags (or environment variables) in the CLI when
221
+
connecting to the workspace. For example, `coder ssh --no-wait` will connect to
222
+
the workspace without waiting for the startup script to complete.
223
+
224
+
```hcl
225
+
resource "coder_agent" "coder" {
226
+
os = "linux"
227
+
arch = "amd64"
228
+
startup_script_behavior = "blocking"
229
+
startup_script = "echo 'Starting...'"
230
+
```
231
+
187
232
### Start/stop
188
233
189
234
[Learn about resource persistence in Coder](./resource-persistence.md)
@@ -372,6 +417,18 @@ practices:
372
417
- The Coder agent shutdown script logs are typically stored in `/tmp/coder-shutdown-script.log`
373
418
- This can also happen if the websockets are not being forwarded correctly when running Coder behind a reverse proxy. [Read our reverse-proxy docs](https://coder.com/docs/v2/latest/admin/configure#tls--reverse-proxy)
374
419
420
+
### Startup script in progress, incomplete workspace
421
+
422
+
WIP
423
+
424
+
### Startup script in progress, session before completion
425
+
426
+
WIP
427
+
428
+
### Startup script error
429
+
430
+
WIP
431
+
375
432
### Agent does not become ready
376
433
377
434
If the agent does not become ready, it means the [startup script](https://registry.terraform.io/providers/coder/coder/latest/docs/resources/agent#startup_script) is still running or has exited with a non-zero status. This also means the [login before ready](https://registry.terraform.io/providers/coder/coder/latest/docs/resources/agent#login_before_ready) option hasn't been set to true.
0 commit comments