diff --git a/src/main.rs b/src/main.rs index cb02cf8..b0487c3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -217,18 +217,20 @@ fn main() -> Result<()> { .unwrap_or_else(|| "5050".to_owned()) .parse() .with_context(|| "Invalid port number")?; - - service::server::run( - port, - Some(auth_secret.as_slice()), - api_url, - web_url, - web_dir_path, - swagger_url, - swagger_dir_path, - db.clone(), - command_sender, - )?; + let db_server = db.clone(); + std::thread::spawn(move || { + let _ = service::server::run( + port, + Some(auth_secret.as_slice()), + api_url, + web_url, + web_dir_path, + swagger_url, + swagger_dir_path, + db_server, + command_sender, + ); + }); // Start DDNS updates let db_ddns = db.clone(); diff --git a/src/service/actix/server.rs b/src/service/actix/server.rs index 2dcc699..58f457c 100644 --- a/src/service/actix/server.rs +++ b/src/service/actix/server.rs @@ -1,3 +1,4 @@ +use actix_rt::System; use actix_web::{App, HttpServer}; use anyhow::*; use std::path::PathBuf; @@ -6,8 +7,7 @@ use std::sync::Arc; use crate::db::DB; use crate::index::CommandSender; -#[actix_rt::main] -pub async fn run( +pub fn run( port: u16, auth_secret: Option<&[u8]>, api_url: String, @@ -18,7 +18,9 @@ pub async fn run( db: DB, command_sender: Arc, ) -> Result<()> { - HttpServer::new(move || { + let mut sys = System::new("polaris_service_executor"); + + let server = HttpServer::new(move || { App::new().configure(|cfg| { super::configure_app( cfg, @@ -30,8 +32,8 @@ pub async fn run( ) }) }) - .bind(format!("127.0.0.1:{}", port))? + .bind(format!("0.0.0.0:{}", port))? .run(); - Ok(()) + sys.block_on(server).map_err(Error::new) }