rails守护进程

rails s -p 16052 -d
ruby script/server -p 16050 -d

启动守护进程后,当前路径变为 根路径/ ,所有相对路径的写法就会有问题(Dir.pwd变为 /)

在 puma.rb里 设置 daemonize true ,当前路径还是 项目路径

image.png

The Puma 5.0 release removed daemonization. For older versions and alternatives, continue reading.

https://blog.csdn.net/xingchao_1995/article/details/60151552


puts 'parent'
puts "pid:#{Process.pid}"

exit if fork

puts "fork1,pid:#{Process.pid}"

Process.setsid 

puts "setsid,pid:#{Process.pid}"

exit if fork

puts "fork2,pid:#{Process.pid}"
puts "now_dir:#{Dir.pwd}"
Process.daemon

File.open("/Users/rcc/Desktop/process.txt",'wb'){|f| f.puts("pid:#{Process.pid}")}


File.open("/Users/rcc/Desktop/process.txt",'a+'){|f| f.puts(Dir.pwd)}


while true
  File.open("/Users/rcc/Desktop/process.txt",'a+'){|f| f.puts(Time.now.to_i)}
  sleep(1)
end





你可能感兴趣的:(rails守护进程)