mirror of
git://git.proxmox.com/git/proxmox-backup.git
synced 2025-01-22 22:04:00 +03:00
proxmox-rest-server: improve logging
And rename server_state_init() into catch_shutdown_and_reload_signals().
This commit is contained in:
parent
a0ffd4a413
commit
38da8ca1bc
@ -152,9 +152,9 @@ impl Reloader {
|
|||||||
self.do_reexec(new_args)
|
self.do_reexec(new_args)
|
||||||
})
|
})
|
||||||
{
|
{
|
||||||
Ok(Ok(())) => eprintln!("do_reexec returned!"),
|
Ok(Ok(())) => log::error!("do_reexec returned!"),
|
||||||
Ok(Err(err)) => eprintln!("do_reexec failed: {}", err),
|
Ok(Err(err)) => log::error!("do_reexec failed: {}", err),
|
||||||
Err(_) => eprintln!("panic in re-exec"),
|
Err(_) => log::error!("panic in re-exec"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(ForkResult::Parent { child }) => {
|
Ok(ForkResult::Parent { child }) => {
|
||||||
@ -307,7 +307,7 @@ where
|
|||||||
wait_service_is_not_state(service_name, "reloading").await?;
|
wait_service_is_not_state(service_name, "reloading").await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
log::info!("daemon shut down...");
|
log::info!("daemon shut down.");
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -360,6 +360,11 @@ pub enum SystemdNotify {
|
|||||||
|
|
||||||
/// Tells systemd the startup state of the service (see: ``man sd_notify``)
|
/// Tells systemd the startup state of the service (see: ``man sd_notify``)
|
||||||
pub fn systemd_notify(state: SystemdNotify) -> Result<(), Error> {
|
pub fn systemd_notify(state: SystemdNotify) -> Result<(), Error> {
|
||||||
|
|
||||||
|
if let SystemdNotify::Ready = &state {
|
||||||
|
log::info!("service is ready");
|
||||||
|
}
|
||||||
|
|
||||||
let message = match state {
|
let message = match state {
|
||||||
SystemdNotify::Ready => CString::new("READY=1"),
|
SystemdNotify::Ready => CString::new("READY=1"),
|
||||||
SystemdNotify::Reloading => CString::new("RELOADING=1"),
|
SystemdNotify::Reloading => CString::new("RELOADING=1"),
|
||||||
@ -374,5 +379,6 @@ pub fn systemd_notify(state: SystemdNotify) -> Result<(), Error> {
|
|||||||
std::io::Error::from_raw_os_error(-rc),
|
std::io::Error::from_raw_os_error(-rc),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -96,7 +96,6 @@ pub fn our_ctrl_sock() -> String {
|
|||||||
static SHUTDOWN_REQUESTED: AtomicBool = AtomicBool::new(false);
|
static SHUTDOWN_REQUESTED: AtomicBool = AtomicBool::new(false);
|
||||||
|
|
||||||
pub fn request_shutdown() {
|
pub fn request_shutdown() {
|
||||||
println!("request_shutdown");
|
|
||||||
SHUTDOWN_REQUESTED.store(true, Ordering::SeqCst);
|
SHUTDOWN_REQUESTED.store(true, Ordering::SeqCst);
|
||||||
crate::server_shutdown();
|
crate::server_shutdown();
|
||||||
}
|
}
|
||||||
|
@ -34,13 +34,18 @@ lazy_static! {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn server_state_init() -> Result<(), Error> {
|
/// Listen to ``SIGINT`` and ``SIGHUP`` signals
|
||||||
|
///
|
||||||
|
/// * ``SIGINT``: start server shutdown
|
||||||
|
///
|
||||||
|
/// * ``SIGHUP``: start server reload
|
||||||
|
pub fn catch_shutdown_and_reload_signals() -> Result<(), Error> {
|
||||||
|
|
||||||
let mut stream = signal(SignalKind::interrupt())?;
|
let mut stream = signal(SignalKind::interrupt())?;
|
||||||
|
|
||||||
let future = async move {
|
let future = async move {
|
||||||
while stream.recv().await.is_some() {
|
while stream.recv().await.is_some() {
|
||||||
println!("got shutdown request (SIGINT)");
|
log::info!("got shutdown request (SIGINT)");
|
||||||
SERVER_STATE.lock().unwrap().reload_request = false;
|
SERVER_STATE.lock().unwrap().reload_request = false;
|
||||||
crate::request_shutdown();
|
crate::request_shutdown();
|
||||||
}
|
}
|
||||||
@ -55,7 +60,7 @@ pub fn server_state_init() -> Result<(), Error> {
|
|||||||
|
|
||||||
let future = async move {
|
let future = async move {
|
||||||
while stream.recv().await.is_some() {
|
while stream.recv().await.is_some() {
|
||||||
println!("got reload request (SIGHUP)");
|
log::info!("got reload request (SIGHUP)");
|
||||||
SERVER_STATE.lock().unwrap().reload_request = true;
|
SERVER_STATE.lock().unwrap().reload_request = true;
|
||||||
crate::request_shutdown();
|
crate::request_shutdown();
|
||||||
}
|
}
|
||||||
@ -78,7 +83,7 @@ pub fn is_reload_request() -> bool {
|
|||||||
pub fn server_shutdown() {
|
pub fn server_shutdown() {
|
||||||
let mut data = SERVER_STATE.lock().unwrap();
|
let mut data = SERVER_STATE.lock().unwrap();
|
||||||
|
|
||||||
println!("SET SHUTDOWN MODE");
|
log::info!("request_shutdown");
|
||||||
|
|
||||||
data.mode = ServerMode::Shutdown;
|
data.mode = ServerMode::Shutdown;
|
||||||
|
|
||||||
|
@ -127,7 +127,7 @@ async fn run() -> Result<(), Error> {
|
|||||||
let init_result: Result<(), Error> = try_block!({
|
let init_result: Result<(), Error> = try_block!({
|
||||||
proxmox_rest_server::register_task_control_commands(&mut commando_sock)?;
|
proxmox_rest_server::register_task_control_commands(&mut commando_sock)?;
|
||||||
commando_sock.spawn()?;
|
commando_sock.spawn()?;
|
||||||
proxmox_rest_server::server_state_init()?;
|
proxmox_rest_server::catch_shutdown_and_reload_signals()?;
|
||||||
Ok(())
|
Ok(())
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -270,7 +270,7 @@ async fn run() -> Result<(), Error> {
|
|||||||
let init_result: Result<(), Error> = try_block!({
|
let init_result: Result<(), Error> = try_block!({
|
||||||
proxmox_rest_server::register_task_control_commands(&mut commando_sock)?;
|
proxmox_rest_server::register_task_control_commands(&mut commando_sock)?;
|
||||||
commando_sock.spawn()?;
|
commando_sock.spawn()?;
|
||||||
proxmox_rest_server::server_state_init()?;
|
proxmox_rest_server::catch_shutdown_and_reload_signals()?;
|
||||||
Ok(())
|
Ok(())
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ fn worker_task_abort() -> Result<(), Error> {
|
|||||||
|
|
||||||
let init_result: Result<(), Error> = try_block!({
|
let init_result: Result<(), Error> = try_block!({
|
||||||
proxmox_rest_server::register_task_control_commands(&mut commando_sock)?;
|
proxmox_rest_server::register_task_control_commands(&mut commando_sock)?;
|
||||||
proxmox_rest_server::server_state_init()?;
|
proxmox_rest_server::catch_shutdown_and_reload_signals()?;
|
||||||
Ok(())
|
Ok(())
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user