Domain 7Web & Application LayerCORE

(Bergen) Resolving TCP Port Binding Conflicts: Reconfiguring Systemd Services and Nginx Proxies

A comprehensive deep dive into diagnosing TCP socket binding collisions (EADDRINUSE), reconfiguring systemd-managed web applications, and updating Nginx reverse proxy directives to maintain zero service downtime.

Domain: Domain 7: Web & Application Layer•Updated: 2026-11-11
#systemd#nginx#networking#troubleshooting#SadServers#SRE

1. Introduction

In modern Linux infrastructure and Site Reliability Engineering (SRE), network socket collisions are among the most common causes of service startup failures. Because standard TCP/IP networking rules allow only one socket to listen on a specific IP address and port combination at any given time, launching an application that relies on an occupied port triggers a kernel-level EADDRINUSE (Address already in use) error.

In production environments, port binding conflicts frequently occur when:

  • A new service version attempts to launch before an existing daemon releases its socket.
  • Microservices or development servers are deployed with hardcoded port configurations.
  • Reverse proxies (such as Nginx or HAProxy) forward incoming requests to static upstream ports that conflict with host-level binaries.

This article documents a real-world system administration scenario—the “Bergen: Port already in use” exercise from SadServers. It provides a step-by-step breakdown of how to diagnose port collisions, trace systemd process dependencies, update Nginx reverse proxy directives, and verify multi-service system health without interrupting existing web traffic.


2. Problem Description and Environment

Scenario Overview

The scenario presents a target server containing a compiled standalone binary located at /home/admin/standalone. The binary fails to launch due to an environmental conflict.

Scenario: "Bergen": Port already in use
Level: Easy
Type: Fix
Tags: systemd, nginx, realistic-interviews
Access: Email / SSH
Root (sudo) Access: True

Problem Statement & Constraints

  • Objective: Fix the environment so /home/admin/standalone can execute and print OK.
  • Constraint 1: Do not modify or patch the /home/admin/standalone binary file itself.
  • Constraint 2: Do not break or disrupt the existing web application served on port 80.
  • Verification Test: Executing /home/admin/standalone must output OK, and running curl http://localhost:80 must return hello SadServers.

System Environment

  • Operating System: Linux (Debian/Ubuntu-based systemd environment).
  • User Context: admin with full sudo root privileges.
  • Active Web Infrastructure: Nginx web server listening on port 80, proxying requests to a Django backend application.

3. Initial Investigation and Hypotheses

Before modifying system configurations, a systematic investigation is necessary to establish baseline metrics and avoid service downtime.

Initial Observations

  1. Attempting to execute ./standalone produces the following output: listen tcp4 0.0.0.0:8000: bind: address already in use.
  2. Executing curl http://localhost:80 successfully returns hello SadServers.

Investigative Questions

  • Which process is currently bound to TCP port 8000?
  • Is the process on port 8000 an unmanaged process or a systemd-managed service?
  • How is Nginx configured on port 80, and is port 8000 configured as an upstream proxy dependency?

Hypothesis Matrix

Hypothesis Supporting Evidence Evidence Against Diagnostic Step
H1: Port 8000 is occupied by an unmanaged orphan process. ./standalone outputs bind: address already in use on 0.0.0.0:8000. curl http://localhost:80 returns valid HTTP content, suggesting a functional stack. Inspect sockets with ss -tulpn.
H2: Port 8000 is used by a Django app serving as the upstream backend for Nginx. Nginx serves hello SadServers on port 80; Django app directory exists in /home/admin/django_app. None yet. Inspect process tree with ps and Nginx site definitions under /etc/nginx/.
H3: The process on port 8000 is managed by a systemd service auto-restart loop. standard Linux daemon setup. Unconfirmed until systemd status is checked. Query systemd with systemctl status.

4. Troubleshooting Process

The investigation followed a chronological, evidence-driven path to identify process ownership, map proxy dependencies, and apply remediation.

+-----------------------------------------------------------------------------------+
| Step 1: Replicate Failure & Identify Socket Owner                                 |
| `./standalone` -> Port 8000 bound | `ss -tulpn` -> PID 913 (python3)              |
+-----------------------------------------------------------------------------------+
                                         |
                                         v
