Programing

Rails에서 데몬 서버를 중지하는 방법은 무엇입니까?

lottogame 2020. 10. 18. 08:18
반응형

Rails에서 데몬 서버를 중지하는 방법은 무엇입니까?


다음을 사용하여 레일 애플리케이션을 실행하고 있습니다.

  $script/server -d webrick 

내 Ubuntu 시스템에서 위의 명령은 백그라운드에서 webrick 서버를 실행합니다. kill 명령을 사용하여 프로세스를 종료 할 수 있습니다.

  $kill pid

Rails는 백그라운드 실행 데몬 서버를 중지하는 명령을 제공합니까?

서버를 시작하기 위해 레일에서 제공하는 것과 같습니다. 감사합니다.

편집 데몬 서버를 시작하는 것이 적절할 때? 실시간 시나리오가 도움이 될 것입니다.


레이크 작업은 어떻습니까?

desc 'stop rails'
task :stop do
    pid_file = 'tmp/pids/server.pid'
    pid = File.read(pid_file).to_i
    Process.kill 9, pid
    File.delete pid_file
end

레이크 정지 또는 sudo 레이크 정지로 실행


유용 할 수 있다면, 리눅스에서 어떤 프로세스가 포트 (이 경우 3000)를 사용하고 있는지 찾을 수 있습니다.

lsof -i : 3000

그것은 너무 pid를 반환 할 것입니다


Ryan이 말한 것처럼 :

원하는 pid는 tmp / pids /에 있습니다.

아마도 server.pid는 원하는 파일입니다.

kill -9 $(cat tmp/pids/server.pid)데몬 화 된 서버를 종료하기 위해 실행할 수 있어야 합니다.


데몬 서버의 프로세스 ID는 애플리케이션 디렉토리 tmp / pids /에 저장됩니다. kill process_id거기에서 찾은 정보로 표준 사용할 수 있습니다 .


유일한 적절한 (에 WEBrick입니다) 레일 기본 서버에 루비를 죽이는 방법입니다 :

kill -INT $(cat tmp/pids/server.pid)

Mongrel을 실행중인 경우 다음으로 충분합니다.

kill $(cat tmp/pids/server.pid)

kill -9데몬이 중단 된 경우 사용 합니다. 의미를 기억하십시오. kill -9Active Record 캐시에 보관 된 데이터가 디스크로 플러시되지 않으면 데이터가 손실됩니다. (최근처럼)


터미널에서 프로세스 ID (PID)를 찾으십시오.

$ lsof -wni tcp:3000

그런 다음 PID 열의 번호를 사용하여 프로세스를 종료합니다.

$ kill -9 <PID>

pguardiarioSIGKILL(권장) 대신 사용하기 때문에 그의 구현이 약간 위험하지만 나를 이겼습니다 SIGINT. 다음은 개발 프로젝트로 가져 오는 갈퀴 작업입니다.

lib / tasks / stopserver.rake

desc 'stop server'
task :stopserver do
  pid_file = 'tmp/pids/server.pid'
  if File.file?(pid_file)
    print "Shutting down WEBrick\n"
    pid = File.read(pid_file).to_i
    Process.kill "INT", pid
  end
  File.file?(pid_file) && File.delete(pid_file)
end

이것은 pidfile이 존재하는 경우에만 서버에 인터럽트를 발행합니다. 서버가 실행되고 있지 않아도보기 흉한 오류가 발생하지 않으며 실제로 서버가 종료되고 있는지 알려줍니다.

서버가이 작업을 사용하여 종료하지 않으려는 경우 줄 뒤에 다음 줄을 추가 Process.kill "INT"하고이 버그가 수정 된 커널로 업그레이드하십시오.

Process.kill "CONT", pid

(모자 팁 : jackr )


다음 명령을 실행하십시오.

locate tmp/pids/server.pid

output: Complete path of this file. Check your project directory name to find your concerned file if multiple files are shown in list.

Then run this command:

rm -rf [complete path of tmp/pids/server.pid file]

A Ruby ticket, http://bugs.ruby-lang.org/issues/4777, suggests it's a kernel (Linux) bug. They give a work around (essentially equivalent to the Ctrl-C/Ctrl-Z one), for use if you've demonized the server:

  1. kill -INT cat tmp/pids/server.pid
  2. kill -CONT cat tmp/pids/server.pid

This seems to cause the original INT signal to be processed, possibly allowing data flush and so on.


Here I leave a bash function which, if pasted in you .bashrc or .zshrc will alloy you do things like:

rails start # To start the server in development environment
rails start production # To start the server in production environment
rails stop # To stop the server
rails stop -9 # To stop the server sending -9 kill signal
rails restart # To restart the server in development environment
rails restart production # To restart the server in production environment
rails whatever # Will send the call to original rails command

Here it is the function:

function rails() {
  if [ "$1" = "start" ]; then
     if [ "$2" = "" ]; then
        RENV="development"
     else
        RENV="$2"
     fi
     rails server -d -e "$RENV"
     return 0
  elif [ "$1" = "stop" ]; then
     if [ -f tmp/pids/server.pid ]; then
        kill $2 $(cat tmp/pids/server.pid)
        return 0
     else
        echo "It seems there is no server running or you are not in a rails project root directory"
        return 1
     fi
  elif [ "$1" = "restart" ]; then
     rails stop && rails start $2
  else
     command rails $@
  fi;
}

More information in the blog post I wrote about it.


i don't think it does if you use -d. I'd just kill the process.

In the future, just open up another terminal window instead and use the command without -d, it provides some really useful debugging output.

If this is production, use something like passenger or thin, so that they're easy to stop the processes or restart the servers


one-liner:  kill -INT `ps -e | grep ruby | awk '{print $1}'`

ps -e lists every process on the system
grep ruby searches that output for the ruby process
awk passes the first argument of that output (the pid) to kill -INT.


Try it with echo instead of kill if you just want to see the PID.


if kill process not works, then delete file server.pid from MyRailsApp/tmp/pids/


I came here because I were trying to (unsuccesfully) stop with a normal kill, and thought I'd being doing something wrong.

A kill -9 is the only sure way to stop a ruby on rails server? What!? Do you know the implications of this? Can be a disaster...


You can start your server in the background by adding -d to your command. For instance:

puma -d

To stop it, just kill whatever process is running on port 3000:

kill $(cat tmp/pids/server.pid)

참고URL : https://stackoverflow.com/questions/1164091/how-to-stop-a-daemon-server-in-rails

반응형