1 mod contants; 2 mod error; 3 mod executor; 4 mod manager; 5 mod parse; 6 mod systemctl; 7 mod task; 8 mod time; 9 mod unit; 10 11 use error::ErrorFormat; 12 use manager::{timer_manager::TimerManager, Manager}; 13 use parse::UnitParser; 14 use systemctl::listener::Systemctl; 15 16 use crate::executor::Executor; 17 18 pub struct FileDescriptor(usize); 19 20 const DRAGON_REACH_UNIT_DIR: &'static str = "/etc/reach/system/"; main()21fn main() { 22 // 初始化 23 Systemctl::init(); 24 25 let mut units_file_name = Vec::new(); 26 //读取目录里面的unit文件 27 if let Ok(entries) = std::fs::read_dir(DRAGON_REACH_UNIT_DIR) { 28 for entry in entries { 29 if let Ok(entry) = entry { 30 if let Ok(file_type) = entry.file_type() { 31 if file_type.is_file() { 32 let filename = entry.file_name().to_str().unwrap().to_string(); 33 units_file_name.push(filename); 34 } 35 } 36 } 37 } 38 } 39 40 //启动服务 41 for path in units_file_name { 42 let id = match UnitParser::from_path(&path) { 43 Ok(id) => id, 44 Err(e) => { 45 eprintln!("Err:{}", e.error_format()); 46 0 47 } 48 }; 49 if id != 0 { 50 if let Err(e) = Executor::exec(id) { 51 eprintln!("Err:{}", e.error_format()); 52 } 53 } 54 println!("Parse {} success!", path); 55 } 56 57 // 启动完服务后进入主循环 58 loop { 59 // 检查各服务运行状态 60 Manager::check_running_status(); 61 // 检查cmd进程状态 62 Manager::check_cmd_proc(); 63 // 检查计时器任务 64 TimerManager::check_timer(); 65 // 监听systemctl 66 Systemctl::ctl_listen(); 67 } 68 } 69