Sinatra - terminate server from request

◇◆丶佛笑我妖孽 提交于 2019-12-04 14:46:02
jgnagy

This seems to come down to a problem with running code after the response is sent. Not a very easy task:

What's the fastest way for a true sinatra(ruby/rack) after_filter?

That said, it looks like you could do something like this (though I haven't tested it):

post '/terminate' do
  body "I'll be back..."
  # maybe clean things up here...
  logger.info "Received terminate request!"
  Thread.new { sleep 1; Process.kill 'INT', Process.pid }
  halt 200
end

Seems very "hacky", but I question the point of being able to remotely shutdown a web server via a call to a URI anyway. ;-)

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!