mirror of
https://github.com/sadoyan/aralez.git
synced 2026-06-10 01:04:20 +08:00
OS signals , PID file
This commit is contained in:
10
Cargo.lock
generated
10
Cargo.lock
generated
@@ -154,6 +154,7 @@ dependencies = [
|
||||
"rcgen",
|
||||
"reqwest",
|
||||
"rustls-pemfile",
|
||||
"sd-notify",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"serde_yml",
|
||||
@@ -3404,6 +3405,15 @@ version = "1.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
|
||||
|
||||
[[package]]
|
||||
name = "sd-notify"
|
||||
version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3e4ef7359e694bfaf1dd27a30f9d760b54c00dfae9f19bd0c05a39bc9128fe76"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sec1"
|
||||
version = "0.7.3"
|
||||
|
||||
@@ -50,3 +50,4 @@ log4rs = "1.4.0"
|
||||
tikv-jemallocator = "0.7.0"
|
||||
tikv-jemalloc-ctl = { version = "0.7.0", features = ["stats"] }
|
||||
signal-hook = "0.4.4"
|
||||
sd-notify = "0.5.0"
|
||||
|
||||
@@ -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