Skip to content

Remove daemonization code from docs.rs #844

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ chrono = { version = "0.4.11", features = ["serde"] }
time = "0.1" # TODO: Remove once `iron` is removed

[target.'cfg(not(windows))'.dependencies]
libc = "0.2"

# Process information
procfs = "0.7"

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ docker-compose run web database blacklist remove <CRATE_NAME>
# Run a persistent daemon which queues builds and starts a web server.
# Warning: This will try to queue hundreds of packages on crates.io, only start it
# if you have enough resources!
docker-compose run -p 3000:3000 web daemon --foreground
docker-compose run -p 3000:3000 web daemon
```

### Changing the build environment
Expand Down
8 changes: 6 additions & 2 deletions src/bin/cratesfyi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ enum CommandLine {

/// Starts cratesfyi daemon
Daemon {
/// Run the server in the foreground instead of detaching a child
/// Deprecated. Run the server in the foreground instead of detaching a child
#[structopt(name = "FOREGROUND", short = "f", long = "foreground")]
foreground: bool,
},
Expand Down Expand Up @@ -93,7 +93,11 @@ impl CommandLine {
Server::start(Some(&socket_addr), reload_templates, config)?;
}
Self::Daemon { foreground } => {
cratesfyi::utils::start_daemon(!foreground, config)?;
if foreground {
log::warn!("--foreground was passed, but there is no need for it anymore");
}

cratesfyi::utils::start_daemon(config)?;
}
Self::Database { subcommand } => subcommand.handle_args(),
Self::Queue { subcommand } => subcommand.handle_args(),
Expand Down
30 changes: 1 addition & 29 deletions src/utils/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ use std::sync::Arc;
use std::time::Duration;
use std::{env, thread};

#[cfg(not(target_os = "windows"))]
use ::{libc::fork, std::fs::File, std::io::Write, std::process::exit};

pub fn start_daemon(background: bool, config: Arc<Config>) -> Result<(), Error> {
pub fn start_daemon(config: Arc<Config>) -> Result<(), Error> {
const CRATE_VARIABLES: [&str; 3] = [
"CRATESFYI_PREFIX",
"CRATESFYI_GITHUB_USERNAME",
Expand All @@ -38,31 +35,6 @@ pub fn start_daemon(background: bool, config: Arc<Config>) -> Result<(), Error>
// check paths once
dbopts.check_paths().unwrap();

if background {
#[cfg(target_os = "windows")]
{
panic!("running in background not supported on windows");
}

#[cfg(not(target_os = "windows"))]
{
// fork the process
let pid = unsafe { fork() };
if pid > 0 {
let mut file = File::create(dbopts.prefix.join("cratesfyi.pid"))
.expect("Failed to create pid file");
writeln!(&mut file, "{}", pid).expect("Failed to write pid");

info!(
"cratesfyi {} daemon started on: {}",
crate::BUILD_VERSION,
pid
);
exit(0);
}
}
}

// check new crates every minute
thread::Builder::new()
.name("registry index reader".to_string())
Expand Down