diff --git a/Procfile b/Procfile index 320f6aa1ca2..107a8581882 100644 --- a/Procfile +++ b/Procfile @@ -1,3 +1,3 @@ release: bin/diesel migration run -web: ./script/start-web.sh +web: ./target/release/server background_worker: ./target/release/background-worker diff --git a/script/start-web.sh b/script/start-web.sh index bcf62b29efc..adee94fb935 100755 --- a/script/start-web.sh +++ b/script/start-web.sh @@ -1,12 +1,15 @@ #! /bin/bash set -ue +# Since this script is launched from our app, we tell the nginx +# buildpack (`bin/start-nginx`) that `cat` is our server. + if [[ -z "${USE_FASTBOOT-}" ]]; then unset USE_FASTBOOT - bin/start-nginx ./target/release/server + bin/start-nginx cat else export USE_FASTBOOT node --optimize_for_size --max_old_space_size=200 fastboot.js & - bin/start-nginx ./target/release/server & + bin/start-nginx cat & wait -n fi diff --git a/src/bin/server.rs b/src/bin/server.rs index 5d5d2102f7c..c9fcb86d485 100644 --- a/src/bin/server.rs +++ b/src/bin/server.rs @@ -5,8 +5,8 @@ use cargo_registry::{boot, App, Env}; use std::{ borrow::Cow, fs::File, + process::Command, sync::{mpsc::channel, Arc, Mutex}, - thread, time::Duration, }; @@ -139,9 +139,6 @@ fn main() -> Result<(), Box> { println!("listening on port {}", port); - // Give tokio a chance to spawn the first worker thread - thread::sleep(Duration::from_millis(10)); - // Creating this file tells heroku to tell nginx that the application is ready // to receive traffic. if heroku { @@ -152,6 +149,13 @@ fn main() -> Result<(), Box> { }; println!("Writing to {}", path); File::create(path).unwrap(); + + // Launch nginx via the Heroku nginx buildpack + // `wait()` is never called on the child process, but it should be okay to leave a zombie + // process around on shutdown when Heroku is tearing down the entire container anyway. + Command::new("./script/start-web.sh") + .spawn() + .expect("Couldn't spawn nginx"); } // Block the main thread until the server has shutdown diff --git a/src/downloads_counter.rs b/src/downloads_counter.rs index 7fbfd6fdc59..a617da59bda 100644 --- a/src/downloads_counter.rs +++ b/src/downloads_counter.rs @@ -80,7 +80,7 @@ impl DownloadsCounter { } println!( - "download_counter all_shards counted_versions={} counted_downloads={} pending_downloads={}", + "downloads_counter all_shards counted_versions={} counted_downloads={} pending_downloads={}", counted_versions, counted_downloads, pending_downloads, @@ -101,7 +101,7 @@ impl DownloadsCounter { let stats = self.persist_shard(&conn, shard)?; println!( - "download_counter shard={} counted_versions={} counted_downloads={} pending_downloads={}", + "downloads_counter shard={} counted_versions={} counted_downloads={} pending_downloads={}", idx, stats.counted_versions, stats.counted_downloads,