daemon fix

This commit is contained in:
2024-09-20 21:32:18 +02:00
parent f674a18f3b
commit b933a6f8be

View File

@@ -224,30 +224,28 @@ fn get_settings() -> Settings {
} }
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
#[tokio::main] fn main() {
async fn main() {
let current_directory = env::current_dir().expect("Could not get app directory."); let current_directory = env::current_dir().expect("Could not get app directory.");
let stdout = File::create("/var/vote/log/daemon.out").unwrap(); let stdout = File::create("/var/vote/log/daemon.out").unwrap();
let stderr = File::create("/var/vote/log/daemon.err").unwrap(); let stderr = File::create("/var/vote/log/daemon.err").unwrap();
let daemonize = Daemonize::new() let daemonize = Daemonize::new()
.pid_file("/var/vote/server.pid") .pid_file("/var/vote/server.pid")
.chown_pid_file(true)
.working_directory(current_directory) .working_directory(current_directory)
.stdout(stdout) .stdout(stdout)
.stderr(stderr); .stderr(stderr);
match daemonize.start() { match daemonize.start() {
Ok(_) => run().await, Ok(_) => run(),
Err(e) => eprintln!("Error, {}", e), Err(e) => eprintln!("Error, {}", e),
} }
} }
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
#[tokio::main] fn main() {
async fn main() { run();
run().await;
} }
#[tokio::main]
async fn run() { async fn run() {
let settings = get_settings(); let settings = get_settings();
let db_pool = Arc::new(Mutex::new(SqlitePool::connect(&settings.database_url).await.expect("Could not connect to database. Make sure the url is correct."))); let db_pool = Arc::new(Mutex::new(SqlitePool::connect(&settings.database_url).await.expect("Could not connect to database. Make sure the url is correct.")));