proxmox-rest-server: allow to catch SIGINT and SIGHUP separately
And make ServerState private.
This commit is contained in:
parent
11148dce43
commit
fd1b65cc3c
|
@ -9,18 +9,18 @@ use tokio::signal::unix::{signal, SignalKind};
|
||||||
use pbs_tools::broadcast_future::BroadcastData;
|
use pbs_tools::broadcast_future::BroadcastData;
|
||||||
|
|
||||||
#[derive(PartialEq, Copy, Clone, Debug)]
|
#[derive(PartialEq, Copy, Clone, Debug)]
|
||||||
pub enum ServerMode {
|
enum ServerMode {
|
||||||
Normal,
|
Normal,
|
||||||
Shutdown,
|
Shutdown,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct ServerState {
|
struct ServerState {
|
||||||
pub mode: ServerMode,
|
mode: ServerMode,
|
||||||
pub shutdown_listeners: BroadcastData<()>,
|
shutdown_listeners: BroadcastData<()>,
|
||||||
pub last_worker_listeners: BroadcastData<()>,
|
last_worker_listeners: BroadcastData<()>,
|
||||||
pub worker_count: usize,
|
worker_count: usize,
|
||||||
pub internal_task_count: usize,
|
internal_task_count: usize,
|
||||||
pub reload_request: bool,
|
reload_request: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
|
@ -34,12 +34,8 @@ lazy_static! {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Listen to ``SIGINT`` and ``SIGHUP`` signals
|
/// Listen to ``SIGINT`` for server shutdown
|
||||||
///
|
pub fn catch_shutdown_signal() -> Result<(), Error> {
|
||||||
/// * ``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())?;
|
||||||
|
|
||||||
|
@ -56,6 +52,12 @@ pub fn catch_shutdown_and_reload_signals() -> Result<(), Error> {
|
||||||
|
|
||||||
tokio::spawn(task.map(|_| ()));
|
tokio::spawn(task.map(|_| ()));
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Listen to ``SIGHUP`` for server reload
|
||||||
|
pub fn catch_reload_signal() -> Result<(), Error> {
|
||||||
|
|
||||||
let mut stream = signal(SignalKind::hangup())?;
|
let mut stream = signal(SignalKind::hangup())?;
|
||||||
|
|
||||||
let future = async move {
|
let future = async move {
|
||||||
|
|
|
@ -127,7 +127,8 @@ 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::catch_shutdown_and_reload_signals()?;
|
proxmox_rest_server::catch_shutdown_signal()?;
|
||||||
|
proxmox_rest_server::catch_reload_signal()?;
|
||||||
Ok(())
|
Ok(())
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -270,7 +270,8 @@ 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::catch_shutdown_and_reload_signals()?;
|
proxmox_rest_server::catch_shutdown_signal()?;
|
||||||
|
proxmox_rest_server::catch_reload_signal()?;
|
||||||
Ok(())
|
Ok(())
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -53,7 +53,6 @@ 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::catch_shutdown_and_reload_signals()?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue