EventMachine.connect_unix_domain
在将 Thin 作为服务运行时如何使用(使用下面的初始化脚本(摘录)和配置)。下面的代码就是问题所在(我得到一个eventmachine not initialized: evma_connect_to_unix_server
错误)。第二个代码示例有效,但不允许我守护瘦(我不认为)。Thin 是否还没有正在运行的 EventMachine 实例?
更新:奇怪的是:停止服务器(使用service thin stop
),似乎进入 config.ru 文件并运行应用程序(所以它可以工作,直到stop
命令超时并终止进程)。当薄停止可能导致这种行为时会发生什么?
有问题的代码
class Server < Sinatra::Base
# Webserver code removed
end
module Handler
def receive_data data
$received_data_changed = 1
$received_data = data
end
end
$sock = EventMachine.connect_unix_domain("/tmp/mysock.sock", Handler)
工作代码
EventMachine.run do
class Server < Sinatra::Base
# Webserver code removed
end
module Handler
def receive_data data
$received_data_changed = 1
$received_data = data
end
end
$sock = EventMachine.connect_unix_domain("/tmp/mysock.sock", Handler)
Server.run!(:port => 4567)
end
初始化脚本摘录
DAEMON=/usr/local/bin/thin
SCRIPT_NAME=/etc/init.d/thin
CONFIG_PATH=/etc/thin
# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0
case "$1" in
start)
$DAEMON start --all $CONFIG_PATH
;;
精简配置
---
chdir: /var/www
environment: development
timeout: 30
log: log/thin.log
pid: tmp/pids/thin.pid
max_conns: 1024
max_persistent_conns: 512
require: []
wait: 30
servers: 1
socket: /tmp/thin.server.sock
daemonize: true