# Check if port is open, but don't end job

**URL:** <https://discourse.openondemand.org/t/check-if-port-is-open-but-dont-end-job/4345>\
**Category:** Get Help\
**Created:** [July 9, 2025, 1:40am UTC](https://discourse.openondemand.org/t/check-if-port-is-open-but-dont-end-job/4345 "2025-07-09T01:40:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kstine](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/kstine/32/2539_2.png) [@kstine](https://discourse.openondemand.org/u/kstine)\
**Post date:** [July 9, 2025, 1:40am UTC](https://discourse.openondemand.org/t/check-if-port-is-open-but-dont-end-job/4345/1 "2025-07-09T01:40:41Z")

</div>

I have the following `after.sh.erb` script that I’m trying to adapt for an application:

```auto
# Wait for server to start
echo "Waiting for server to open port ${port}..."
if wait_until_port_used "${host}:${port}" 240; then
  echo "Discovered server listening on port ${port}!"
else
  # Copy TOPPATH and MASTERPATH variables
  TOPPATH="/raid/$SLURM_JOB_USER.$SLURM_JOB_ID/topdir"
  MASTERPATH=$TOPCSPATH/master
  echo "Timed out waiting for server to open port ${port}!"
  # Clean up sockets
  $MASTERPATH/bin/stop
  wait 90
  pkill -P ${SCRIPT_PID}
  clean_up 1
fi
sleep 2

```

The issue I’m having is that it’s immediately ending the session once the `script.sh.erb` finishes.

In the output.log, I get:

```auto
<install output>
Generating connection YAML file...
Cleaning up...

```

After which it immediately ends the job. The `script.sh.erb` ends cleanly at the end of it and there’s no way (as script is only running the installer, not the application itself) for it to be kept in the foreground. The port is still open on the machine, but I think OOD isn’t seeing that. Is there some way to keep OOD open and connected once the port comes up?

---

<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:** [July 9, 2025, 1:30pm UTC](https://discourse.openondemand.org/t/check-if-port-is-open-but-dont-end-job/4345/2 "2025-07-09T13:30:28Z")

</div>

> [@kstine](#):
>
> The `script.sh.erb` ends cleanly at the end of it and there’s no way (as script is only running the installer, not the application itself) for it to be kept in the foreground.

You need to keep it in the foreground. Here’s an example of how to do that below.

> <https://github.com/OSC/bc_osc_stata/blob/master/template/script.sh.erb#L53-L60>

---

<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:** [January 5, 2026, 1:31pm UTC](https://discourse.openondemand.org/t/check-if-port-is-open-but-dont-end-job/4345/3 "2026-01-05T13:31:20Z")

</div>

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