How to stop a Daemon Server in Rails?

前端 未结 15 563
灰色年华
灰色年华 2020-12-12 09:52

I am running my rails application using the following

  $script/server -d webrick 

on my Ubuntu system , above command run the webrick s

相关标签:
15条回答
  • 2020-12-12 10:13

    The only proper way to kill the Ruby on Rails default server (which is WEBrick) is:

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

    If you are running Mongrel, this is sufficient:

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

    Use kill -9 if your daemon hung. Remember the implications of kill -9 - if the data kept in Active Record caches weren't flushed to disk, you will lose your data. (As I recently did)

    0 讨论(0)
  • 2020-12-12 10:14

    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

    0 讨论(0)
  • 2020-12-12 10:16

    if it can be useful, on linux you can find which process is using a port (in this case 3000) you can use:

    lsof -i :3000

    it'll return the pid too

    0 讨论(0)
  • 2020-12-12 10:17

    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)
    
    0 讨论(0)
  • 2020-12-12 10:20

    The process id of the daemon server is stored in your application directory tmp/pids/. You can use your standard kill process_id with the information you find there.

    0 讨论(0)
  • 2020-12-12 10:20
    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.

    0 讨论(0)
提交回复
热议问题