+-----------------------------------------------------------------------------------+
| Step 2: Trace Process Hierarchy & Systemd Unit                                    |
| `ps -fp 913` -> Django runserver 8000 | `systemctl cat django.service`           |
+-----------------------------------------------------------------------------------+
                                         |
                                         v
+-----------------------------------------------------------------------------------+
| Step 3: Inspect Nginx Reverse Proxy Dependencies                                  |
| `cat /etc/nginx/sites-enabled/*` -> proxy_pass http://127.0.0.1:8000              |
+-----------------------------------------------------------------------------------+
                                         |
                                         v
+-----------------------------------------------------------------------------------+
| Step 4: Attempt 1 & Pitfall (502 Bad Gateway)                                     |
| Moved Django to 8001 | Edited sites-available/default instead of sites-enabled  |
+-----------------------------------------------------------------------------------+
                                         |
                                         v
+-----------------------------------------------------------------------------------+
| Step 5: Remediate Active Nginx Config & Reload                                     |
| Updated `/etc/nginx/sites-enabled/bergen` to 8001 | `nginx -t` & `systemctl reload`|
+-----------------------------------------------------------------------------------+
                                         |
                                         v
+-----------------------------------------------------------------------------------+
| Step 6: Final Verification & Validation                                           |
| `./standalone` -> OK | `curl http://localhost:80` -> hello SadServers             |
+-----------------------------------------------------------------------------------+

Step 1: Replicate Failure and Identify Socket Owner

Objective

Replicate the execution failure of /home/admin/standalone and identify the exact Process ID (PID) holding TCP port 8000 open.

Commands Executed

/home/admin/standalone
sudo ss -tulpn
curl -i http://localhost:80

Command Explanation

  • ss -tulpn: Queries socket statistics (-t TCP, -u UDP, -l Listening, -p Process name/PID, -n Numeric ports).
  • curl -i: Performs an HTTP request and prints response headers along with the body.

Output and Analysis

admin@i-07691e4a45b3cd971:~$ ./standalone
listen tcp4 0.0.0.0:8000: bind: address already in use

admin@i-07691e4a45b3cd971:~$ ss -tulpn
Netid State  Recv-Q Send-Q Local Address:Port  Peer Address:Port Process                           
tcp   LISTEN 0      10           0.0.0.0:8000       0.0.0.0:*    users:(("python3",pid=913,fd=4))
tcp   LISTEN 0      511          0.0.0.0:80         0.0.0.0:*    users:(("nginx",pid=756,fd=6))  

admin@i-07691e4a45b3cd971:~$ curl -i http://localhost:80
HTTP/1.1 200 OK
Server: nginx
Content-Type: text/html; charset=utf-8

hello SadServers

Decision

  • The ./standalone binary fails because it attempts to bind specifically to 0.0.0.0:8000.
  • PID 913 (python3) is currently bound to port 8000.
  • Port 80 is handled by Nginx and returns hello SadServers.
  • Next step: Inspect PID 913 to determine its invocation parameters and process parentage.

Step 2: Trace Process Hierarchy and Systemd Unit Definition

Objective

Determine how PID 913 was started and whether it is managed by systemd.

Commands Executed

ps -fp 913
systemctl status 913
systemctl cat django.service

Output and Analysis

admin@i-07691e4a45b3cd971:~$ ps -fp 913
UID        PID  PPID  C STIME TTY          TIME CMD
admin      913   753  0 14:25 ?        00:00:00 /usr/bin/python3 manage.py runserver 0.0.0.0:8000

admin@i-07691e4a45b3cd971:~$ systemctl status 913
● django.service - Django Hello SadServers (dev runserver)
     Loaded: loaded (/etc/systemd/system/django.service; enabled; preset: enabled)
     Active: active (running) since Wed 2026-11-11 14:25:19 UTC; 3min 16s ago
   Main PID: 753 (python3)
     CGroup: /system.slice/django.service
             ├─753 /usr/bin/python3 manage.py runserver 0.0.0.0:8000
             └─913 /usr/bin/python3 manage.py runserver 0.0.0.0:8000

admin@i-07691e4a45b3cd971:~$ systemctl cat django.service
# /etc/systemd/system/django.service
[Unit]
Description=Django Hello SadServers (dev runserver)
After=network.target

[Service]
Type=simple
User=admin
Group=admin
WorkingDirectory=/home/admin/django_app
ExecStart=/usr/bin/python3 manage.py runserver 0.0.0.0:8000
Restart=on-failure
RestartSec=2

