I was wondering what could I possible be doing wrong when attempting to deploy a very minimal expressjs server? I followed every instruction from the documentation but deploy crushes with the message ’ shutting down the virtual machine’. I honestly don’t even know how to structure my question properly. I am just failing to deploy a very basic server in order to test out the fly.io functionality. Has anyone a reference to a solid set up tutorial that shows what the best way is to set up an expressjs server?
Can you share more logs, the dockerfile, app’s fly.toml (and repo link if the code is public)?
shutting down the virtual machine.
Sounds like expressjs isn’t listening for incoming connections forever and the process simply terminates immediately after its up… or, something of the sort.
You could also compare your code with any of these reference node apps: Fly.io Apps · GitHub
This is a great collection of reference material; a lot of what’s in the fly-apps
repos isn’t actively maintained (more likely so, if it’s not used in one of the guides on our docs page), so while there’s a lot of inspiration and useful patterns in those repos, some of them may not work out of the box.
That being said, I’ve just run through the node/express guide in our docs, in which fly launch
uses a buildpack to build the app in the “hellonode-builtin” repo, and it worked, so that may be a good starting point if you haven’t run through it already.
2022-06-18T17:58:13.456 runner[70e9cfb2] ams [info] Starting instance
2022-06-18T17:58:13.986 runner[70e9cfb2] ams [info] Configuring virtual machine
2022-06-18T17:58:13.987 runner[70e9cfb2] ams [info] Pulling container image
2022-06-18T17:58:16.128 runner[70e9cfb2] ams [info] Unpacking image
2022-06-18T17:58:16.804 runner[70e9cfb2] ams [info] Preparing kernel init
2022-06-18T17:58:17.051 runner[70e9cfb2] ams [info] Configuring firecracker
2022-06-18T17:58:17.153 runner[70e9cfb2] ams [info] Starting virtual machine
2022-06-18T17:58:17.337 app[70e9cfb2] ams [info] Starting init (commit: e21acb3)…
2022-06-18T17:58:17.352 app[70e9cfb2] ams [info] Preparing to run: /cnb/process/web
as heroku
2022-06-18T17:58:17.371 app[70e9cfb2] ams [info] 2022/06/18 17:58:17 listening on [fdaa:0:7020:a7b:23c5:70e9:cfb2:2]:22 (DNS: [fdaa::3]:53)
2022-06-18T17:58:18.109 app[70e9cfb2] ams [info] > flyio@1.0.0 start
2022-06-18T17:58:18.109 app[70e9cfb2] ams [info] > node server.js
2022-06-18T17:58:18.281 app[70e9cfb2] ams [info] server is up and runnning on port 300
2022-06-18T18:03:28.026 runner[70e9cfb2] ams [info] Shutting down virtual machine
2022-06-18T18:03:28.127 app[70e9cfb2] ams [info] Sending signal SIGINT to main child process w/ PID 515
Error 3003: HTTP host header / pseudoheader is missing
2022-06-19T01:38:06.247 proxy[e54f140b] fra [error] Error 2011: App is unhealthy
2022-06-19T01:39:31.565 proxy[e54f140b] fra [error] Error 2011: App is unhealthy
fly.toml file generated for expressjs on 2022-06-18T23:37:30+06:00
app = “expressjs”
kill_signal = “SIGINT”
kill_timeout = 5
processes =
[build]
builder = “heroku/buildpacks:20”
[env]
PORT = “8080”
[experimental]
allowed_public_ports =
auto_rollback = true
[[services]]
http_checks =
internal_port = 8080
processes = [“app”]
protocol = “tcp”
script_checks =
[services.concurrency]
hard_limit = 25
soft_limit = 20
type = “connections”
[[services.ports]]
force_https = true
handlers = [“http”]
port = 80
[[services.ports]]
handlers = [“tls”, “http”]
port = 443
[[services.tcp_checks]]
grace_period = “1s”
interval = “15s”
restart_limit = 0
timeout = “2s”
- Remove
process
entries from the fly.toml since it doesn’t look like you need it (this isn’t the reason why the app isn’t running). - From the logs, it looks like your server is listening on port
300
, so change code to listen on8080
or change fly.toml entries (might be the reason the app is taken down by Fly’s init on health-check failures). - Go easy on the health-check grace-period and restarts.
Try:
app = "expressjs"
kill_signal = "SIGINT"
kill_timeout = 5
processes = # remove this line
[build]
builder = "heroku/buildpacks:20"
[env]
PORT = "8080" # is the server code using this env-variable?
...
[[services]]
http_checks =
internal_port = 8080 # is the server listening on 8080 or 300?
processes = ["app"] # remove this line
...
[[services.tcp_checks]]
grace_period = "1s" # a bit higher, 5s or 10s?
interval = "15s" # this means health-check connects to the server every 15s...
restart_limit = 0 # at least, attempt a restart 1 or 3?
timeout = "2s" # aggressive, but ok