Experience
Projects
My Stack
Case studies
Contact me
Open my CV

·5 min read

One missing curl flag broke my mail server setup

The mail server image sat there, up and healthy, and still refused to finish its own setup. The entrypoint logged that it could not open a JMAP session, killed the temporary Stalwart process it had started, and returned an error. The password was right. The server was running. The git history of this bug is two commits fifty seconds apart: one that makes the failure talk, and one that fixes it with a single flag.

Project
Pterodactyl yolks
Date
Oct 2026
Stack
Docker, Shell, curl, jq, Stalwart
Commit
09570f1, 7b54f3f

What broke

Stalwart is an all-in-one mail server in one binary. On a fresh data store it creates its default listeners on ports 25, 465, 993 and 443, and a Wings container cannot bind any of those. So my entrypoint does a one-time setup before the real start. It boots Stalwart once in recovery mode on the server's web port, then talks to it over JMAP, the JSON mail API, to create listeners on the ports the panel allocated to this server.

JMAP begins with a session request. A client asks /.well-known/jmap and the server answers with a document that describes the accounts and where to send further calls. My script needs that document to find the account id to use. The loop looked like this in the first version of the image (8752bae):

bash
session=$(curl -fsS -u "admin:${MAIL_ADMIN_PASSWORD}" "http://127.0.0.1:${WEB_PORT}/.well-known/jmap" 2>/dev/null) && break

And after the loop, if no account id could be read from the session with jq, the script logged "could not open a JMAP session for setup" and gave up. That is what I was seeing, with nothing to explain it: a message that told me the result and none of the cause.

What the code showed

The answer is in what -f does. With curl -f, an HTTP status of 400 or above makes curl fail. A redirect is a 3xx status, so it does not count as a failure, and without -L curl does not follow it. The command exits with success, the && break leaves the loop on the first try, and session holds whatever the redirect response carried instead of a JMAP session. Then jq finds no account in it, and the setup stops.

I did not keep the original failing output, so this is the reading of the code and the curl flags, not a captured log. What I did capture is the step that led to the fix. The first commit changed the failure branch to show what had actually come back:

bash
echo "Renode: could not open a JMAP session for setup:"
printf '%s\n' "$session" | head -c 2000; echo

That is 7b54f3f (Oct 2026), a commit literally titled "debug: show session on setup failure". The head -c 2000 is there so an unexpected HTML page or a large error does not flood the panel console. The idea is simple: when a script reports an outcome without a reason, make it print the reason before you start theorizing.

The fix

Fifty seconds later, 09570f1 (Oct 2026), titled "follow the JMAP session redirect", added one letter to the curl options, from -fsS to -fsSL:

bash
session=$(curl -fsSL -u "admin:${MAIL_ADMIN_PASSWORD}" "http://127.0.0.1:${WEB_PORT}/.well-known/jmap" 2>/dev/null) && break

The same commit touched the CI workflow in three places, and that part is easy to miss. The workflow checks the web endpoint directly: the administrator login must answer 200, a wrong password must answer 401, and the same login must still answer 200 after a restart. Each of those used curl to request the same .well-known/jmap URL, and each had to get -L too:

bash
code=$(curl -s -o /dev/null -w '%{http_code}' -L -u "admin:$PW" http://127.0.0.1:25728/.well-known/jmap)
echo "jmap with password: $code"; [ "$code" = 200 ]

Without it, the tests would have been looking at the status of the redirect instead of the status of the session. That matters most for the wrong-password check. A test that expects 401 and gets a redirect status fails for a reason that has nothing to do with passwords, and a test that "passes" by accident would be worse.

  1. 01

    Start in recovery mode

    Stalwart boots once on the server's web port

  2. 02

    Ask for the session

    curl -fsSL on /.well-known/jmap, retried for up to 60 seconds

  3. 03

    Follow the redirect

    -L carries the request to the real session document

  4. 04

    Read the account id

    jq takes the primary account from the session

  5. 05

    Create the listeners

    JMAP calls set up this server's allocated ports

Figure 1. How the setup finds its account, after 09570f1.

What I would do differently

The first version used -fsS, the standard "quiet but fail on error" recipe. It is a good default for an API with a stable URL. A .well-known endpoint is a discovery address, and discovery addresses are exactly the ones that redirect. I would treat any .well-known request as one that may redirect and write the flag from the start.

I would also keep a debug line like that one permanently, not as a throwaway commit. The final entrypoint still prints the session body on failure, and I am glad it does. A setup step that runs once, inside a customer's container, is hard to reproduce. Having the response in the console is what turns "could not open a session" into something I can act on.

Where this fits

This was one of a handful of small startup failures in my Pterodactyl images, each of which was found by running the image the way Wings does and then fixed with a CI check that keeps it fixed. The full yolks case study has the Stalwart setup in context, including the marker file that stops the listener setup running twice.

Read the entrypoint's `configure_listeners` function to see the JMAP setup this one flag unblocked.

View the image on GitHub

#curl#jmap#docker#pterodactyl#debugging

Keep reading

Have a project in mind?