mirror of
https://github.com/sadoyan/aralez.git
synced 2026-06-10 17:24:21 +08:00
OS signals , PID file
This commit is contained in:
@@ -13,6 +13,7 @@ use pingora_core::listeners::tls::TlsSettings;
|
||||
use pingora_core::prelude::{background_service, Opt};
|
||||
use pingora_core::server::Server;
|
||||
use privdrop::reexports::libc::SIGQUIT;
|
||||
use sd_notify::NotifyState;
|
||||
use signal_hook::{
|
||||
consts::{SIGINT, SIGTERM},
|
||||
iterator::Signals,
|
||||
@@ -20,7 +21,7 @@ use signal_hook::{
|
||||
use std::sync::mpsc::{channel, Receiver, Sender};
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
use std::{fs, thread};
|
||||
use std::{fs, process, thread};
|
||||
|
||||
pub fn run() {
|
||||
// default_provider().install_default().expect("Failed to install rustls crypto provider");
|
||||
@@ -115,6 +116,8 @@ pub fn run() {
|
||||
if let (Some(user), Some(group)) = (cfg.rungroup.clone(), cfg.runuser.clone()) {
|
||||
drop_priv(user, group, cfg.proxy_address_http.clone(), cfg.proxy_address_tls.clone());
|
||||
}
|
||||
let _ = sd_notify::notify(&[NotifyState::Ready]);
|
||||
let _ = fs::write("/tmp/aralez.pid", process::id().to_string());
|
||||
|
||||
let mut signals = Signals::new(&[SIGINT, SIGTERM, SIGQUIT]).unwrap();
|
||||
for sig in signals.forever() {
|
||||
|
||||
@@ -88,25 +88,12 @@ pub async fn run_server(config: &APIUpstreamProvider, mut to_return: Sender<Conf
|
||||
break;
|
||||
}
|
||||
});
|
||||
rx.recv().await; // async wait, yields to tokio properly
|
||||
rx.recv().await;
|
||||
api_server.abort();
|
||||
if let Some(handle) = static_handle {
|
||||
handle.abort();
|
||||
}
|
||||
info!("Exiting...");
|
||||
|
||||
// port_is_available("Config API", &config.address).await;
|
||||
// let listener = TcpListener::bind(config.address.clone()).await.unwrap();
|
||||
// info!("Starting the API server on: {}", config.address);
|
||||
// axum::serve(listener, app).await.unwrap();
|
||||
// if let (Some(address), Some(folder)) = (&config.file_server_address, &config.file_server_folder) {
|
||||
// port_is_available("File Server", &address).await;
|
||||
// let static_files = ServeDir::new(folder);
|
||||
// let static_serve: Router = Router::new().fallback_service(static_files);
|
||||
// let static_listen = TcpListener::bind(address).await.unwrap();
|
||||
// static_handle = Some(tokio::spawn(async move { axum::serve(static_listen, static_serve).await.unwrap() }))
|
||||
// }
|
||||
//
|
||||
}
|
||||
|
||||
async fn conf(State(st): State<AppState>, Query(params): Query<HashMap<String, String>>, content: String) -> impl IntoResponse {
|
||||
|
||||
Reference in New Issue
Block a user