@@ -17,8 +17,6 @@ use utils::{update_sources, update_release_activity};
17
17
use db:: { connect_db, update_search_index} ;
18
18
19
19
20
- const DAEMON_PID_FILE_PATH : & ' static str = "/var/run/cratesfyi.pid" ;
21
-
22
20
23
21
pub fn start_daemon ( ) {
24
22
// first check required environment variables
@@ -30,13 +28,16 @@ pub fn start_daemon() {
30
28
env:: var ( v) . expect ( "Environment variable not found" ) ;
31
29
}
32
30
31
+ let dbopts = opts ( ) ;
32
+
33
33
// check paths once
34
- opts ( ) . check_paths ( ) . unwrap ( ) ;
34
+ dbopts . check_paths ( ) . unwrap ( ) ;
35
35
36
36
// fork the process
37
37
let pid = unsafe { fork ( ) } ;
38
38
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" ) ;
40
41
writeln ! ( & mut file, "{}" , pid) . expect ( "Failed to write pid" ) ;
41
42
42
43
info ! ( "cratesfyi {} daemon started on: {}" , :: BUILD_VERSION , pid) ;
@@ -113,7 +114,7 @@ pub fn start_daemon() {
113
114
// update search index every 3 hours
114
115
thread:: spawn ( move || {
115
116
loop {
116
- thread:: sleep ( Duration :: from_secs ( 60 * 60 * 3 ) ) ;
117
+ thread:: sleep ( Duration :: from_secs ( 60 * 60 * 3 ) ) ;
117
118
let conn = connect_db ( ) . expect ( "Failed to connect database" ) ;
118
119
if let Err ( e) = update_search_index ( & conn) {
119
120
error ! ( "Failed to update search index: {}" , e) ;
@@ -132,6 +133,6 @@ pub fn start_daemon() {
132
133
133
134
fn opts ( ) -> DocBuilderOptions {
134
135
let prefix = PathBuf :: from ( env:: var ( "CRATESFYI_PREFIX" )
135
- . expect ( "CRATESFYI_PREFIX environment variable not found" ) ) ;
136
+ . expect ( "CRATESFYI_PREFIX environment variable not found" ) ) ;
136
137
DocBuilderOptions :: from_prefix ( prefix)
137
138
}
0 commit comments