如何更改Thin的配置?

时间:2012-03-02 09:05:11

标签: ruby-on-rails thin

我继承了Rails应用程序,我正在努力理解它。但是,当我跑:

rails s

我收到此日志:

=> Booting Thin
=> Rails 3.2.1 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
>> Thin web server (v1.3.1 codename Triple Espresso)
>> Maximum connections set to 1024
>> Listening on 0.0.0.0:3000, CTRL+C to stop

但是,这对我来说似乎有问题,因为两台服务器都试图收听3000.当我运行rails s时,导致rails启动的原因是什么?

3 个答案:

答案 0 :(得分:5)

安装thin gem后,rails默认会将其用作服务器。

您可以使用-p选项更改端口,例如-p 3001。还有一些可用于设置环境,绑定地址和类似的选项。有关Rails guide中的信息的更多信息。

答案 1 :(得分:5)

示例,具有nginx和瘦服务器的Padrinorb应用程序:

<强>细

# config/thin.yml

port: 3000
user: padrino
group: padrino
pid: tmp/pids/thin.pid
timeout: 30
wait: 30
log: log/thin.log
max_conns: 1024
require: []
environment: production
max_persistent_conns: 512
servers: 4
threaded: true
no-epoll: true
daemonize: true
socket: tmp/sockets/thin.sock
chdir: /home/padrino/my-padrino-app
tag: my-padrino-app

<强> Nginx的

# /etc/nginx/sites-enabled/my-padrino-app

server {
    listen 80 default_server;
    server_name my-padrino-app.com;
    location / {
        proxy_pass http://padrino;
    }
}

upstream padrino {
    server unix:/home/padrino/my-padrino-app/tmp/sockets/thin.0.sock;
    server unix:/home/padrino/my-padrino-app/tmp/sockets/thin.1.sock;
    server unix:/home/padrino/my-padrino-app/tmp/sockets/thin.2.sock;
    server unix:/home/padrino/my-padrino-app/tmp/sockets/thin.3.sock;
}

启动,停止,重启,状态的脚本

#!/usr/bin/env bash
# bin/my-padrino-app-service.sh

APPDIR="/home/padrino/my-padrino-app"
CURDIR=$(pwd)

if [[ $# -lt 1 ]]
then
    echo
    echo "Usage:"
    echo "  $0 <start|stop|restart|status>"
    echo
    exit 1
fi

case $1 in
    "status")
        cat $APPDIR/tmp/pids/thin.* &> /dev/null
        if [[ $? -ne 0 ]]
        then
            echo "Service stopped"
        else
            for i in $(ls -C1 $APPDIR/tmp/pids/thin.*)
            do
                echo "Running: $(cat $i)"
            done
        fi
    ;;
    "start")
        echo "Making thin dirs..."
        mkdir -p $APPDIR/tmp/thin
        mkdir -p $APPDIR/tmp/pids
        mkdir -p $APPDIR/tmp/sockets

        echo "Starting thin..."
        cd $APPDIR
        # Production
        thin start -e production -C $APPDIR/config/thin.yml
        cd $CURDIR
        sleep 2
        $0 status
    ;;
    "stop")
        cat $APPDIR/tmp/pids/thin.* &> /dev/null
        if [[ $? -eq 0 ]]
        then
            for i in $(ls -C1 $APPDIR/tmp/pids/thin.*)
            do
                PID=$(cat $i)
                echo -n "Stopping thin ${PID}..."
                kill $PID
                if [[ $? -eq 0 ]]
                then
                    echo "OK"
                else
                    echo "FAIL"
                fi
            done
        fi
        $0 status
    ;;
    "restart")
        $0 stop
        $0 start
        $0 status
    ;;
esac

答案 2 :(得分:3)

您可以这样做:

thin start -p 3000 -e production ....等等每个参数。但它太无聊......

最好的方法是在 app_name / config / 目录中创建配置yml文件。

#config/my_thin.yml

user: www-data
group: www-data
pid: tmp/pids/thin.pid
timeout: 30
wait: 30
log: log/thin.log
max_conns: 1024
require: []
environment: production
max_persistent_conns: 512
servers: 1
threaded: true
no-epoll: true
daemonize: true
socket: tmp/sockets/thin.sock
chdir: /path/to/your/apps/root
tag: a-name-to-show-up-in-ps aux

并运行它指定此配置文件:thin start -C config/mythin.yml