>_ IzzyLab

Hands-on task

This task is step 16 of the course “Processes and signals”

The old instance didn't give up the port

medium~10 min

A new version of the API was rolled out, but it won't come up: port 80 is still held by the old instance someone forgot to stop. Find the process on that port, stop it, and start the new version from /opt/api/run.sh in the background so that it survives the terminal being closed. You're done when http://localhost:80/ answers API v2. The Site tab above the terminal shows who's answering on port 80 right now: for now it's API v1.

What you'll practise:
  • ss -p
  • finding a process by port
  • kill
  • background start
  • setsid

Topic breakdown

A port in the LISTEN state belongs to one socket, and while an old process holds it, a new one gets Address already in use. ss with process display shows who holds it: next to the address there's the name and pid=…. Then comes a signal: first SIGTERM, so the process exits cleanly, and only if it doesn't react — SIGKILL. The new version is started detached from the terminal (setsid or nohup with input and output redirected), otherwise it dies together with the session it was started from.

What's checked

  1. the new version answers on 80
  2. the old instance is stopped

What it looks like