Skip to content

Do not disconnect from coder_app after command #7931

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jaulz opened this issue Jun 9, 2023 · 12 comments
Closed

Do not disconnect from coder_app after command #7931

jaulz opened this issue Jun 9, 2023 · 12 comments
Labels
stale This issue is like stale bread.

Comments

@jaulz
Copy link

jaulz commented Jun 9, 2023

It would be great if the coder apps do not disconnect automatically after they return. To ensure compatibility it would of course be fine to have a parameter (e.g. tty=true?) to control it. My use case is that I want to list the log files in the database via:

resource "coder_app" "postgres" {
  agent_id = coder_agent.postgres.id
  display_name     = "Logs"
  command  = "ls /var/lib/postgresql/data/log/"
  icon     = "https://iconarchive.com/download/i83612/pelfusion/flat-file-type/log.ico"
  slug     = "postgres-logs"
}

Unfortunately, once opened it immediately says "Disconnected" and I cannot even view the result but actually I would like to use it as a starting point to run further commands.

@cdr-bot cdr-bot bot added the feature label Jun 9, 2023
@kylecarbs
Copy link
Member

You could do this with ls /var/lib/postgresql/data/log/ && $SHELL I believe!

@matifali
Copy link
Member

Any success @jaulz. Please update if you were able to make it work.

@matifali matifali added waiting-for-info The issue creator is asked to provide more information. and removed feature labels Jun 11, 2023
@jaulz
Copy link
Author

jaulz commented Jun 12, 2023

@kylecarbs thanks a lot for the tip, that worked great! 😊 The only minor issue is that it still displays this warning which can be misleading:
image

@jaulz
Copy link
Author

jaulz commented Jun 12, 2023

And while we are here, I have another use case where I just want to print the content of a file:


cat $(mkcert -CAROOT)/rootCA.pem

The $SHELL trick works fine here but I wonder if a file explorer also makes sense at some point to download files directly from the web interface 😊

@matifali
Copy link
Member

matifali commented Jun 12, 2023

And while we are here, I have another use case where I just want to print the content of a file:


cat $(mkcert -CAROOT)/rootCA.pem

The $SHELL trick works fine here but I wonder if a file explorer also makes sense at some point to download files directly from the web interface 😊

you could give https://filebrowser.org/ a try by creating a coder_app for this.
A live example.

@matifali matifali added feature and removed waiting-for-info The issue creator is asked to provide more information. labels Jun 12, 2023
@jaulz
Copy link
Author

jaulz commented Jun 12, 2023

@matifali perfect, that works as well. Thanks! 😊 So it's now just about the screenshot that I posted above...

@matifali
Copy link
Member

@kylecarbs thanks a lot for the tip, that worked great! 😊 The only minor issue is that it still displays this warning which can be misleading: image

@mafredri and @BrunoQuaresma is this an expected behaviour?

@BrunoQuaresma
Copy link
Collaborator

Yes, this warning will be displayed until the startup script is done.

@matifali
Copy link
Member

matifali commented Jun 12, 2023

@jaulz can you please confirm if your startup_script has finished? We have some nice docs on how to make sure that a startup_script ends positively.

@jaulz
Copy link
Author

jaulz commented Jun 13, 2023

Actually, I think the startup script should finish because I use the init script of the agent in the container. It has a custom startup script but that uses & to run the default entrypoint in the background:

resource "docker_network" "internal" {
  name = "${data.coder_parameter.namespace.value}"
}

resource "coder_agent" "postgres" {
  arch           = data.coder_provisioner.me.arch
  os             = "linux"
  startup_script = <<EOT
#!/bin/bash

cd / 

exec /usr/local/bin/entrypoint.sh postgres &

EOT
}

resource "docker_container" "postgres" {
  count    = data.coder_workspace.me.start_count
  image    = docker_image.postgres.image_id
  # Uses lower() to avoid Docker restriction on container names.
  name     = "${data.coder_parameter.namespace.value}-${data.coder_workspace.me.owner}-${lower(data.coder_workspace.me.name)}-postgres"
  hostname = "postgres"
  dns      = ["1.1.1.1"]
  # Use the docker gateway if the access URL is 127.0.0.1
  entrypoint = ["sh", "-c", replace(coder_agent.postgres.init_script, "127.0.0.1", "host.docker.internal")]
  command  = ["postgres"]
  env      = [
    "CODER_AGENT_TOKEN=${coder_agent.postgres.token}",
    "POSTGRES_PASSWORD=${var.postgres_password}"
  ]
  host {
    host = "host.docker.internal"
    ip   = "host-gateway"
  }
  volumes {
    container_path = "/var/lib/postgresql/data"
    volume_name    = docker_volume.postgres_data.name
    read_only      = false
  }
  networks_advanced {
    name = docker_network.internal.name
  }
  restart = "unless-stopped"
}

@BrunoQuaresma
Copy link
Collaborator

Maybe the process is still open. This warning is only displayed when the startup script is running. Just checking with @mafredri

@mafredri
Copy link
Member

@jaulz It's possible it won't exit even though it seems like it should, see about redirecting stdout and stderr here: https://coder.com/docs/v2/latest/templates#startup_script

@github-actions github-actions bot added the stale This issue is like stale bread. label Dec 11, 2023
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Dec 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale This issue is like stale bread.
Projects
None yet
Development

No branches or pull requests

5 participants