- 自动识别 JDK 8/11/17/21 与宿主机 CPU、可用内存;容器内以 cgroup 限额为准;堆默认取可用内存 50%,-Xms 与 -Xmx 同值 - 按版本分支生成参数:JDK 8 用 -Xloggc 一组,JDK 9+ 用 -Xlog:; 堆超过 30g 时自动省略压缩指针参数 - 支持 --jdk/--java/--heap/--xms/--env/--gc-log/--heap-dump-on-oom/ --print-flags/--dry-run;jar 之后的参数原样交给应用 - 前台运行:stdio 直连、退出码透传、SIGINT/SIGTERM 转发给 JVM - BuiltinRequest 增加 Stdin,使内置命令可以读取调用方输入 - 修正帮助中的用法行重复(自定义 Usage 不再追加通用透传尾巴) - 文档:新增 README.java.md,主 README 补充导航与示例
41 lines
857 B
Go
41 lines
857 B
Go
//go:build !windows
|
|
|
|
package executor
|
|
|
|
import (
|
|
"os"
|
|
"os/exec"
|
|
"os/signal"
|
|
"syscall"
|
|
)
|
|
|
|
// forwardSignals relays interrupts to the JVM so its shutdown hooks run
|
|
// instead of the process being torn down abruptly.
|
|
//
|
|
// The JVM shares kopsc's process group, so a terminal Ctrl+C already reaches
|
|
// it; this relay also covers the case where a supervisor signals kopsc alone.
|
|
// The returned stop function must be called once the child has been waited for.
|
|
func forwardSignals(cmd *exec.Cmd) (stop func()) {
|
|
signals := make(chan os.Signal, 1)
|
|
signal.Notify(signals, os.Interrupt, syscall.SIGTERM)
|
|
|
|
done := make(chan struct{})
|
|
go func() {
|
|
for {
|
|
select {
|
|
case sig := <-signals:
|
|
if cmd.Process != nil {
|
|
_ = cmd.Process.Signal(sig)
|
|
}
|
|
case <-done:
|
|
return
|
|
}
|
|
}
|
|
}()
|
|
|
|
return func() {
|
|
signal.Stop(signals)
|
|
close(done)
|
|
}
|
|
}
|