Rake a task to start a server in an independent thread and then destroy the thread when the task is completed?

How to start a thread in rake task, and then kill the tread when the task is completed.

Essentially, I am writing rake taskto test the jekyll site. I would like to be able to start the server, perform some other tasks, and then destroy the thread when the task is complete. Here is what I still have:

task :test_site do
  `ejekyll --server`
  `git -Xdn`
  if agree( "Clean all ignored files?")
    git -Xdf
  end
end

but unfortunately the only way to stop jekyll --serveris to use ctrl c. I would be glad to hear about the possibility of stopping the jekyll --serverrake in the estate, which does not come out of the task, but please just comment, because the question specifically asked questions about the flow and rake problems.

+3
1

Process.spawn, . , . PID, Process.kill(:QUIT, pid) , .

pid = Process.spawn(
  "ejekyll", "--server",
  out: "/dev/null",
  err: "/dev/null"
)

# you may need to add a short sleep() here

# other stuff

Process.kill(:QUIT, pid) && Process.wait

ejekyll , , , , , PID, .

+3

All Articles