2017-11-21 1 views
2

외부 쉘 명령을 실행하는 작업 내에서 일부 처리를하고 있습니다. 이 명령은 완료하는 데 몇 시간이 걸리는 스크립트를 실행 중입니다.sidekiq에 의해 생성 된 프로세스는 sidekiq이 멈 추면 중지됩니다.

spawndetach을 사용하여 스크립트를 시작한 후 kill -15 신호를 사용하여 sidekiq 작업을 종료하면 스크립트가 실행을 중지합니다. 이 동작은 spawn 명령이 sidekiq에 의해 시작된 경우에만 발생합니다. irb에서 콘솔을 닫은 경우가 아닙니다. 그래서 어떻게 든 그것은 여전히 ​​보이는 sidekiq에 묶여 있습니다 -하지만 그것을 피하는 이유와 방법?.

test.sh

#!/bin/bash 

for a in `seq 1000` ; do 
    echo "$a " 
    sleep 1 
done 

spawn_test_job.rb

module WorkerJobs 
    class SpawnTestJob < CountrySpecificWorker 
    sidekiq_options :queue => :my_jobs, :retry => false 

    def perform version 
     logfile = "/home/deployer/test_#{version}.log" 
     pid = spawn(
     "cd /home/deployer && 
      ./test.sh 
     ", 
     [:out, :err] => logfile 
    ) 
     Process.detach(pid) 
    end 

    end 
end 

나는 일 WorkerJobs::SpawnTestJob.perform_async(1)을 대기열에 내가 꼬리가 test_1.log가 내 카운터가 계속 볼 수 있다면. 그러나 sidekiq에게 -15를 보내면 카운터가 멈추고 스크립트 pid가 사라집니다.

+0

나는 [이 답변] (https://stackoverflow.com/a/31572431/3784008) 화재와 루비에서 자식 프로세스를 잊을 수있는 가장 적절한 방법을 결정하는 시점의 흐름도 다음 좋습니다. – anothermh

+0

헤이 @anothermh, 꽤 멋진 다이어그램. 공유해 주셔서 감사합니다. 나는 그것에 따라 프로세스를 산란하지만 작동하지 않습니다. – radubogdan

답변

1

디버깅 시간이 지나면 필자는 systemd가이 문제를 일으키는 것을 발견했습니다. sidekiq 내부에서 시작된 프로세스는 sidekiq가 cgroup이고 프로세스를 종료 할 때마다 기본값 killmodecontrol-group입니다.

  • https://www.freedesktop.org/wiki/Software/systemd/ControlGroupInterface/
  • 01 :

    [email protected]:~$ ps -efj | grep test.sh 
    UID  PID PPID PGID SID C STIME TTY   TIME CMD 
    deployer 16679 8455 16678 8455 0 12:59 pts/0 00:00:00 grep --color=auto test.sh 
    deployer 24904 30861 24904 30861 0 12:52 ?  00:00:00 sh -c cd /home/deployer &&   ./test.sh 
    deployer 24906 24904 24904 30861 0 12:52 ?  00:00:00 /bin/bash ./test.sh 
    
    deployer 6382  1 6382 6382 38 12:53 ?  00:02:14 sidekiq 4.2.10 my_proj [8 of 8 busy] 
    deployer 7787  1 7787 7787 30 12:46 ?  00:04:07 sidekiq 4.2.10 my_proj [6 of 8 busy] 
    deployer 13680  1 13680 13680 29 12:49 ?  00:03:08 sidekiq 4.2.10 my_proj [8 of 8 busy] 
    deployer 14372  1 14372 14372 38 12:49 ?  00:03:48 sidekiq 4.2.10 my_proj [8 of 8 busy] 
    deployer 16719 8455 16718 8455 0 12:59 pts/0 00:00:00 grep --color=auto sidekiq 
    deployer 17678  1 17678 17678 38 12:50 ?  00:03:22 sidekiq 4.2.10 my_proj [8 of 8 busy] 
    deployer 18023  1 18023 18023 32 12:50 ?  00:02:49 sidekiq 4.2.10 my_proj [8 of 8 busy] 
    deployer 18349  1 18349 18349 34 12:43 ?  00:05:32 sidekiq 4.2.10 my_proj [8 of 8 busy] 
    deployer 18909  1 18909 18909 34 12:51 ?  00:02:53 sidekiq 4.2.10 my_proj [8 of 8 busy] 
    deployer 22956  1 22956 22956 39 12:01 ?  00:22:42 sidekiq 4.2.10 my_proj [8 of 8 busy] 
    deployer 30861  1 30861 30861 46 12:00 ?  00:27:23 sidekiq 4.2.10 my_proj [8 of 8 busy] 
    

    내가 내 sidekiq 서비스를 지시하여 문제를 해결

    cat /proc/24904/cgroup 
    11:perf_event:/ 
    10:blkio:/ 
    9:pids:/system.slice 
    8:devices:/system.slice/system-my_proj\x2dsidekiq.slice 
    7:cpuset:/ 
    6:freezer:/ 
    5:memory:/ 
    4:cpu,cpuacct:/ 
    3:net_cls,net_prio:/ 
    2:hugetlb:/ 
    1:name=systemd:/system.slice/system-my_proj\x2dsidekiq.slice/[email protected] 
    

    KillModeprocess

    참조입니다

+0

이것은 정말 좋은 정보입니다. 아래로 추적하고 추적하면 감사합니다. –

+0

@MikePerham 감사합니다. systemd에 대한 나의 경험이 제한되어 있고 새로운 init 시스템에서 sidekiq를 실행하는 데 필요한 많은 자원이 없기 때문에 그것을 추적하기가 어려웠습니다. 나는이 대답이 다른 사람들을 도울 것이거나 적어도 그들에게 systemd 문서를 더 철저하게 읽게 해주기를 바란다. – radubogdan

관련 문제