Cactus/
shutdown.rs

1use log::{info, warn};
2
3use crate::consts::messages;
4
5/// Enum representing standardized server exit codes.
6pub enum ExitCode {
7    Success,
8    Failure,
9    CtrlC,
10}
11
12/// Gracefully exits the server with an exit code.
13pub fn gracefully_exit(exit_code: ExitCode) -> ! {
14    let numerical_exit_code: i32 = match exit_code {
15        ExitCode::Success => {
16            info!("{}", *messages::SERVER_SHUTDOWN_SUCCESS);
17            0
18        }
19        ExitCode::Failure => {
20            warn!("{}", *messages::SERVER_SHUTDOWN_ERROR);
21            1
22        }
23        ExitCode::CtrlC => {
24            info!("{}", *messages::SERVER_SHUTDOWN_CTRL_C);
25            130
26        }
27    };
28
29    std::process::exit(numerical_exit_code);
30}