-
Notifications
You must be signed in to change notification settings - Fork 58
Expand file tree
/
Copy pathmain.rs
More file actions
77 lines (63 loc) · 1.79 KB
/
main.rs
File metadata and controls
77 lines (63 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#![cfg_attr(
all(not(debug_assertions), not(feature = "win_service")),
windows_subsystem = "windows"
)]
extern crate alloc;
use anyhow::Result;
#[cfg(all(feature = "win_service", windows))]
#[macro_use]
extern crate windows_service;
#[cfg(all(feature = "win_service", windows))]
mod win_service;
#[cfg(all(debug_assertions, feature = "tokio-console"))]
use console_subscriber;
pub use pb::config::Config;
pub use transport::Transport;
mod agent;
mod assets;
mod install;
mod portal;
mod printer;
mod run;
mod shell;
mod task;
#[cfg(test)]
mod tests;
mod version;
#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<()> {
#[cfg(all(debug_assertions, feature = "tokio-console"))]
{
console_subscriber::init();
println!("Tokio Console active.");
}
run::init_logger();
#[cfg(feature = "install")]
{
#[cfg(debug_assertions)]
log::info!("beginning installation");
if std::env::args().any(|arg| arg == "install") {
return install::install().await;
}
}
#[cfg(all(feature = "win_service", windows))]
match windows_service::service_dispatcher::start("imix", ffi_service_main) {
Ok(_) => {
return Ok(());
}
Err(_err) => {
#[cfg(debug_assertions)]
log::error!("Failed to start service (running as exe?): {_err}");
}
}
run::run_agent().await
}
// ============ Windows Service =============
#[cfg(all(feature = "win_service", windows))]
define_windows_service!(ffi_service_main, service_main);
#[cfg(all(feature = "win_service", windows))]
#[tokio::main(flavor = "current_thread")]
async fn service_main(arguments: Vec<std::ffi::OsString>) {
crate::win_service::handle_service_main(arguments);
let _ = run::run_agent().await;
}