proxmox-rest-server: improve logging

And rename server_state_init() into catch_shutdown_and_reload_signals().
This commit is contained in:
Dietmar Maurer 2021-09-29 14:34:25 +02:00
parent a0ffd4a413
commit 38da8ca1bc
6 changed files with 22 additions and 12 deletions

View File

@ -152,9 +152,9 @@ impl Reloader {
self.do_reexec(new_args)
})
{
Ok(Ok(())) => eprintln!("do_reexec returned!"),
Ok(Err(err)) => eprintln!("do_reexec failed: {}", err),
Err(_) => eprintln!("panic in re-exec"),
Ok(Ok(())) => log::error!("do_reexec returned!"),
Ok(Err(err)) => log::error!("do_reexec failed: {}", err),
Err(_) => log::error!("panic in re-exec"),
}
}
Ok(ForkResult::Parent { child }) => {
@ -307,7 +307,7 @@ where
wait_service_is_not_state(service_name, "reloading").await?;
}
log::info!("daemon shut down...");
log::info!("daemon shut down.");
Ok(())
}
@ -360,6 +360,11 @@ pub enum SystemdNotify {
/// Tells systemd the startup state of the service (see: ``man sd_notify``)
pub fn systemd_notify(state: SystemdNotify) -> Result<(), Error> {
if let SystemdNotify::Ready = &state {
log::info!("service is ready");
}
let message = match state {
SystemdNotify::Ready => CString::new("READY=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),
);
}
Ok(())
}

View File

@ -96,7 +96,6 @@ pub fn our_ctrl_sock() -> String {
static SHUTDOWN_REQUESTED: AtomicBool = AtomicBool::new(false);
pub fn request_shutdown() {
println!("request_shutdown");
SHUTDOWN_REQUESTED.store(true, Ordering::SeqCst);
crate::server_shutdown();
}

View File

@ -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 future = async move {
while stream.recv().await.is_some() {
println!("got shutdown request (SIGINT)");
log::info!("got shutdown request (SIGINT)");
SERVER_STATE.lock().unwrap().reload_request = false;
crate::request_shutdown();
}
@ -55,7 +60,7 @@ pub fn server_state_init() -> Result<(), Error> {
let future = async move {
while stream.recv().await.is_some() {
println!("got reload request (SIGHUP)");
log::info!("got reload request (SIGHUP)");
SERVER_STATE.lock().unwrap().reload_request = true;
crate::request_shutdown();
}
@ -78,7 +83,7 @@ pub fn is_reload_request() -> bool {
pub fn server_shutdown() {
let mut data = SERVER_STATE.lock().unwrap();
println!("SET SHUTDOWN MODE");
log::info!("request_shutdown");
data.mode = ServerMode::Shutdown;

View File

@ -127,7 +127,7 @@ async fn run() -> Result<(), Error> {
let init_result: Result<(), Error> = try_block!({
proxmox_rest_server::register_task_control_commands(&mut commando_sock)?;
commando_sock.spawn()?;
proxmox_rest_server::server_state_init()?;
proxmox_rest_server::catch_shutdown_and_reload_signals()?;
Ok(())
});

View File

@ -270,7 +270,7 @@ async fn run() -> Result<(), Error> {
let init_result: Result<(), Error> = try_block!({
proxmox_rest_server::register_task_control_commands(&mut commando_sock)?;
commando_sock.spawn()?;
proxmox_rest_server::server_state_init()?;
proxmox_rest_server::catch_shutdown_and_reload_signals()?;
Ok(())
});

View File

@ -53,7 +53,7 @@ fn worker_task_abort() -> Result<(), Error> {
let init_result: Result<(), Error> = try_block!({
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(())
});