hyperlane_plugin/process/
fn.rs1use super::*;
2
3#[instrument_trace]
4pub async fn create<P, F, Fut>(pid_path: P, server_hook: F)
5where
6 P: AsRef<str>,
7 F: Fn() -> Fut + Send + Sync + 'static,
8 Fut: Future<Output = ()> + Send + 'static,
9{
10 let args: Vec<String> = args().collect();
11 debug!("Process create args{COLON_SPACE}{args:?}");
12 let mut manager: ServerManager = ServerManager::new();
13 manager
14 .set_pid_file(pid_path.as_ref())
15 .set_server_hook(server_hook);
16 let is_daemon: bool = args.len() >= 3 && args[2].to_lowercase() == DAEMON_FLAG;
17 let start_server = || async {
18 if is_daemon {
19 match manager.start_daemon().await {
20 Ok(_) => info!("Server started in background successfully"),
21 Err(error) => {
22 error!("Error starting server in background{COLON_SPACE}{error}")
23 }
24 };
25 } else {
26 info!("Server started successfully");
27 manager.start().await;
28 }
29 };
30 let stop_server = || async {
31 match manager.stop().await {
32 Ok(_) => info!("Server stopped successfully"),
33 Err(error) => error!("Error stopping server{COLON_SPACE}{error}"),
34 };
35 };
36 let hot_restart_server = || async {
37 match manager
38 .watch_detached(&["--clear", "--skip-local-deps", "-q", "-x", "run"])
39 .await
40 {
41 Ok(_) => info!("Server started successfully"),
42 Err(error) => error!("Error starting server in background{COLON_SPACE}{error}"),
43 }
44 };
45 let restart_server = || async {
46 stop_server().await;
47 start_server().await;
48 };
49 if args.len() < 2 {
50 warn!("No additional command-line parameters, default startup");
51 start_server().await;
52 return;
53 }
54 let command: String = args[1].to_lowercase();
55 match command.as_str() {
56 CMD_STOP => stop_server().await,
57 CMD_RESTART => restart_server().await,
58 CMD_HOT_RESTART => hot_restart_server().await,
59 _ => {
60 error!("Invalid command{COLON_SPACE}{command}");
61 }
62 }
63}