如何只为一个应用程序启动瘦身?

时间:2011-05-21 14:40:51

标签: ruby-on-rails ruby thin

在/ etc / thin /我有几个yml文件。当我运行service thin stop -C /etc/thin/app.yml时,精简会停止所有应用程序,而不是仅指定我指定的应用程序。

如何精简停止/仅启动指定的应用程序?

更新:嗯,在/etc/init.d/thin中有:$DAEMON restart --all $CONFIG_PATH。这解释了很多。有更聪明的init.d脚本吗?这是我的剧本:

https://gist.github.com/1003131

另见:

Running Rails apps with thin as a service

3 个答案:

答案 0 :(得分:5)

你必须编辑/etc/init.d/thin添加新动作或修改“重启”动作。

如您所见, - 所有$ CONFIG_PATH 将命令发送到所有精简实例。

将init脚本粘贴到某处,我们可以找到一个不错的解决方案;)

更新:

尝试添加以下行,下面:

restart)
  $DAEMON restart --all $CONFIG_PATH
  ;;
restart-single)
  $DAEMON restart -C $2
  ;;
stop-single)
  $DAEMON stop -C $2
  ;;

我没试过,但它应该运作良好。这是一个非常简单的解决方案(没有错误检查),我们添加了两个必须调用的新操作:

service thin restart-single /etc/thin/your_app.yml
or
service thin stop-single /etc/thin/your_app.yml

让我知道它是否有效;)

欢呼声, 甲

答案 1 :(得分:0)

我提出了另一种解决方案(我认为更方便):

  1. 设置/etc/init.d/thin文件的内容以使用我的修复程序:

    #!/bin/sh
    ### BEGIN INIT INFO
    # Provides:          thin
    # Required-Start:    $local_fs $remote_fs
    # Required-Stop:     $local_fs $remote_fs
    # Default-Start:     2 3 4 5
    # Default-Stop:      S 0 1 6
    # Short-Description: thin initscript
    # Description:       thin
    ### END INIT INFO
    
    # Original author: Forrest Robertson
    
    # Do NOT "set -e"
    
    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
    
    if [ "X$2" = X ] || [ "X$3" = X ]; then
        INSTANCES="--all $CONFIG_PATH"
    else
        INSTANCES="-C $3"
    fi
    
    case "$1" in
      start)
      $DAEMON start $INSTANCES 
      ;;
      stop)
      $DAEMON stop $INSTANCES
      ;;
      restart)
      $DAEMON restart $INSTANCES
      ;;
      *)
      echo "Usage: $SCRIPT_NAME {start|stop|restart} (-C config_file.yml)" >&2
      exit 3
      ;;
    esac
    
    :
    
  2. 使用thin restart -C /etc/thin/my_website.yml。可以在startrestartstop命令中使用此类语法。但是,thin restart(当然还是startstop)会造成所有已注册的实例。

答案 2 :(得分:0)

这很奇怪,我从gem本身为脚本添加了一个补丁,用于下一个版本的init脚本,以便在将来的安装中重新启动

重启文件)    $ DAEMON重启-C $ 2 ;;

但是宝石所有者拒绝合并,并说你可以使用瘦启动 - C / path /这很奇怪,因为我已经尝试了很多而且脚本本身说 - 所有并且不允许单个配置, 我也尝试过他说的话,显然它重新开始,因为脚本使用了所有内容,任何人都可以为这个https://github.com/macournoyer/thin/pull/176

提供更多的亮点