[Install]
WantedBy=multi-user.target

Decision

  • Process 913 is a child process of PID 753, spawned by django.service running Django’s development server (manage.py runserver 0.0.0.0:8000).
  • Terminating PID 913 directly via kill -9 will fail to resolve the problem because systemd has Restart=on-failure configured and will instantly spawn a new instance on port 8000.
  • To free port 8000 safely, django.service must be reconfigured to bind to a different port (e.g., port 8001).

Step 3: Inspect Nginx Reverse Proxy Dependencies

Objective

Inspect Nginx’s virtual host configuration to determine how requests on port 80 are routed to the backend Django process.

Commands Executed

cat /etc/nginx/sites-enabled/*

Output and Analysis

server {
    listen 80 default_server;
    listen [::]:80 default_server;
    server_name _;

    location / {
        proxy_pass http://127.0.0.1:8000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

Decision

  • Nginx listens on port 80 and uses proxy_pass [http://127.0.0.1:8000](http://127.0.0.1:8000); to forward incoming HTTP requests to Django.
  • If django.service is moved to port 8001, Nginx’s proxy_pass directive must be updated to [http://127.0.0.1:8001](http://127.0.0.1:8001); simultaneously. Otherwise, Nginx will attempt to connect to port 8000 and return 502 Bad Gateway to clients.

Step 4: Attempt 1 and Pitfall Analysis (502 Bad Gateway)

Objective

Reconfigure django.service to port 8001, update Nginx, and test both endpoints.

Commands Executed

sudo sed -i 's/0.0.0.0:8000/0.0.0.0:8001/' /etc/systemd/system/django.service
sudo sed -i 's/127.0.0.1:8000/127.0.0.1:8001/' /etc/nginx/sites-available/default
sudo systemctl daemon-reload
sudo systemctl restart django.service
sudo systemctl reload nginx
sudo ss -tulpn | grep -E ":8000|:8001"
curl -i http://localhost:80
/home/admin/standalone

Output and Analysis

admin@i-07691e4a45b3cd971:~$ sudo ss -tulpn | grep -E ":8000|:8001"
tcp   LISTEN 0      10           0.0.0.0:8001       0.0.0.0:*    users:(("python3",pid=1109,fd=4))

admin@i-07691e4a45b3cd971:~$ curl -i http://localhost:80
HTTP/1.1 502 Bad Gateway
Server: nginx
Content-Type: text/html

<html>
<head><title>502 Bad Gateway</title></head> ...

admin@i-07691e4a45b3cd971:~$ ./standalone
OK

Diagnostic Pitfall Breakdown

  1. What Succeeded: django.service successfully moved to port 8001, freeing TCP port 8000. As a result, /home/admin/standalone executed and output OK.
  2. What Failed: curl http://localhost:80 returned 502 Bad Gateway.
  3. Why it Failed: The second sed command targeted /etc/nginx/sites-available/default. However, inspecting /etc/nginx/sites-enabled/ revealed that the active site configuration was named /etc/nginx/sites-enabled/bergen. Because bergen was an independent file copy rather than a symbolic link to sites-available/default, editing sites-available/default left the active Nginx config pointing to port 8000.

Step 5: Remediate Active Nginx Configuration and Reload

Objective

Update the active configuration file /etc/nginx/sites-enabled/bergen, validate syntax, and reload Nginx.

Commands Executed

cat /etc/nginx/sites-enabled/bergen
sudo vim /etc/nginx/sites-enabled/bergen
sudo systemctl daemon-reload
sudo systemctl restart django
sudo nginx -t
sudo systemctl reload nginx

Output and Analysis

admin@i-07691e4a45b3cd971:~$ cat /etc/nginx/sites-enabled/bergen
server {
    listen 80 default_server;
    listen [::]:80 default_server;
    server_name _;

    location / {
        proxy_pass http://127.0.0.1:8000;
...

[Updated /etc/nginx/sites-enabled/bergen via editor to proxy_pass http://127.0.0.1:8001;]

admin@i-07691e4a45b3cd971:~$ sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

admin@i-07691e4a45b3cd971:~$ sudo systemctl reload nginx

Step 6: Final Verification

Objective

Verify that both constraints of the scenario are satisfied and execute the challenge verification agent.

Commands Executed

curl http://localhost:80
./standalone
agent/check.sh

Output and Analysis

admin@i-07691e4a45b3cd971:~$ curl http://localhost:80
hello SadServers

admin@i-07691e4a45b3cd971:~$ ./standalone
OK

admin@i-07691e4a45b3cd971:~$ agent/check.sh
OK

5. Root Cause Analysis

Detailed Explanation of Failure

The system failure was caused by a **TCP port collision on 0.0.0.0:8000**.

When the standalone binary /home/admin/standalone was executed, it made a socket() and bind() system call targeting IPv4 address 0.0.0.0 on TCP port 8000. The Linux kernel inspected its internal socket hash tables and determined that socket 0.0.0.0:8000 was already allocated to file descriptor 4 of Process ID 913 (python3). Consequently, the kernel rejected the bind() request and returned error code EADDRINUSE.

+-----------------------------------------------------------------------------------+
| System Startup State                                                              |
| 1. systemd starts `django.service` -> binds 0.0.0.0:8000                          |
| 2. nginx starts -> listens on 0.0.0.0:80, proxies to 127.0.0.1:8000              |
+-----------------------------------------------------------------------------------+
                                         |
                                         v
+-----------------------------------------------------------------------------------+
| Execution Failure                                                                 |
| User runs `./standalone` -> attempts `bind(0.0.0.0:8000)`                         |
| Kernel returns `EADDRINUSE` -> `./standalone` exits with error                    |
+-----------------------------------------------------------------------------------+
                                         |
                                         v
+-----------------------------------------------------------------------------------+
| Remediated Architecture                                                           |
| 1. `django.service` reconfigured -> binds 0.0.0.0:8001                            |
| 2. Nginx `/etc/nginx/sites-enabled/bergen` updated -> proxy_pass 127.0.0.1:8001 |
| 3. `./standalone` executes -> successfully binds 0.0.0.0:8000 and prints OK       |
+-----------------------------------------------------------------------------------+

6. Solution and Remediation

To resolve the conflict while maintaining zero service disruption on port 80:

1. Systemd Service Unit Update

Modify /etc/systemd/system/django.service to update the listening port argument from 8000 to 8001:

# /etc/systemd/system/django.service
[Unit]
Description=Django Hello SadServers (dev runserver)
After=network.target

[Service]
Type=simple
User=admin
Group=admin
WorkingDirectory=/home/admin/django_app
- ExecStart=/usr/bin/python3 manage.py runserver 0.0.0.0:8000
+ ExecStart=/usr/bin/python3 manage.py runserver 0.0.0.0:8001
Restart=on-failure
RestartSec=2

[Install]
WantedBy=multi-user.target

2. Active Nginx Site Configuration Update

Modify /etc/nginx/sites-enabled/bergen to point the upstream proxy_pass directive to port 8001:

# /etc/nginx/sites-enabled/bergen
server {
    listen 80 default_server;
    listen [::]:80 default_server;
    server_name _;

    location / {
-       proxy_pass http://127.0.0.1:8000;
+       proxy_pass http://127.0.0.1:8001;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

3. Reload Daemons and Restart Services

Execute service management commands to apply configuration changes:

sudo systemctl daemon-reload
sudo systemctl restart django
sudo nginx -t
sudo systemctl reload nginx

7. Verification and Validation

Verification confirms that both requirements are fully satisfied and persistent:

Verification Step Command Expected Result Actual Result Status
Backend Port Shift `sudo ss -tulpn grep :8001` python3 listening on 0.0.0.0:8001 tcp LISTEN 0 10 0.0.0.0:8001 ... pid=1109
Port 80 Web App curl -i http://localhost:80 HTTP/1.1 200 OK with hello SadServers hello SadServers PASS
Standalone Binary /home/admin/standalone OK OK PASS
Challenge Check agent/check.sh OK OK PASS

8. Alternative Troubleshooting Approaches

While ss and systemctl were used during the incident, alternative Linux utilities can achieve identical diagnostic outcomes depending on tool availability.

1. lsof (List Open Files)

lsof treats network sockets as open files within the Linux VFS structure.

sudo lsof -i :8000
COMMAND   PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
python3   913 admin    4u  IPv4  23412      0t0  TCP *:8000 (LISTEN)
  • Advantages: Directly links port numbers to user accounts, PIDs, and File Descriptors (FDs).
  • Limitations: Slower on systems with thousands of open files.

2. fuser (File and Socket User Identification)

fuser identifies processes using specific files, filesystems, or network sockets.

sudo fuser 8000/tcp
8000/tcp:            913
  • Advantages: extremely lightweight; allows immediate process termination using fuser -k 8000/tcp.
  • Limitations: Minimal output detail compared to ss or lsof.

3. strace (System Call Tracing)

If the binary source code or port requirement is unknown, strace intercepts kernel system calls to expose socket binding requests.

strace -e trace=network ./standalone
socket(AF_INET, SOCK_STREAM, IPPROTO_TCP) = 3
bind(3, {sa_family=AF_INET, sin_port=htons(8000), sin_addr=inet_addr("0.0.0.0")}, 16) = -1 EADDRINUSE (Address already in use)
write(2, "listen tcp4 0.0.0.0:8000: bind: address already in use\n", 55) = 55
  • Advantages: Reveals hardcoded port numbers without access to source code.

Diagnostic Tool Comparison

Tool Focus Command Example Best Use Case
ss Socket Statistics ss -tulpn Rapid socket auditing & interface binding analysis
lsof File Descriptor Audit lsof -i :8000 Mapping open sockets to specific files and users
fuser Quick PID Lookup fuser 8000/tcp Scripting and fast signal delivery
strace Syscall Interception strace -e bind ./standalone Debugging binary socket operations without source code

9. Linux Command Deep Dive

Command: ss (Socket Statistics)

Purpose

ss inspects kernel socket information directly via the kernel netlink interface, replacing the legacy netstat utility.

General Syntax

ss [options] [FILTER]

Commonly Used Troubleshooting Options

Flag Long Option Description
-t --tcp Display TCP sockets.
-u --udp Display UDP sockets.
-l --listening Show only listening sockets (omits established connections).
-p --processes Show process PID and application name owning the socket (requires sudo).
-n --numeric Show numerical addresses/ports instead of resolving service names.
-a --all Show both listening and non-listening (established) sockets.
-s --summary Print summary statistics of total socket memory and state counts.

Practical Examples

# Find any process listening on port 8000 or 8001
sudo ss -tulpn | grep -E ':8000|:8001'

# View socket summary statistics
ss -s

Command: systemctl (Systemd Control)

Purpose

systemctl manages the systemd init system, controlling services, targets, and unit file states.

Useful Options & Commands

Subcommand Description
systemctl status <unit> Displays runtime status, PID, memory consumption, and recent journal logs.
systemctl cat <unit> Displays the full content of a unit file and drop-in overrides.
systemctl daemon-reload Reloads systemd manager configuration after editing unit files on disk.
systemctl restart <unit> Stops and starts a target service unit.
systemctl edit <unit> Creates a safe drop-in override file under /etc/systemd/system/<unit>.d/override.conf.

Practical Examples

# Check if a specific PID belongs to a systemd service unit
systemctl status <PID>

# Safely edit a service unit without overwriting vendor files
sudo systemctl edit --full django.service

Command: nginx

Purpose

High-performance HTTP server and reverse proxy daemon.

Useful Command Flags

Flag Description
-t Test configuration file syntax and validate directives without restarting.
-T Test configuration and print the entire parsed configuration to stdout.
-s reload Send SIGHUP signal to master process to reload configuration gracefully without dropping active connections.

Practical Examples

# Test Nginx configuration before reloading
sudo nginx -t

# Perform graceful configuration reload
sudo systemctl reload nginx

10. Underlying Linux Concepts and Architecture

1. Socket Binding & EADDRINUSE Mechanics

In Linux networking, a socket is identified by a 5-tuple: (Protocol, Source IP, Source Port, Destination IP, Destination Port).

When an application invokes the bind() system call:

  1. The kernel checks if the requested local IP address and port combination is present in the listening hash table (inet_hashinfo).
  2. If another process is already bound to 0.0.0.0:8000, the kernel returns -1 with errno set to EADDRINUSE.
  3. Wildcard binding (0.0.0.0) claims the target port across all network interfaces on the host, preventing any other socket from binding to that port on 127.0.0.1 or specific interface IPs.

2. Systemd Unit Reloading Lifecycle

Systemd maintains an in-memory dependency graph of all system units:

  • Editing a unit file on disk (e.g., /etc/systemd/system/django.service) modifies the file system but not systemd’s active memory.
  • Executing systemctl daemon-reload causes systemd PID 1 to rescan unit files, re-parse configuration directives, and update its runtime state graph.
  • If daemon-reload is omitted prior to systemctl restart, systemd will issue a warning and execute the old cached unit definition.

3. Nginx Reverse Proxying & sites-available vs. sites-enabled

In Debian/Ubuntu Nginx distributions, configuration files are split:

  • /etc/nginx/sites-available/: Contains configuration templates for virtual hosts. Files here are inactive by default.
  • /etc/nginx/sites-enabled/: Contains active virtual host configurations included directly by /etc/nginx/nginx.conf (include /etc/nginx/sites-enabled/*;).

The HTTP 502 Bad Gateway Error

An HTTP 502 Bad Gateway error occurs when Nginx successfully receives an HTTP request on port 80, attempts to forward it to the upstream IP address specified in proxy_pass, and encounters a ECONNREFUSED (Connection refused) error from the backend TCP socket.


11. Real-World Sysadmin and SRE Applications

1. Production Detection & Monitoring

In production environments, port collisions and 502 Bad Gateway errors should be detected automatically before impacting end users:

  • Prometheus Blackbox Exporter: Probes port 80 HTTP response codes and alerts if status codes return 502 Bad Gateway.
  • Systemd Unit Alerts: Monitors systemd_unit_state{failed="true"} metrics to detect failing services entering crash loops.
  • Socket Health Audits: Automates socket checks using ss in CI/CD deployment pipelines prior to application startup.

2. Preventing Port Collisions

To prevent port collisions in modern cloud environments:

  • Use Environment Variables for Application Ports: Avoid hardcoding ports inside binaries or service definitions. Pass ports dynamically (e.g., ExecStart=/usr/bin/python3 manage.py runserver 0.0.0.0:${PORT}).
  • Adopt Containerization & Network Namespaces: Running applications in Docker containers or Kubernetes pods provides dedicated network namespaces, isolating container ports from host-level port collisions.

12. Further Learning and Experiments

Hands-on Experiments

Experiment 1: Simulate Socket Collision and Process Killing

  1. Open a terminal and launch a simple HTTP server on port 8000:
python3 -m http.server 8000
  1. Open a second terminal and attempt to launch another instance:
python3 -m http.server 8000

Observe the OSError: [Errno 98] Address already in use error. 3. Use fuser to identify and terminate the process holding port 8000:

sudo fuser -k 8000/tcp
  1. Navigate to Nginx directories:
ls -la /etc/nginx/sites-enabled/
  1. Practice creating proper symlinks for site deployment:
sudo ln -s /etc/nginx/sites-available/default /etc/nginx/sites-enabled/default
sudo nginx -t

Documentation References


13. Key Takeaways

  1. Check Active Configurations First: Always verify which file is actively loaded in /etc/nginx/sites-enabled/ before modifying templates in /etc/nginx/sites-available/.
  2. Always Run systemctl daemon-reload: Modifying systemd unit files on disk requires reloading systemd memory before restarting services.
  3. Validate Nginx Configuration Syntax: Always execute nginx -t prior to reloading Nginx worker processes to avoid introducing production downtime.
  4. Use Zero-Downtime Reloads: Prefer systemctl reload nginx over restart when updating reverse proxy rules to avoid dropping active client connections.
  5. Trace System Dependencies systematically: Use ss -tulpn to find socket owners and systemctl status to inspect service supervision trees before terminating processes.

14. Quick Troubleshooting Reference / Runbook

# 1. Identify process listening on target port (e.g. 8000)
sudo ss -tulpn | grep :8000

# 2. Inspect process details and systemd parentage
ps -fp <PID>
systemctl status <PID>

# 3. Modify systemd service unit file to use a new port (e.g. 8001)
sudo sed -i 's/8000/8001/' /etc/systemd/system/<service_name>.service

# 4. Reload systemd daemon and restart service
sudo systemctl daemon-reload
sudo systemctl restart <service_name>

# 5. Update active Nginx reverse proxy configuration
sudo sed -i 's/8000/8001/' /etc/nginx/sites-enabled/<config_file>

# 6. Test Nginx configuration syntax and reload
sudo nginx -t
sudo systemctl reload nginx

# 7. Verify HTTP endpoint and target binary
curl -i http://localhost:80
/path/to/standalone/binary