2012-03-02 37 views
4

我继承了一个Rails应用程序,我试图理解它。然而,当我运行:如何更改Thin的配置?

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

回答

5

当安装了gem的thin时,ra​​ils会默认使用它作为服务器。

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

+0

我不知道为什么我下的印象的Rails试图在同一端口上启动2台服务器。 – Geo 2012-03-02 09:27:20

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

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