How to configure apps that are not meant to have publicly available ports

Same as this unanswered post: How to setup a service/process app that never shuts down

My question is: how do you correctly set up a service in fly.io that should not be publicly accessible

I’ve got a service (cron) that is not meant to be accessed at all. But every time I deploy I get this warning:

WARNING: Service must expose at least one port. Add a [[services.ports]] section to fly.toml; Check docs at https://fly.io/docs/reference/configuration/#services-ports 
 Validation for _services without ports_ will hard fail after February 15, 2024.

My fly.toml is the following:

app = "<redacted>"
primary_region = "ord"

[env]
  SERVER_PORT = "3000"
  WEBHOOK_SERVICE_PORT = "3030"

[deploy]
  release_command = "bunx prisma migrate deploy && bunx prisma generate"

[processes]
  api = "bun run start:main"
  webhooks = "bun run start:webhooks"
  cron = "bun run start:cron"
   
[http_service]
  internal_port = 3000
  force_https = true
  auto_stop_machines = true
  auto_start_machines = true
  min_machines_running = 1
  processes = ["api"]
  [http_service.concurrency]
    type = "requests"
    hard_limit = 250
    soft_limit = 200

[[services]]
  processes = ["webhooks"]
  internal_port = 3030
  protocol = "tcp"
  auto_stop_machines = true
  auto_start_machines = true
  min_machines_running = 0

  [[services.ports]]
    handlers = ["http"]
    port = 8080
    force_https = true

  [[services.ports]]
    handlers = ["tls", "http"]
    port = 448

# min config to ensure the cron service never shuts down
[[services]]
  processes = ["cron"]
  internal_port = 3333
  protocol = "tcp"
  auto_stop_machines = true
  auto_start_machines = true
  min_machines_running = 1

Just remove the http_service block. That, and [services], tell our infrastructure to setup a network service.

I can’t just remove the http service as that represents the api service that I have. I didn’t add the http_service section to be left unused.

I have 3 services running in this fly app:

  • api-server (running as a traditional http service whose port is mapped to 3000)
  • cron service that should not be publicly accessible and needs no port mapping
  • webhooks which should auto start and stop and receives event traffic from time to time

I think Kurt meant to say you should remove the [[services]] block for your cron process. It doesn’t need one. When you remove it and redeploy, you’ll get a single Machine with a standby. That Machine should stay running.

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