diff --git a/.github/workflows/container.yml b/.github/workflows/container.yml index 63ba4c80..4edd763c 100644 --- a/.github/workflows/container.yml +++ b/.github/workflows/container.yml @@ -374,56 +374,7 @@ jobs: cache-to: type=gha,mode=max file: Dockerfile-client - build-macos-x86_64: - runs-on: macos-13 - permissions: - contents: read - packages: write - id-token: write - - - - steps: - - uses: actions/checkout@v3 - with: - submodules: recursive - - - - name: Set up Go - uses: actions/setup-go@v4 - with: - go-version: 'stable' - - - name: package-gt - run: |- - sudo mkdir -pv /opt/homebrew/opt - brew install make llvm@16 binutils ninja - pip3 install --upgrade setuptools - curl -LOJ https://chrome-infra-packages.appspot.com/dl/gn/gn/mac-amd64/+/latest - unzip gn-mac-amd64.zip - chmod +x gn && mv gn /usr/local/opt/llvm@16/bin/ - sudo ln -s /usr/local/opt/llvm@16 /opt/homebrew/opt/llvm - ln -s /usr/local/opt/llvm@16 /usr/local/opt/llvm - echo 'export PATH="/usr/local/opt/llvm@16/bin:$PATH"' >> ~/.bash_profile - export PATH="/usr/local/opt/make/libexec/gnubin:$PATH" - echo 'export PATH="/usr/local/opt/binutils/bin:$PATH"' >> ~/.bash_profile - source ~/.bash_profile - mv /usr/local/opt/llvm/bin/llvm-libtool-darwin /usr/local/opt/llvm/bin/libtool - rustup target add x86_64-apple-darwin aarch64-apple-darwin - cd ./libcs && TARGET=x86_64-apple-darwin GOOS=darwin GOARCH=amd64 arch -arch x86_64 make release_lib - cargo build --target x86_64-apple-darwin -r - cd .. - mkdir -p release - cp target/x86_64-apple-darwin/release/gt release/gt-macos-x86_64 - - - name: Archive GT artifacts - uses: actions/upload-artifact@v3 - with: - name: gt-macos-x86_64 - path: | - release/* - - build-macos-arm64: + build-macos: runs-on: macos-14 permissions: contents: read @@ -451,7 +402,7 @@ jobs: - name: package-gt run: |- - brew install make llvm@16 binutils ninja + brew install llvm@16 ninja curl -LOJ https://chrome-infra-packages.appspot.com/dl/gn/gn/mac-amd64/+/latest unzip gn-mac-amd64.zip chmod +x gn && mv gn /opt/homebrew/opt/llvm@16/bin/ @@ -462,15 +413,19 @@ jobs: source ~/.bash_profile mv /opt/homebrew/opt/llvm/bin/llvm-libtool-darwin /opt/homebrew/opt/llvm/bin/libtool rustup target add x86_64-apple-darwin aarch64-apple-darwin - cd ./libcs && TARGET=aarch64-apple-darwin GOOS=darwin GOARCH=arm64 arch -arch arm64 make release_lib - cargo build --target aarch64-apple-darwin -r + cd ./libcs + TARGET=aarch64-apple-darwin GOOS=darwin GOARCH=arm64 arch -arch arm64 make release_lib + TARGET=x86_64-apple-darwin GOOS=darwin GOARCH=amd64 arch -arch x86_64 make release_lib cd .. + cargo build --target aarch64-apple-darwin -r + cargo build --target x86_64-apple-darwin -r mkdir -p release cp target/aarch64-apple-darwin/release/gt release/gt-macos-aarch64 + cp target/x86_64-apple-darwin/release/gt release/gt-macos-x86_64 - name: Archive GT artifacts uses: actions/upload-artifact@v3 with: - name: gt-macos-aarch64 + name: gt-macos path: | release/* diff --git a/bin/src/main.rs b/bin/src/main.rs index 1b8db683..72b850ad 100644 --- a/bin/src/main.rs +++ b/bin/src/main.rs @@ -102,13 +102,7 @@ fn main() { } } - let mut args = env::args(); - if args.len() == 0 { - error!("no program provided"); - return; - } - let program = args.next().unwrap(); - let m = manager::Manager::new(program, manager_args); + let m = manager::Manager::new(manager_args); info!("GT"); if let Err(e) = m.run_manager() { error!("GT Manager error: {:?}", e); diff --git a/bin/src/manager.rs b/bin/src/manager.rs index 87e4ad42..29832b75 100644 --- a/bin/src/manager.rs +++ b/bin/src/manager.rs @@ -73,16 +73,14 @@ enum ProcessConfigEnum { } pub struct Manager { - program: String, args: ManagerArgs, cmds: Arc>>, configs: Arc>>>, } impl Manager { - pub fn new(program: String, args: ManagerArgs) -> Self { + pub fn new(args: ManagerArgs) -> Self { Self { - program, args, cmds: Arc::new(Mutex::new(HashMap::new())), configs: Arc::new(Mutex::new(None)), @@ -184,12 +182,11 @@ impl Manager { } fn sync_run( - program: String, cmd_map: Arc>>, configs: Vec, sub_cmd: &'static str, ) -> BoxFuture<'static, Result<()>> { - async move { Self::run(program, cmd_map, configs, sub_cmd).await }.boxed() + async move { Self::run(cmd_map, configs, sub_cmd).await }.boxed() } async fn handle_stdout( @@ -265,7 +262,6 @@ impl Manager { } async fn run( - program: String, cmd_map: Arc>>, configs: Vec, sub_cmd: &'static str, @@ -295,7 +291,7 @@ impl Manager { .into_iter() .map(|config| { info!("run {sub_cmd} config: {:?}", config); - let mut cmd = Command::new(program.clone()); + let mut cmd = Command::new(env::current_exe()?); cmd.arg(sub_cmd); cmd_config!(cmd, config); cmd.spawn() @@ -306,7 +302,6 @@ impl Manager { let ready_done_counter = Arc::new(AtomicUsize::new(cmds.len())); for (mut c, config) in cmds { - let program = program.clone(); let cmd_map = cmd_map.clone(); let ready_done_counter = ready_done_counter.clone(); tokio::spawn(async move { @@ -327,11 +322,10 @@ impl Manager { process_shutdown(config.clone(), cmd, send_graceful_shutdown).await; } let reconnect = async { - let program = program.clone(); let cmds = cmd_map.clone(); let config = config.clone(); if let Err(e) = - Self::sync_run(program, cmds, vec![config.clone()], sub_cmd).await + Self::sync_run(cmds, vec![config.clone()], sub_cmd).await { error!("{sub_cmd} ({config:?}) reconnect sync_run failed: {:?}", e); } @@ -387,7 +381,15 @@ impl Manager { loop { info!("restarting {sub_cmd} ({config:?}) in {wait_time:?}"); tokio::time::sleep(wait_time).await; - let mut cmd = Command::new(&program); + let exe = match env::current_exe() { + Ok(exe) => exe, + Err(e) => { + wait_time = Duration::from_secs(3 * 60); + error!("failed to restart {sub_cmd} ({config:?}): {:?}", e); + continue; + } + }; + let mut cmd = Command::new(exe); cmd.arg(sub_cmd); cmd_config!(cmd, config); match cmd.spawn() { @@ -426,7 +428,6 @@ impl Manager { } if !server_config.is_empty() { Self::run( - self.program.clone(), self.cmds.clone(), server_config, "sub-server", @@ -437,7 +438,6 @@ impl Manager { if !client_config.is_empty() { Self::run( - self.program.clone(), self.cmds.clone(), client_config, "sub-client", diff --git a/libcs/client/peerproc.go b/libcs/client/peerproc.go index abf87309..de378594 100644 --- a/libcs/client/peerproc.go +++ b/libcs/client/peerproc.go @@ -75,7 +75,11 @@ type opGetOfferSDP struct { } func (pt *peerProcessTask) init() (err error) { - cmd := exec.Command(os.Args[0], "sub-p2p") + execPath, err := os.Executable() + if err != nil { + return + } + cmd := exec.Command(execPath, "sub-p2p") pt.stdin, err = cmd.StdinPipe() if err != nil { return diff --git a/libcs/web/server/util/system.go b/libcs/web/server/util/system.go index 175afb90..64c9d3a3 100644 --- a/libcs/web/server/util/system.go +++ b/libcs/web/server/util/system.go @@ -36,8 +36,6 @@ func SendSignal(signal string) (err error) { cmd = exec.Command(execPath, "-s", "restart") case "stop": cmd = exec.Command(execPath, "-s", "stop") - case "kill": - cmd = exec.Command(execPath, "-s", "kill") default: err = errors.New("unknown signal") return diff --git a/libcs/web/server/util/system_win.go b/libcs/web/server/util/system_win.go index ace9bcbc..17f06586 100644 --- a/libcs/web/server/util/system_win.go +++ b/libcs/web/server/util/system_win.go @@ -36,14 +36,12 @@ func SendSignal(signal string) (err error) { cmd = exec.Command(execPath, "-s", "restart") case "stop": cmd = exec.Command(execPath, "-s", "stop") - case "kill": - cmd = exec.Command(execPath, "-s", "kill") default: err = errors.New("unknown signal") return } cmd.SysProcAttr = &syscall.SysProcAttr{ - // Setpgid: true + CreationFlags: syscall.CREATE_NEW_PROCESS_GROUP, } err = cmd.Start() if err != nil {