修改rpm打包方式,修改文件存放路径,增加先查询node后调用debug
This commit is contained in:
@@ -33,12 +33,24 @@ func terminalSize() (width, height int, err error) {
|
||||
func debug(config types.Coredump_config, command string) error {
|
||||
// 使用kubectl命令执行debug操作
|
||||
if config.Image_id != "" {
|
||||
if config.Hostname == "" {
|
||||
return errors.New("hostname must not be empty")
|
||||
// 定义要运行的 kubectl 命令
|
||||
command := "kubectl get nodes -o jsonpath='{range .items[*]}{.metadata.name} {end}'"
|
||||
|
||||
// 在 shell 中运行 kubectl 命令并读取输出
|
||||
cmd := exec.Command("bash", "-c", command)
|
||||
output, err := cmd.Output()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 将输出字符串按空格拆分为字符串切片
|
||||
nodes := strings.Split(strings.TrimSpace(string(output)), " ")
|
||||
if len(nodes) == 0 {
|
||||
return errors.New("the node list is empty")
|
||||
}
|
||||
if command == "gdb" {
|
||||
chmod := "cd" + filepath.Dir(config.Process_exe_path)
|
||||
cmd := exec.Command("kubectl", "debug", "node/"+config.Hostname, "-it", "--image="+config.Image_id, "--image-pull-policy=Never", "--", "gdb", config.Process_exe_path, "/host"+config.Storage, "-ex", chmod)
|
||||
cmd := exec.Command("kubectl", "debug", "node/"+nodes[0], "-it", "--image="+config.Image_id, "--image-pull-policy=Never", "--", "gdb", config.Process_exe_path, "/host"+config.Storage, "-ex", chmod)
|
||||
cmd.Stdin = os.Stdin
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
|
||||
@@ -174,7 +174,7 @@ func main() {
|
||||
flag.StringVar(&coredump_config.Initial_ns_pid, "P", "", "initial ns pid")
|
||||
flag.StringVar(&coredump_config.Process_ns_pid, "p", "", "process ns pid")
|
||||
flag.StringVar(&coredump_config.Process_exe_path, "E", "", "pathname of executable process")
|
||||
flag.StringVar(&coredump_config.Corepipe_config_path, "configpath", "", "configfile's path")
|
||||
flag.StringVar(&coredump_config.Corepipe_config_path, "C", "", "configfile's path")
|
||||
flag.Int64Var(&coredump_config.Timestamp, "t", 0, "the time of coredump")
|
||||
flag.StringVar(&coredump_config.GID, "g", "", "Numeric real GID of dumped process.")
|
||||
flag.IntVar(&coredump_config.Signal, "s", -1, "Number of signal causing dump")
|
||||
@@ -185,7 +185,7 @@ func main() {
|
||||
if err != nil {
|
||||
journal.Print(journal.PriErr, err.Error())
|
||||
}
|
||||
info = fmt.Sprintf("initialize command line parameters. -P=%s -p=%s -E=%s -configpath=%s -t=%d -g=%s -h=%s -s=%d -u=%s", coredump_config.Initial_ns_pid, coredump_config.Process_ns_pid, coredump_config.Process_exe_path, coredump_config.Corepipe_config_path, coredump_config.Timestamp, coredump_config.GID, coredump_config.Hostname, coredump_config.Signal, coredump_config.UID)
|
||||
info = fmt.Sprintf("initialize command line parameters. -P=%s -p=%s -E=%s -C=%s -t=%d -g=%s -h=%s -s=%d -u=%s", coredump_config.Initial_ns_pid, coredump_config.Process_ns_pid, coredump_config.Process_exe_path, coredump_config.Corepipe_config_path, coredump_config.Timestamp, coredump_config.GID, coredump_config.Hostname, coredump_config.Signal, coredump_config.UID)
|
||||
journal.Print(journal.PriInfo, info)
|
||||
coredump_config.Process_exe_path = strings.Replace(coredump_config.Process_exe_path, "!", "/", -1)
|
||||
//判断参数读取是否正确
|
||||
@@ -200,6 +200,9 @@ func main() {
|
||||
journal.Print(journal.PriErr, err.Error())
|
||||
return
|
||||
}
|
||||
if pipe_config.Storage_type == 0 {
|
||||
return
|
||||
}
|
||||
//判断硬盘使用率
|
||||
flag, err := isDiskSufficient(pipe_config)
|
||||
if err != nil && !flag {
|
||||
|
||||
1
script/coredump-tools.sh
Normal file
1
script/coredump-tools.sh
Normal file
@@ -0,0 +1 @@
|
||||
export PATH=/opt/tsg/coredump/bin
|
||||
@@ -25,15 +25,16 @@ cd ./coredump-ctl
|
||||
go build -o coredump-tool .
|
||||
cd ..
|
||||
%install
|
||||
mkdir -p %{buildroot}/etc/coredump-handler
|
||||
mkdir -p %{buildroot}/opt/tsg/coredump
|
||||
cp ./coredump-handler/coredump-handler %{buildroot}/opt/tsg/coredump
|
||||
cp ./config/config.json %{buildroot}/etc/coredump-handler
|
||||
cp ./coredump-ctl/coredump-tool %{buildroot}/opt/tsg/coredump
|
||||
%post
|
||||
echo "export PATH=/opt/tsg/coredump:$PATH" >>~/.bashrc
|
||||
mkdir -p %{buildroot}/opt/tsg/coredump/bin
|
||||
mkdir -p %{buildroot}/opt/tsg/coredump/etc
|
||||
cp ./coredump-handler/coredump-handler %{buildroot}/opt/tsg/coredump/bin
|
||||
cp ./config/config.json %{buildroot}/opt/tsg/coredump/etc
|
||||
cp ./coredump-ctl/coredump-tool %{buildroot}/opt/tsg/coredump/bin
|
||||
cp ./script/coredump-tools.sh %{buildroot}/etc/profile.d
|
||||
%files
|
||||
%defattr (-,root,root)
|
||||
/etc/coredump-handler/config.json
|
||||
/opt/tsg/coredump/coredump-handler
|
||||
/opt/tsg/coredump/coredump-tool
|
||||
/opt/tsg/coredump/etc/config.json
|
||||
/opt/tsg/coredump/bin/coredump-handler
|
||||
/opt/tsg/coredump/bin/coredump-tool
|
||||
/etc/profile.d/coredump-tools.sh
|
||||
|
||||
Reference in New Issue
Block a user