Skip to content

Commit f227ce4

Browse files
committed
remove daemonization code from docs.rs
This commit removes the forking code in the docs.rs daemon, forcing it to always run in the background. The rationale for the change is that forking adds complexity and sets extra constraint for development, while it's not needed anymore on modern infrastructure. The --foreground flag is kept in the binary for compatibility, and it will only print a warning. Once this commit is deployed in production for a while, the flag can be removed.
1 parent 84fe0cb commit f227ce4

File tree

5 files changed

+8
-35
lines changed

5 files changed

+8
-35
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,6 @@ chrono = { version = "0.4.11", features = ["serde"] }
6767
time = "0.1" # TODO: Remove once `iron` is removed
6868

6969
[target.'cfg(not(windows))'.dependencies]
70-
libc = "0.2"
71-
7270
# Process information
7371
procfs = "0.7"
7472

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ docker-compose run web database blacklist remove <CRATE_NAME>
202202
# Run a persistent daemon which queues builds and starts a web server.
203203
# Warning: This will try to queue hundreds of packages on crates.io, only start it
204204
# if you have enough resources!
205-
docker-compose run -p 3000:3000 web daemon --foreground
205+
docker-compose run -p 3000:3000 web daemon
206206
```
207207

208208
### Changing the build environment

src/bin/cratesfyi.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ enum CommandLine {
6262

6363
/// Starts cratesfyi daemon
6464
Daemon {
65-
/// Run the server in the foreground instead of detaching a child
65+
/// Deprecated. Run the server in the foreground instead of detaching a child
6666
#[structopt(name = "FOREGROUND", short = "f", long = "foreground")]
6767
foreground: bool,
6868
},
@@ -93,7 +93,11 @@ impl CommandLine {
9393
Server::start(Some(&socket_addr), reload_templates, config)?;
9494
}
9595
Self::Daemon { foreground } => {
96-
cratesfyi::utils::start_daemon(!foreground, config)?;
96+
if foreground {
97+
log::warn!("--foreground was passed, but there is no need for it anymore");
98+
}
99+
100+
cratesfyi::utils::start_daemon(config)?;
97101
}
98102
Self::Database { subcommand } => subcommand.handle_args(),
99103
Self::Queue { subcommand } => subcommand.handle_args(),

src/utils/daemon.rs

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@ use std::sync::Arc;
1616
use std::time::Duration;
1717
use std::{env, thread};
1818

19-
#[cfg(not(target_os = "windows"))]
20-
use ::{libc::fork, std::fs::File, std::io::Write, std::process::exit};
21-
22-
pub fn start_daemon(background: bool, config: Arc<Config>) -> Result<(), Error> {
19+
pub fn start_daemon(config: Arc<Config>) -> Result<(), Error> {
2320
const CRATE_VARIABLES: [&str; 3] = [
2421
"CRATESFYI_PREFIX",
2522
"CRATESFYI_GITHUB_USERNAME",
@@ -38,31 +35,6 @@ pub fn start_daemon(background: bool, config: Arc<Config>) -> Result<(), Error>
3835
// check paths once
3936
dbopts.check_paths().unwrap();
4037

41-
if background {
42-
#[cfg(target_os = "windows")]
43-
{
44-
panic!("running in background not supported on windows");
45-
}
46-
47-
#[cfg(not(target_os = "windows"))]
48-
{
49-
// fork the process
50-
let pid = unsafe { fork() };
51-
if pid > 0 {
52-
let mut file = File::create(dbopts.prefix.join("cratesfyi.pid"))
53-
.expect("Failed to create pid file");
54-
writeln!(&mut file, "{}", pid).expect("Failed to write pid");
55-
56-
info!(
57-
"cratesfyi {} daemon started on: {}",
58-
crate::BUILD_VERSION,
59-
pid
60-
);
61-
exit(0);
62-
}
63-
}
64-
}
65-
6638
// check new crates every minute
6739
thread::Builder::new()
6840
.name("registry index reader".to_string())

0 commit comments

Comments
 (0)