Skip to content

Commit 82e1eb1

Browse files
committed
Save pid file into prefix
1 parent 10d26cd commit 82e1eb1

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/utils/daemon.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ use utils::{update_sources, update_release_activity};
1717
use db::{connect_db, update_search_index};
1818

1919

20-
const DAEMON_PID_FILE_PATH: &'static str = "/var/run/cratesfyi.pid";
21-
2220

2321
pub fn start_daemon() {
2422
// first check required environment variables
@@ -30,13 +28,16 @@ pub fn start_daemon() {
3028
env::var(v).expect("Environment variable not found");
3129
}
3230

31+
let dbopts = opts();
32+
3333
// check paths once
34-
opts().check_paths().unwrap();
34+
dbopts.check_paths().unwrap();
3535

3636
// fork the process
3737
let pid = unsafe { fork() };
3838
if pid > 0 {
39-
let mut file = File::create(DAEMON_PID_FILE_PATH).expect("Failed to create pid file");
39+
let mut file = File::create(dbopts.prefix.join("cratesfyi.pid"))
40+
.expect("Failed to create pid file");
4041
writeln!(&mut file, "{}", pid).expect("Failed to write pid");
4142

4243
info!("cratesfyi {} daemon started on: {}", ::BUILD_VERSION, pid);
@@ -113,7 +114,7 @@ pub fn start_daemon() {
113114
// update search index every 3 hours
114115
thread::spawn(move || {
115116
loop {
116-
thread::sleep(Duration::from_secs(60*60*3));
117+
thread::sleep(Duration::from_secs(60 * 60 * 3));
117118
let conn = connect_db().expect("Failed to connect database");
118119
if let Err(e) = update_search_index(&conn) {
119120
error!("Failed to update search index: {}", e);
@@ -132,6 +133,6 @@ pub fn start_daemon() {
132133

133134
fn opts() -> DocBuilderOptions {
134135
let prefix = PathBuf::from(env::var("CRATESFYI_PREFIX")
135-
.expect("CRATESFYI_PREFIX environment variable not found"));
136+
.expect("CRATESFYI_PREFIX environment variable not found"));
136137
DocBuilderOptions::from_prefix(prefix)
137138
}

0 commit comments

Comments
 (0)