# How to show allocated host+port in Info card?

**URL:** <https://discourse.openondemand.org/t/how-to-show-allocated-host-port-in-info-card/3390>\
**Category:** Get Help\
**Tags:** ondemand2\
**Created:** [March 29, 2024, 6:07pm UTC](https://discourse.openondemand.org/t/how-to-show-allocated-host-port-in-info-card/3390 "2024-03-29T18:07:00Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![npavlovikj](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/npavlovikj/32/890_2.png) [@npavlovikj](https://discourse.openondemand.org/u/npavlovikj)\
**Post date:** [March 29, 2024, 6:07pm UTC](https://discourse.openondemand.org/t/how-to-show-allocated-host-port-in-info-card/3390/1 "2024-03-29T18:07:00Z")

</div>

Hi,

We have Open OnDemand App that when launched opens web browser in a Desktop with `host+port` URL generated when the job starts.  
We want to have this URL available in the Info card, so researchers can reopen the URL if they close the browser in the App.

When the App starts, the `Host` name is shown in the Info card.  
However, I haven’t been able to add the `port` to the Info card, nor access the `Host` information after it is generated.

I do export the `port` in `before.sh.erb` and define it as `conn_params` in `submit.yml.erb`, but I am not able to access these values in `info.html.erb`.

We use VNC template for this App, so we can not have `view.html.erb`.

Can you please let me know how I can achieve this and have the dynamic URL as part of the Info card?

We have Open OnDemand 2.0.32 on our cluster.  
Please let me know if you need any additional information.

Thank you,  
Natasha

---

<div class="post-metadata">

**Author:** ![jeff.ohrstrom](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/jeff.ohrstrom/32/136_2.png) [@jeff.ohrstrom](https://discourse.openondemand.org/u/jeff.ohrstrom)\
**Post date:** [March 29, 2024, 6:38pm UTC](https://discourse.openondemand.org/t/how-to-show-allocated-host-port-in-info-card/3390/2 "2024-03-29T18:38:25Z")

</div>

> [@npavlovikj](#):
>
> I do export the `port` in `before.sh.erb` and define it as `conn_params` in `submit.yml.erb`, but I am not able to access these values in `info.html.erb`.

I was able to get this to run by using the `connect` API. Here’s what I did.

```auto
# made it here!
<p><%= connect.host %></p>
<p><%= connect.port %></p>

```

However, that said, I think you likely want to define a new thing like `app_port` and use _it_ as `port` is special to us and it is the port that noVNC connects to.

So you set and export the variable in `before.sh.erb`

```auto
export app_port=$(find_port)

```

Add it to the `conn_params` and you should be able to reference it through `connect.app_port`.

---

<div class="post-metadata">

**Author:** ![jeff.ohrstrom](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/jeff.ohrstrom/32/136_2.png) [@jeff.ohrstrom](https://discourse.openondemand.org/u/jeff.ohrstrom)\
**Post date:** [March 29, 2024, 6:42pm UTC](https://discourse.openondemand.org/t/how-to-show-allocated-host-port-in-info-card/3390/3 "2024-03-29T18:42:04Z")

</div>

Though I shoul note that you’ll see something like this when the app hasn’t started yet, which is normal - there’s no file to read yet so it throws this error. It will display the error until the job is actually running and has written the connection.yml.

 ![image](https://us1.discourse-cdn.com/flex015/uploads/osc/original/2X/4/46baf067a98a491186d12763ce4c7bb02825d377.png)  
d

---

<div class="post-metadata">

**Author:** ![npavlovikj](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/npavlovikj/32/890_2.png) [@npavlovikj](https://discourse.openondemand.org/u/npavlovikj)\
**Post date:** [March 29, 2024, 6:50pm UTC](https://discourse.openondemand.org/t/how-to-show-allocated-host-port-in-info-card/3390/4 "2024-03-29T18:50:42Z")

</div>

Thank you for the prompt reply Jeff!

I actually got that error, so I was gonna ask you about it 🙂

Is there a way to bypass the error, have a dummy empty `connection.yml` file or have it delayed with `after.sh.erb` maybe ?  
I am worried that researchers using the App won’t know that that Error message can be ignored.

Thank you,  
Natasha

---

<div class="post-metadata">

**Author:** ![jeff.ohrstrom](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/jeff.ohrstrom/32/136_2.png) [@jeff.ohrstrom](https://discourse.openondemand.org/u/jeff.ohrstrom)\
**Post date:** [March 29, 2024, 6:55pm UTC](https://discourse.openondemand.org/t/how-to-show-allocated-host-port-in-info-card/3390/5 "2024-03-29T18:55:32Z")

</div>

> [@npavlovikj](#):
>
> Is there a way to bypass the error, have a dummy empty `connection.yml` file or have it delayed with `after.sh.erb` maybe ?

I might have said no - but your idea for a dummy empty connection.yml will do just the trick.

Do this in your app’s root directory and when the job launches it’ll see this empty erb file, render it (well, try to, it’s empty) and place the empty connection.yml in the right location. The job will overwrite it when it does it’s thing.

```auto
touch template/connection.yml.erb

```

---

<div class="post-metadata">

**Author:** ![npavlovikj](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/npavlovikj/32/890_2.png) [@npavlovikj](https://discourse.openondemand.org/u/npavlovikj)\
**Post date:** [March 29, 2024, 7:11pm UTC](https://discourse.openondemand.org/t/how-to-show-allocated-host-port-in-info-card/3390/6 "2024-03-29T19:11:06Z")

</div>

Thank you Jeff!

The empty `connection.yml.erb` file worked regarding the error from above.

However, that caused a different issue for me.  
The App starts a server that takes a while to start, so I have:

```auto
timeout 30
echo "Waiting for Server to open port ${app_port}..."

```

in `after.sh.erb` such that the `Launch App` button appears after the server starts (otherwise it shows black screen when the button is clicked and that may cause another confusion for researchers using the App).

By adding the empty connection file, the `Launch App` button is shown before the App server is started which is causing the same issue I had before adding `timeout` in `after.sh.erb`.

Is there a way for me to have these two separate things solved at the same time, or I can only have one at the time?

Thank you,  
Natasha

---

<div class="post-metadata">

**Author:** ![jeff.ohrstrom](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/jeff.ohrstrom/32/136_2.png) [@jeff.ohrstrom](https://discourse.openondemand.org/u/jeff.ohrstrom)\
**Post date:** [March 29, 2024, 7:19pm UTC](https://discourse.openondemand.org/t/how-to-show-allocated-host-port-in-info-card/3390/7 "2024-03-29T19:19:53Z")

</div>

> [@npavlovikj](#):
>
> Is there a way for me to have these two separate things solved at the same time, or I can only have one at the time?

🤦‍♂️ Sorry, no I don’t think so.

---

<div class="post-metadata">

**Author:** ![jeff.ohrstrom](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/jeff.ohrstrom/32/136_2.png) [@jeff.ohrstrom](https://discourse.openondemand.org/u/jeff.ohrstrom)\
**Post date:** [March 29, 2024, 7:21pm UTC](https://discourse.openondemand.org/t/how-to-show-allocated-host-port-in-info-card/3390/8 "2024-03-29T19:21:32Z")

</div>

Well actually, maybe in the `info.html.erb` you can check for the file first. So you provide an if block to check for the file and if its’ there, then you render `connect.app_port`.

```erb
if File.exist?()
  show the port
end

```

---

<div class="post-metadata">

**Author:** ![npavlovikj](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/npavlovikj/32/890_2.png) [@npavlovikj](https://discourse.openondemand.org/u/npavlovikj)\
**Post date:** [March 29, 2024, 7:52pm UTC](https://discourse.openondemand.org/t/how-to-show-allocated-host-port-in-info-card/3390/9 "2024-03-29T19:52:33Z")

</div>

Jeff, thank you, thank you, so much!

Checking for the `connection.yml` File in `info.html.erb` did exactly what I wanted - the `host` and `port` are shown in the Info card after the session starts, and the `Launch App` button is shown when the server starts as well.

Thank you always for the prompt and great support!

Thank you,  
Natasha

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex015/uploads/osc/original/2X/b/bae70bd0ed39a3ae769c2108155f4cb3e9da8385.png) [@system](https://discourse.openondemand.org/u/system)\
**Post date:** [September 25, 2024, 7:53pm UTC](https://discourse.openondemand.org/t/how-to-show-allocated-host-port-in-info-card/3390/10 "2024-09-25T19:53:35Z")

</div>

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
