Multi-process / services hello world

tldr; how to configure a single fly.io app to run multiple processes on separate vms and control which of these processes is publicly accessible and which are not.

I am struggling to set this up personally. At the moment fly.io is creating all my processes on different machines (which is what I want it to do), but the [[services]] config that I have at the moment seems to not be working (in the sense that my webhooks service does not seem to be publicly accessible over http or https).

fwiw, here is my config atm:

primary_region = "ord"

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

[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

# config for the webhooks service 
[[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 = 443

[[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 = 443

# DO NOT EXPOSE THE CRON SERVICE
# hence no port info provided
[[services]]
  processes = ["cron"]
  internal_port = 9090 
  protocol = "tcp"
  min_machines_running = 1```

@rubys Sorry to ping you directly … might you have any ideas where I may be going wrong?

Hi,

Just to jump in …

It may simply be a typo in the post and so not the cause, but it seems that the webhooks [[services]] block is repeated :thinking:

If that’s in your actual fly.toml, could that be confusing it?

[[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 = 443

The other thing I’d check would be that the webhook service is indeed running on port 3030 and so available to connect to. That should be shown in flyctl logs.

Sorry - was a late night of debugging last night :sweat_smile:

I ended up realizing that I had to change the tls setting for the webhook (along with removing the duplicate code as you pointed out). Here is the working config:

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

Note that the api service runs on standard ports 80 and 443 while the webhooks service runs on ports 8080 and 448.

This allows me to expose the webhooks service via https://my-app-name.fly.dev:448

1 Like

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