1#[cfg(feature = "logger")]
2pub mod logger;
3
4#[cfg(feature = "panic_handle")]
5pub mod painc;
6
7#[cfg(feature = "config")]
8pub mod config;
9
10pub mod app_info;
11
12pub mod time;
13pub use anyhow;
14pub use chrono;
15pub use serde;
16pub use time::*;
17
18pub type AppResult<T = ()> = std::result::Result<T, anyhow::Error>;
19
20#[cfg(feature = "logger")]
21use std::time::Duration;
22#[cfg(target_os = "linux")]
23use tokio::process::Command;
24
25#[cfg(feature = "logger")]
27pub fn after_app_exist(sec: u8) {
28 tokio::spawn(async move {
29 log::info!("程序退出,{} 秒后重启", sec);
30 tokio::time::sleep(Duration::from_secs(sec as u64)).await;
31 std::process::exit(1);
32 });
33}
34
35#[cfg(feature = "logger")]
37pub fn after_reboot(sec: u8) {
38 #[cfg(target_os = "linux")]
39 {
40 tokio::spawn(async move {
41 log::info!("程序重启,{} 秒后重启", sec);
42 tokio::time::sleep(Duration::from_secs(sec as u64)).await;
43 let status = Command::new("reboot").status().await.unwrap();
44 if status.success() {
45 log::info!("程序重启成功");
46 } else {
47 log::error!("程序重启失败");
48 }
49 });
50 }
51 #[cfg(target_os = "windows")]
52 log::warn!("windows系统不支持自动重启:{}", sec)
53}