mirror of
https://github.com/Corfirean/coa-server-manager.git
synced 2026-11-21 03:25:56 +00:00
driver::run now calls coa-core::launcher::ops::run in-process instead of running Scripts/manage.py through launcher_bridge.py. Failures carry a typed code (Error::Service) instead of being guessed from stderr text. Moved into the launcher: realm profiles (realm id, name and databases from Settings/realm-profile.json), extra worlds sharing the main database, the shared world startup deadline and console readiness check, the owned-world check on shutdown, force-stop-all, and an environment block without AC_REALM_SERVER_PORT for update validation. The world supervisor is Scripts/coa-launcher.exe when the repack ships it, otherwise manage.py watch-world. Extra worlds get an unmodified manage.py. The realm patch of manage.py stays for the repack's own .bat files. Verified with examples/manager_launcher_e2e on a disposable repack. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
278 lines
10 KiB
Rust
278 lines
10 KiB
Rust
//! Starting a long-running service process that inherits exactly two handles: its log (as stdout and stderr) and
|
|
//! NUL (as stdin).
|
|
//!
|
|
//! `std::process::Command` on Windows lets a child inherit every inheritable handle of the parent. A server
|
|
//! started that way keeps open whatever the launcher's caller had open (the Manager's pipes, a test's log file),
|
|
//! for as long as the server runs. Python's subprocess passes an explicit handle list; this does the same with
|
|
//! `PROC_THREAD_ATTRIBUTE_HANDLE_LIST`.
|
|
|
|
use std::path::Path;
|
|
|
|
#[cfg(not(windows))]
|
|
use crate::error::Error;
|
|
use crate::error::Result;
|
|
|
|
/// A started process. The handle is closed when this is dropped; the process keeps running.
|
|
pub struct Proc {
|
|
pub pid: u32,
|
|
#[cfg(windows)]
|
|
handle: windows_sys::Win32::Foundation::HANDLE,
|
|
}
|
|
|
|
unsafe impl Send for Proc {}
|
|
|
|
/// One argument quoted the way the Microsoft C runtime parses it back.
|
|
fn quote(arg: &str) -> String {
|
|
if !arg.is_empty() && !arg.contains([' ', '\t', '"']) {
|
|
return arg.to_string();
|
|
}
|
|
let mut out = String::from('"');
|
|
let mut backslashes = 0;
|
|
for c in arg.chars() {
|
|
match c {
|
|
'\\' => backslashes += 1,
|
|
'"' => {
|
|
out.push_str(&"\\".repeat(backslashes * 2 + 1));
|
|
out.push('"');
|
|
backslashes = 0;
|
|
}
|
|
_ => {
|
|
out.push_str(&"\\".repeat(backslashes));
|
|
out.push(c);
|
|
backslashes = 0;
|
|
}
|
|
}
|
|
}
|
|
out.push_str(&"\\".repeat(backslashes * 2));
|
|
out.push('"');
|
|
out
|
|
}
|
|
|
|
pub fn command_line(exe: &Path, args: &[&str]) -> String {
|
|
let mut parts = vec![quote(&exe.to_string_lossy())];
|
|
parts.extend(args.iter().map(|a| quote(a)));
|
|
parts.join(" ")
|
|
}
|
|
|
|
/// This process's environment without the `remove` names (compared without case, as Windows does), sorted as
|
|
/// Windows expects, as a `CreateProcessW` block: `NAME=value |