新手问题 Capistrano 部署的错误

zicjin · 2014年08月21日 · 最后由 zicjin 回复于 2014年08月22日 · 4651 次阅读

$ bundle exec cap production deploy

···
INFO[945bdbd0] Running /usr/bin/env service resque restart on d.baozoubisai.com
DEBUG[945bdbd0] Command: /usr/bin/env service resque restart
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing on host d.baozoubisai.com: service exit status: 1
service stdout: Nothing written
service stderr: Nothing written
/home/vagrant/.rvm/gems/ruby-2.1.1/gems/sshkit-1.5.1/lib/sshkit/command.rb:97:in `exit_status='
···

这种错误该怎么调试?完全摸不着上下文。 手动执行『service resque restart』没有问题,使用的是与 cap 登录的相同的用户。

deploy.rb:

lock '3.1.0'
...
namespace :deploy do
  desc "Restart unicorn and resque"
  task :restart do
    invoke 'deploy:passenger:restart'
    invoke 'deploy:resque:restart'
  end
  after :publishing, :restart

  namespace :passenger do
    task :restart do
      on roles(:app) do
        execute :touch, "#{release_path}/tmp/restart.txt"
      end
    end
  end

  namespace :resque do
    %w( start stop restart ).each do |action|
      desc "#{action} resque worker"
      task action do
        on roles(:app) do
          execute :service, :resque, action
        end
      end
    end
  end
end
```shell

resque 脚本:
```shell
set -e
set -u

APP_ROOT=/home/zcj/www/d.baozoubisai.com/current
USER=zcj

TIMEOUT=${TIMEOUT-60}
PIDFILE="$APP_ROOT/tmp/pids/resque.%d.pid"
QUEUES="*"
COUNT=1

run () {
  if [ "$(id -un)" = "$USER" ]; then
    eval $1
  else
    su -c "$1" - $USER
  fi
}

case "$1" in
  start)
    for i in $(seq 1 $COUNT); do
      pidfile=$(printf "$PIDFILE" $i)

      if test -s "$pidfile" && run "kill -0 `cat $pidfile`"; then
        echo "Worker `cat $pidfile` alread running"
      else
        run "cd $APP_ROOT; bundle exec rake environment resque:work QUEUE=$QUEUES PIDFILE=$pidfile TERM_CHILD=1 BACKGROUND=yes RAILS_ENV=production > /dev/null 2>&1"
        echo "Start worker `cat $pidfile`"
      fi
    done
    ;;
  stop)
    for i in $(seq 1 $COUNT); do
      pidfile=$(printf "$PIDFILE" $i)

      if test -s "$pidfile" && run "kill -QUIT `cat $pidfile`"; then
        echo "Stop worker `cat $pidfile`"
        run "rm $pidfile"
      fi
    done
    ;;
  restart|reload)
    $0 stop
    $0 start
    ;;
  *)
    echo >&2 "Usage: $0 <start|stop|restart|reload>"
    exit 1
    ;;
esac

service resque restart这个的错误吧?到服务器上手动执行看看?

#1 楼 @Tony612 手动执行这个没有问题

#2 楼 @zicjin 会不会是 cap 的用户没有执行的权限?

建议把全部的日志贴出来。

#4 楼 @hging

vagrant@vagrant-ubuntu-precise-64:/vagrant$ bundle exec cap production deploy --verbose DEBUG[74b74676] Running /usr/bin/env [ -d ~/.rvm ] on d.baozoubisai.com DEBUG[74b74676] Command: [ -d ~/.rvm ] DEBUG[74b74676] Finished in 2.942 seconds with exit status 0 (successful). DEBUG[438aa924] Running ~/.rvm/bin/rvm version on d.baozoubisai.com DEBUG[438aa924] Command: ~/.rvm/bin/rvm version DEBUG[438aa924] rvm 1.25.28 (stable) by Wayne E. Seguin [email protected], Michal Papis [email protected] [https://rvm.io/] DEBUG[438aa924] Finished in 0.549 seconds with exit status 0 (successful). rvm 1.25.28 (stable) by Wayne E. Seguin [email protected], Michal Papis [email protected] [https://rvm.io/] DEBUG[460ea343] Running ~/.rvm/bin/rvm current on d.baozoubisai.com DEBUG[460ea343] Command: ~/.rvm/bin/rvm current DEBUG[460ea343] ruby-2.1.1 DEBUG[460ea343] Finished in 0.628 seconds with exit status 0 (successful). ruby-2.1.1 DEBUG[8f2c3d4b] Running ~/.rvm/bin/rvm default do ruby --version on d.baozoubisai.com DEBUG[8f2c3d4b] Command: ~/.rvm/bin/rvm default do ruby --version DEBUG[8f2c3d4b] ruby 2.1.1p76 (2014-02-24 revision 45161) [x86_64-linux] DEBUG[8f2c3d4b] Finished in 0.875 seconds with exit status 0 (successful). ruby 2.1.1p76 (2014-02-24 revision 45161) [x86_64-linux] INFO[218f12bf] Running /usr/bin/env mkdir -p /tmp/d.baozoubisai.com/ on d.baozoubisai.com DEBUG[218f12bf] Command: /usr/bin/env mkdir -p /tmp/d.baozoubisai.com/ INFO[218f12bf] Finished in 0.225 seconds with exit status 0 (successful). DEBUGUploading /tmp/d.baozoubisai.com/git-ssh.sh 0.0% INFOUploading /tmp/d.baozoubisai.com/git-ssh.sh 100.0% INFO[5f8ca25e] Running /usr/bin/env chmod +x /tmp/d.baozoubisai.com/git-ssh.sh on d.baozoubisai.com DEBUG[5f8ca25e] Command: /usr/bin/env chmod +x /tmp/d.baozoubisai.com/git-ssh.sh INFO[5f8ca25e] Finished in 0.040 seconds with exit status 0 (successful). DEBUG[fb283c4a] Running /usr/bin/env git ls-remote [email protected]:zicjin/campo.git on d.baozoubisai.com DEBUG[fb283c4a] Command: ( GIT_ASKPASS=/bin/echo GIT_SSH=/tmp/d.baozoubisai.com/git-ssh.sh /usr/bin/env git ls-remote [email protected]:zicjin/campo.git ) DEBUG[fb283c4a] Error reading response length from authentication socket. DEBUG[fb283c4a] 8a3586bf0e79494e73f999fabac67236121ede09 HEAD DEBUG[fb283c4a] 57901b32903e85bd4e074f8d2892ad7584f78eae refs/heads/import DEBUG[fb283c4a] 8a3586bf0e79494e73f999fabac67236121ede09 refs/heads/master DEBUG[fb283c4a] Error reading response length from authentication socket. DEBUG[fb283c4a] Finished in 4.785 seconds with exit status 0 (successful). INFO[db73ab16] Running /usr/bin/env mkdir -pv /home/zcj/www/d.baozoubisai.com/shared /home/zcj/www/d.baozoubisai.com/releases on d.baozoubisai.com DEBUG[db73ab16] Command: /usr/bin/env mkdir -pv /home/zcj/www/d.baozoubisai.com/shared /home/zcj/www/d.baozoubisai.com/releases INFO[db73ab16] Finished in 0.384 seconds with exit status 0 (successful). INFO[c7d0b625] Running /usr/bin/env mkdir -pv /home/zcj/www/d.baozoubisai.com/shared/bin /home/zcj/www/d.baozoubisai.com/shared/log /home/zcj/www/d.baozoubisai.com/shared/tmp/pids /home/zcj/www/d.baozoubisai.com/shared/tmp/cache /home/zcj/www/d.baozoubisai.com/shared/tmp/sockets /home/zcj/www/d.baozoubisai.com/shared/vendor/bundle /home/zcj/www/d.baozoubisai.com/shared/public/uploads /home/zcj/www/d.baozoubisai.com/shared/public/assets on d.baozoubisai.com DEBUG[c7d0b625] Command: /usr/bin/env mkdir -pv /home/zcj/www/d.baozoubisai.com/shared/bin /home/zcj/www/d.baozoubisai.com/shared/log /home/zcj/www/d.baozoubisai.com/shared/tmp/pids /home/zcj/www/d.baozoubisai.com/shared/tmp/cache /home/zcj/www/d.baozoubisai.com/shared/tmp/sockets /home/zcj/www/d.baozoubisai.com/shared/vendor/bundle /home/zcj/www/d.baozoubisai.com/shared/public/uploads /home/zcj/www/d.baozoubisai.com/shared/public/assets INFO[c7d0b625] Finished in 0.063 seconds with exit status 0 (successful). INFO[463b322a] Running /usr/bin/env mkdir -pv /home/zcj/www/d.baozoubisai.com/shared/config /home/zcj/www/d.baozoubisai.com/shared/config /home/zcj/www/d.baozoubisai.com/shared/config on d.baozoubisai.com DEBUG[463b322a] Command: /usr/bin/env mkdir -pv /home/zcj/www/d.baozoubisai.com/shared/config /home/zcj/www/d.baozoubisai.com/shared/config /home/zcj/www/d.baozoubisai.com/shared/config INFO[463b322a] Finished in 0.066 seconds with exit status 0 (successful). DEBUG[f17c167a] Running /usr/bin/env [ -f /home/zcj/www/d.baozoubisai.com/shared/config/database.yml ] on d.baozoubisai.com DEBUG[f17c167a] Command: [ -f /home/zcj/www/d.baozoubisai.com/shared/config/database.yml ] DEBUG[f17c167a] Finished in 0.425 seconds with exit status 0 (successful). DEBUG[69ad6fb8] Running /usr/bin/env [ -f /home/zcj/www/d.baozoubisai.com/shared/config/config.yml ] on d.baozoubisai.com DEBUG[69ad6fb8] Command: [ -f /home/zcj/www/d.baozoubisai.com/shared/config/config.yml ] DEBUG[69ad6fb8] Finished in 0.086 seconds with exit status 0 (successful). DEBUG[534880c5] Running /usr/bin/env [ -f /home/zcj/www/d.baozoubisai.com/shared/config/secrets.yml ] on d.baozoubisai.com DEBUG[534880c5] Command: [ -f /home/zcj/www/d.baozoubisai.com/shared/config/secrets.yml ] DEBUG[534880c5] Finished in 0.063 seconds with exit status 0 (successful). DEBUG[601aaa16] Running /usr/bin/env [ -f /home/zcj/www/d.baozoubisai.com/repo/HEAD ] on d.baozoubisai.com DEBUG[601aaa16] Command: [ -f /home/zcj/www/d.baozoubisai.com/repo/HEAD ] DEBUG[601aaa16] Finished in 0.052 seconds with exit status 0 (successful). INFOThe repository mirror is at /home/zcj/www/d.baozoubisai.com/repo DEBUG[d4b72597] Running /usr/bin/env if test ! -d /home/zcj/www/d.baozoubisai.com/repo; then echo "Directory does not exist '/home/zcj/www/d.baozoubisai.com/repo'" 1>&2; false; fi on d.baozoubisai.com DEBUG[d4b72597] Command: if test ! -d /home/zcj/www/d.baozoubisai.com/repo; then echo "Directory does not exist '/home/zcj/www/d.baozoubisai.com/repo'" 1>&2; false; fi DEBUG[d4b72597] Finished in 0.175 seconds with exit status 0 (successful). DEBUG[666fd641] Running /usr/bin/env cd /home/zcj/www/d.baozoubisai.com/repo && git rev-parse --short HEAD on d.baozoubisai.com DEBUG[666fd641] Command: cd /home/zcj/www/d.baozoubisai.com/repo && git rev-parse --short HEAD DEBUG[666fd641] 8a3586b DEBUG[666fd641] Finished in 0.525 seconds with exit status 0 (successful). INFO[eb6717d9] Running /usr/bin/env git remote update on d.baozoubisai.com DEBUG[eb6717d9] Command: cd /home/zcj/www/d.baozoubisai.com/repo && /usr/bin/env git remote update DEBUG[eb6717d9] 正在获取 origin DEBUG[eb6717d9] 正在获取 origin DEBUG[eb6717d9] Error reading response length from authentication socket. INFO[eb6717d9] Finished in 4.209 seconds with exit status 0 (successful). DEBUG[d89f9974] Running /usr/bin/env cd /home/zcj/www/d.baozoubisai.com/repo && git rev-parse --short HEAD on d.baozoubisai.com DEBUG[d89f9974] Command: cd /home/zcj/www/d.baozoubisai.com/repo && git rev-parse --short HEAD DEBUG[d89f9974] 8a3586b DEBUG[d89f9974] Finished in 0.039 seconds with exit status 0 (successful). DEBUG[01660377] Running /usr/bin/env if test ! -d /home/zcj/www/d.baozoubisai.com/repo; then echo "Directory does not exist '/home/zcj/www/d.baozoubisai.com/repo'" 1>&2; false; fi on d.baozoubisai.com DEBUG[01660377] Command: if test ! -d /home/zcj/www/d.baozoubisai.com/repo; then echo "Directory does not exist '/home/zcj/www/d.baozoubisai.com/repo'" 1>&2; false; fi DEBUG[01660377] Finished in 0.040 seconds with exit status 0 (successful). INFO[9a74fb29] Running /usr/bin/env mkdir -p /home/zcj/www/d.baozoubisai.com/releases/20140821094650 on d.baozoubisai.com DEBUG[9a74fb29] Command: cd /home/zcj/www/d.baozoubisai.com/repo && ( GIT_ASKPASS=/bin/echo GIT_SSH=/tmp/d.baozoubisai.com/git-ssh.sh /usr/bin/env mkdir -p /home/zcj/www/d.baozoubisai.com/releases/20140821094650 ) INFO[9a74fb29] Finished in 0.081 seconds with exit status 0 (successful). INFO[8f7f8fee] Running /usr/bin/env git archive master | tar -x -C /home/zcj/www/d.baozoubisai.com/releases/20140821094650 on d.baozoubisai.com DEBUG[8f7f8fee] Command: cd /home/zcj/www/d.baozoubisai.com/repo && ( GIT_ASKPASS=/bin/echo GIT_SSH=/tmp/d.baozoubisai.com/git-ssh.sh /usr/bin/env git archive master | tar -x -C /home/zcj/www/d.baozoubisai.com/releases/20140821094650 ) INFO[8f7f8fee] Finished in 0.193 seconds with exit status 0 (successful). INFO[351bad4f] Running /usr/bin/env mkdir -pv /home/zcj/www/d.baozoubisai.com/releases/20140821094650/config /home/zcj/www/d.baozoubisai.com/releases/20140821094650/config /home/zcj/www/d.baozoubisai.com/releases/20140821094650/config on d.baozoubisai.com DEBUG[351bad4f] Command: /usr/bin/env mkdir -pv /home/zcj/www/d.baozoubisai.com/releases/20140821094650/config /home/zcj/www/d.baozoubisai.com/releases/20140821094650/config /home/zcj/www/d.baozoubisai.com/releases/20140821094650/config INFO[351bad4f] Finished in 0.458 seconds with exit status 0 (successful). DEBUG[0a157d16] Running /usr/bin/env [ -L /home/zcj/www/d.baozoubisai.com/releases/20140821094650/config/database.yml ] on d.baozoubisai.com DEBUG[0a157d16] Command: [ -L /home/zcj/www/d.baozoubisai.com/releases/20140821094650/config/database.yml ] DEBUG[0a157d16] Finished in 0.058 seconds with exit status 1 (failed). DEBUG[acbe3022] Running /usr/bin/env [ -f /home/zcj/www/d.baozoubisai.com/releases/20140821094650/config/database.yml ] on d.baozoubisai.com DEBUG[acbe3022] Command: [ -f /home/zcj/www/d.baozoubisai.com/releases/20140821094650/config/database.yml ] DEBUG[acbe3022] Finished in 0.041 seconds with exit status 1 (failed). INFO[7c8e7b9f] Running /usr/bin/env ln -s /home/zcj/www/d.baozoubisai.com/shared/config/database.yml /home/zcj/www/d.baozoubisai.com/releases/20140821094650/config/database.yml on d.baozoubisai.com DEBUG[7c8e7b9f] Command: /usr/bin/env ln -s /home/zcj/www/d.baozoubisai.com/shared/config/database.yml /home/zcj/www/d.baozoubisai.com/releases/20140821094650/config/database.yml INFO[7c8e7b9f] Finished in 0.042 seconds with exit status 0 (successful). DEBUG[92fa9a9f] Running /usr/bin/env [ -L /home/zcj/www/d.baozoubisai.com/releases/20140821094650/config/config.yml ] on d.baozoubisai.com DEBUG[92fa9a9f] Command: [ -L /home/zcj/www/d.baozoubisai.com/releases/20140821094650/config/config.yml ] DEBUG[92fa9a9f] Finished in 0.038 seconds with exit status 1 (failed). DEBUG[b02364e1] Running /usr/bin/env [ -f /home/zcj/www/d.baozoubisai.com/releases/20140821094650/config/config.yml ] on d.baozoubisai.com DEBUG[b02364e1] Command: [ -f /home/zcj/www/d.baozoubisai.com/releases/20140821094650/config/config.yml ] DEBUG[b02364e1] Finished in 0.166 seconds with exit status 1 (failed). INFO[d0e8bdd6] Running /usr/bin/env ln -s /home/zcj/www/d.baozoubisai.com/shared/config/config.yml /home/zcj/www/d.baozoubisai.com/releases/20140821094650/config/config.yml on d.baozoubisai.com DEBUG[d0e8bdd6] Command: /usr/bin/env ln -s /home/zcj/www/d.baozoubisai.com/shared/config/config.yml /home/zcj/www/d.baozoubisai.com/releases/20140821094650/config/config.yml INFO[d0e8bdd6] Finished in 0.044 seconds with exit status 0 (successful). DEBUG[f1b732be] Running /usr/bin/env [ -L /home/zcj/www/d.baozoubisai.com/releases/20140821094650/config/secrets.yml ] on d.baozoubisai.com DEBUG[f1b732be] Command: [ -L /home/zcj/www/d.baozoubisai.com/releases/20140821094650/config/secrets.yml ] DEBUG[f1b732be] Finished in 0.048 seconds with exit status 1 (failed). DEBUG[280bd81b] Running /usr/bin/env [ -f /home/zcj/www/d.baozoubisai.com/releases/20140821094650/config/secrets.yml ] on d.baozoubisai.com DEBUG[280bd81b] Command: [ -f /home/zcj/www/d.baozoubisai.com/releases/20140821094650/config/secrets.yml ] DEBUG[280bd81b] Finished in 0.044 seconds with exit status 1 (failed). INFO[3464f435] Running /usr/bin/env ln -s /home/zcj/www/d.baozoubisai.com/shared/config/secrets.yml /home/zcj/www/d.baozoubisai.com/releases/20140821094650/config/secrets.yml on d.baozoubisai.com DEBUG[3464f435] Command: /usr/bin/env ln -s /home/zcj/www/d.baozoubisai.com/shared/config/secrets.yml /home/zcj/www/d.baozoubisai.com/releases/20140821094650/config/secrets.yml INFO[3464f435] Finished in 0.041 seconds with exit status 0 (successful). INFO[8be11454] Running /usr/bin/env mkdir -pv /home/zcj/www/d.baozoubisai.com/releases/20140821094650 /home/zcj/www/d.baozoubisai.com/releases/20140821094650 /home/zcj/www/d.baozoubisai.com/releases/20140821094650/tmp /home/zcj/www/d.baozoubisai.com/releases/20140821094650/tmp /home/zcj/www/d.baozoubisai.com/releases/20140821094650/tmp /home/zcj/www/d.baozoubisai.com/releases/20140821094650/vendor /home/zcj/www/d.baozoubisai.com/releases/20140821094650/public /home/zcj/www/d.baozoubisai.com/releases/20140821094650/public on d.baozoubisai.com DEBUG[8be11454] Command: /usr/bin/env mkdir -pv /home/zcj/www/d.baozoubisai.com/releases/20140821094650 /home/zcj/www/d.baozoubisai.com/releases/20140821094650 /home/zcj/www/d.baozoubisai.com/releases/20140821094650/tmp /home/zcj/www/d.baozoubisai.com/releases/20140821094650/tmp /home/zcj/www/d.baozoubisai.com/releases/20140821094650/tmp /home/zcj/www/d.baozoubisai.com/releases/20140821094650/vendor /home/zcj/www/d.baozoubisai.com/releases/20140821094650/public /home/zcj/www/d.baozoubisai.com/releases/20140821094650/public DEBUG[8be11454] mkdir: 已创建目录 "/home/zcj/www/d.baozoubisai.com/releases/20140821094650/tmp" INFO[8be11454] Finished in 0.052 seconds with exit status 0 (successful). DEBUG[49505ad0] Running /usr/bin/env [ -L /home/zcj/www/d.baozoubisai.com/releases/20140821094650/bin ] on d.baozoubisai.com DEBUG[49505ad0] Command: [ -L /home/zcj/www/d.baozoubisai.com/releases/20140821094650/bin ] DEBUG[49505ad0] Finished in 0.378 seconds with exit status 1 (failed). DEBUG[e7811f9e] Running /usr/bin/env [ -d /home/zcj/www/d.baozoubisai.com/releases/20140821094650/bin ] on d.baozoubisai.com DEBUG[e7811f9e] Command: [ -d /home/zcj/www/d.baozoubisai.com/releases/20140821094650/bin ] DEBUG[e7811f9e] Finished in 0.179 seconds with exit status 0 (successful). INFO[8f4611cb] Running /usr/bin/env rm -rf /home/zcj/www/d.baozoubisai.com/releases/20140821094650/bin on d.baozoubisai.com DEBUG[8f4611cb] Command: /usr/bin/env rm -rf /home/zcj/www/d.baozoubisai.com/releases/20140821094650/bin INFO[8f4611cb] Finished in 0.043 seconds with exit status 0 (successful). INFO[fcb9c31f] Running /usr/bin/env ln -s /home/zcj/www/d.baozoubisai.com/shared/bin /home/zcj/www/d.baozoubisai.com/releases/20140821094650/bin on d.baozoubisai.com DEBUG[fcb9c31f] Command: /usr/bin/env ln -s /home/zcj/www/d.baozoubisai.com/shared/bin /home/zcj/www/d.baozoubisai.com/releases/20140821094650/bin INFO[fcb9c31f] Finished in 0.043 seconds with exit status 0 (successful). DEBUG[5f6c31af] Running /usr/bin/env [ -L /home/zcj/www/d.baozoubisai.com/releases/20140821094650/log ] on d.baozoubisai.com DEBUG[5f6c31af] Command: [ -L /home/zcj/www/d.baozoubisai.com/releases/20140821094650/log ] DEBUG[5f6c31af] Finished in 0.051 seconds with exit status 1 (failed). DEBUG[1dac98c6] Running /usr/bin/env [ -d /home/zcj/www/d.baozoubisai.com/releases/20140821094650/log ] on d.baozoubisai.com DEBUG[1dac98c6] Command: [ -d /home/zcj/www/d.baozoubisai.com/releases/20140821094650/log ] DEBUG[1dac98c6] Finished in 0.272 seconds with exit status 0 (successful). INFO[a70a791e] Running /usr/bin/env rm -rf /home/zcj/www/d.baozoubisai.com/releases/20140821094650/log on d.baozoubisai.com DEBUG[a70a791e] Command: /usr/bin/env rm -rf /home/zcj/www/d.baozoubisai.com/releases/20140821094650/log INFO[a70a791e] Finished in 0.046 seconds with exit status 0 (successful). INFO[9046b457] Running /usr/bin/env ln -s /home/zcj/www/d.baozoubisai.com/shared/log /home/zcj/www/d.baozoubisai.com/releases/20140821094650/log on d.baozoubisai.com DEBUG[9046b457] Command: /usr/bin/env ln -s /home/zcj/www/d.baozoubisai.com/shared/log /home/zcj/www/d.baozoubisai.com/releases/20140821094650/log INFO[9046b457] Finished in 0.041 seconds with exit status 0 (successful). DEBUG[bf3b5cf9] Running /usr/bin/env [ -L /home/zcj/www/d.baozoubisai.com/releases/20140821094650/tmp/pids ] on d.baozoubisai.com DEBUG[bf3b5cf9] Command: [ -L /home/zcj/www/d.baozoubisai.com/releases/20140821094650/tmp/pids ] DEBUG[bf3b5cf9] Finished in 0.041 seconds with exit status 1 (failed). DEBUG[57b287ee] Running /usr/bin/env [ -d /home/zcj/www/d.baozoubisai.com/releases/20140821094650/tmp/pids ] on d.baozoubisai.com DEBUG[57b287ee] Command: [ -d /home/zcj/www/d.baozoubisai.com/releases/20140821094650/tmp/pids ] DEBUG[57b287ee] Finished in 0.044 seconds with exit status 1 (failed). INFO[0ed2ac69] Running /usr/bin/env ln -s /home/zcj/www/d.baozoubisai.com/shared/tmp/pids /home/zcj/www/d.baozoubisai.com/releases/20140821094650/tmp/pids on d.baozoubisai.com DEBUG[0ed2ac69] Command: /usr/bin/env ln -s /home/zcj/www/d.baozoubisai.com/shared/tmp/pids /home/zcj/www/d.baozoubisai.com/releases/20140821094650/tmp/pids INFO[0ed2ac69] Finished in 0.043 seconds with exit status 0 (successful). DEBUG[e83b6fbd] Running /usr/bin/env [ -L /home/zcj/www/d.baozoubisai.com/releases/20140821094650/tmp/cache ] on d.baozoubisai.com DEBUG[e83b6fbd] Command: [ -L /home/zcj/www/d.baozoubisai.com/releases/20140821094650/tmp/cache ] DEBUG[e83b6fbd] Finished in 0.067 seconds with exit status 1 (failed). DEBUG[3897f1d3] Running /usr/bin/env [ -d /home/zcj/www/d.baozoubisai.com/releases/20140821094650/tmp/cache ] on d.baozoubisai.com DEBUG[3897f1d3] Command: [ -d /home/zcj/www/d.baozoubisai.com/releases/20140821094650/tmp/cache ] DEBUG[3897f1d3] Finished in 0.216 seconds with exit status 1 (failed). INFO[7836da18] Running /usr/bin/env ln -s /home/zcj/www/d.baozoubisai.com/shared/tmp/cache /home/zcj/www/d.baozoubisai.com/releases/20140821094650/tmp/cache on d.baozoubisai.com DEBUG[7836da18] Command: /usr/bin/env ln -s /home/zcj/www/d.baozoubisai.com/shared/tmp/cache /home/zcj/www/d.baozoubisai.com/releases/20140821094650/tmp/cache INFO[7836da18] Finished in 0.041 seconds with exit status 0 (successful). DEBUG[f0ec9756] Running /usr/bin/env [ -L /home/zcj/www/d.baozoubisai.com/releases/20140821094650/tmp/sockets ] on d.baozoubisai.com DEBUG[f0ec9756] Command: [ -L /home/zcj/www/d.baozoubisai.com/releases/20140821094650/tmp/sockets ] DEBUG[f0ec9756] Finished in 0.039 seconds with exit status 1 (failed). DEBUG[fe4b3fb0] Running /usr/bin/env [ -d /home/zcj/www/d.baozoubisai.com/releases/20140821094650/tmp/sockets ] on d.baozoubisai.com DEBUG[fe4b3fb0] Command: [ -d /home/zcj/www/d.baozoubisai.com/releases/20140821094650/tmp/sockets ] DEBUG[fe4b3fb0] Finished in 0.039 seconds with exit status 1 (failed). INFO[67824ec0] Running /usr/bin/env ln -s /home/zcj/www/d.baozoubisai.com/shared/tmp/sockets /home/zcj/www/d.baozoubisai.com/releases/20140821094650/tmp/sockets on d.baozoubisai.com DEBUG[67824ec0] Command: /usr/bin/env ln -s /home/zcj/www/d.baozoubisai.com/shared/tmp/sockets /home/zcj/www/d.baozoubisai.com/releases/20140821094650/tmp/sockets INFO[67824ec0] Finished in 0.044 seconds with exit status 0 (successful). DEBUG[87c20cdf] Running /usr/bin/env [ -L /home/zcj/www/d.baozoubisai.com/releases/20140821094650/vendor/bundle ] on d.baozoubisai.com DEBUG[87c20cdf] Command: [ -L /home/zcj/www/d.baozoubisai.com/releases/20140821094650/vendor/bundle ] DEBUG[87c20cdf] Finished in 0.042 seconds with exit status 1 (failed). DEBUG[5f528484] Running /usr/bin/env [ -d /home/zcj/www/d.baozoubisai.com/releases/20140821094650/vendor/bundle ] on d.baozoubisai.com DEBUG[5f528484] Command: [ -d /home/zcj/www/d.baozoubisai.com/releases/20140821094650/vendor/bundle ] DEBUG[5f528484] Finished in 0.050 seconds with exit status 1 (failed). INFO[744826ac] Running /usr/bin/env ln -s /home/zcj/www/d.baozoubisai.com/shared/vendor/bundle /home/zcj/www/d.baozoubisai.com/releases/20140821094650/vendor/bundle on d.baozoubisai.com DEBUG[744826ac] Command: /usr/bin/env ln -s /home/zcj/www/d.baozoubisai.com/shared/vendor/bundle /home/zcj/www/d.baozoubisai.com/releases/20140821094650/vendor/bundle INFO[744826ac] Finished in 0.053 seconds with exit status 0 (successful). DEBUG[cd98ab79] Running /usr/bin/env [ -L /home/zcj/www/d.baozoubisai.com/releases/20140821094650/public/uploads ] on d.baozoubisai.com DEBUG[cd98ab79] Command: [ -L /home/zcj/www/d.baozoubisai.com/releases/20140821094650/public/uploads ] DEBUG[cd98ab79] Finished in 0.047 seconds with exit status 1 (failed). DEBUG[c28721ba] Running /usr/bin/env [ -d /home/zcj/www/d.baozoubisai.com/releases/20140821094650/public/uploads ] on d.baozoubisai.com DEBUG[c28721ba] Command: [ -d /home/zcj/www/d.baozoubisai.com/releases/20140821094650/public/uploads ] DEBUG[c28721ba] Finished in 0.041 seconds with exit status 1 (failed). INFO[6576a103] Running /usr/bin/env ln -s /home/zcj/www/d.baozoubisai.com/shared/public/uploads /home/zcj/www/d.baozoubisai.com/releases/20140821094650/public/uploads on d.baozoubisai.com DEBUG[6576a103] Command: /usr/bin/env ln -s /home/zcj/www/d.baozoubisai.com/shared/public/uploads /home/zcj/www/d.baozoubisai.com/releases/20140821094650/public/uploads INFO[6576a103] Finished in 0.058 seconds with exit status 0 (successful). DEBUG[58d06d3e] Running /usr/bin/env [ -L /home/zcj/www/d.baozoubisai.com/releases/20140821094650/public/assets ] on d.baozoubisai.com DEBUG[58d06d3e] Command: [ -L /home/zcj/www/d.baozoubisai.com/releases/20140821094650/public/assets ] DEBUG[58d06d3e] Finished in 0.040 seconds with exit status 1 (failed). DEBUG[af29acad] Running /usr/bin/env [ -d /home/zcj/www/d.baozoubisai.com/releases/20140821094650/public/assets ] on d.baozoubisai.com DEBUG[af29acad] Command: [ -d /home/zcj/www/d.baozoubisai.com/releases/20140821094650/public/assets ] DEBUG[af29acad] Finished in 0.057 seconds with exit status 1 (failed). INFO[26011351] Running /usr/bin/env ln -s /home/zcj/www/d.baozoubisai.com/shared/public/assets /home/zcj/www/d.baozoubisai.com/releases/20140821094650/public/assets on d.baozoubisai.com DEBUG[26011351] Command: /usr/bin/env ln -s /home/zcj/www/d.baozoubisai.com/shared/public/assets /home/zcj/www/d.baozoubisai.com/releases/20140821094650/public/assets INFO[26011351] Finished in 0.039 seconds with exit status 0 (successful). DEBUG[0170840f] Running /usr/bin/env if test ! -d /home/zcj/www/d.baozoubisai.com/releases/20140821094650; then echo "Directory does not exist '/home/zcj/www/d.baozoubisai.com/releases/20140821094650'" 1>&2; false; fi on d.baozoubisai.com DEBUG[0170840f] Command: if test ! -d /home/zcj/www/d.baozoubisai.com/releases/20140821094650; then echo "Directory does not exist '/home/zcj/www/d.baozoubisai.com/releases/20140821094650'" 1>&2; false; fi DEBUG[0170840f] Finished in 0.039 seconds with exit status 0 (successful). INFO[88747bc9] Running ~/.rvm/bin/rvm default do bundle install --binstubs /home/zcj/www/d.baozoubisai.com/shared/bin --path /home/zcj/www/d.baozoubisai.com/shared/bundle --without development test --deployment --quiet on d.baozoubisai.com DEBUG[88747bc9] Command: cd /home/zcj/www/d.baozoubisai.com/releases/20140821094650 && ~/.rvm/bin/rvm default do bundle install --binstubs /home/zcj/www/d.baozoubisai.com/shared/bin --path /home/zcj/www/d.baozoubisai.com/shared/bundle --without development test --deployment --quiet INFO[88747bc9] Finished in 4.180 seconds with exit status 0 (successful). DEBUG[d184cff7] Running /usr/bin/env if test ! -d /home/zcj/www/d.baozoubisai.com/releases/20140821094650; then echo "Directory does not exist '/home/zcj/www/d.baozoubisai.com/releases/20140821094650'" 1>&2; false; fi on d.baozoubisai.com DEBUG[d184cff7] Command: if test ! -d /home/zcj/www/d.baozoubisai.com/releases/20140821094650; then echo "Directory does not exist '/home/zcj/www/d.baozoubisai.com/releases/20140821094650'" 1>&2; false; fi DEBUG[d184cff7] Finished in 0.141 seconds with exit status 0 (successful). INFO[85cc0622] Running ~/.rvm/bin/rvm default do bundle exec rake assets:precompile on d.baozoubisai.com DEBUG[85cc0622] Command: cd /home/zcj/www/d.baozoubisai.com/releases/20140821094650 && ( RAILS_ENV=production ~/.rvm/bin/rvm default do bundle exec rake assets:precompile ) INFO[85cc0622] Finished in 9.076 seconds with exit status 0 (successful). DEBUG[5572d621] Running /usr/bin/env if test ! -d /home/zcj/www/d.baozoubisai.com/releases/20140821094650; then echo "Directory does not exist '/home/zcj/www/d.baozoubisai.com/releases/20140821094650'" 1>&2; false; fi on d.baozoubisai.com DEBUG[5572d621] Command: if test ! -d /home/zcj/www/d.baozoubisai.com/releases/20140821094650; then echo "Directory does not exist '/home/zcj/www/d.baozoubisai.com/releases/20140821094650'" 1>&2; false; fi DEBUG[5572d621] Finished in 0.220 seconds with exit status 0 (successful). INFO[f37309a7] Running /usr/bin/env cp /home/zcj/www/d.baozoubisai.com/releases/20140821094650/public/assets/manifest* /home/zcj/www/d.baozoubisai.com/releases/20140821094650/assets_manifest_backup on d.baozoubisai.com DEBUG[f37309a7] Command: cd /home/zcj/www/d.baozoubisai.com/releases/20140821094650 && /usr/bin/env cp /home/zcj/www/d.baozoubisai.com/releases/20140821094650/public/assets/manifest* /home/zcj/www/d.baozoubisai.com/releases/20140821094650/assets_manifest_backup INFO[f37309a7] Finished in 0.063 seconds with exit status 0 (successful). DEBUG[1128fd5d] Running /usr/bin/env if test ! -d /home/zcj/www/d.baozoubisai.com/releases/20140821094650; then echo "Directory does not exist '/home/zcj/www/d.baozoubisai.com/releases/20140821094650'" 1>&2; false; fi on d.baozoubisai.com DEBUG[1128fd5d] Command: if test ! -d /home/zcj/www/d.baozoubisai.com/releases/20140821094650; then echo "Directory does not exist '/home/zcj/www/d.baozoubisai.com/releases/20140821094650'" 1>&2; false; fi DEBUG[1128fd5d] Finished in 0.040 seconds with exit status 0 (successful). INFO[3ee83489] Running ~/.rvm/bin/rvm default do bundle exec rake db:migrate on d.baozoubisai.com DEBUG[3ee83489] Command: cd /home/zcj/www/d.baozoubisai.com/releases/20140821094650 && ( RAILS_ENV=production ~/.rvm/bin/rvm default do bundle exec rake db:migrate ) INFO[3ee83489] Finished in 8.785 seconds with exit status 0 (successful). INFO[402bf440] Running /usr/bin/env rm -rf /home/zcj/www/d.baozoubisai.com/current on d.baozoubisai.com DEBUG[402bf440] Command: /usr/bin/env rm -rf /home/zcj/www/d.baozoubisai.com/current INFO[402bf440] Finished in 0.074 seconds with exit status 0 (successful). INFO[3114358a] Running /usr/bin/env ln -s /home/zcj/www/d.baozoubisai.com/releases/20140821094650 /home/zcj/www/d.baozoubisai.com/current on d.baozoubisai.com DEBUG[3114358a] Command: /usr/bin/env ln -s /home/zcj/www/d.baozoubisai.com/releases/20140821094650 /home/zcj/www/d.baozoubisai.com/current INFO[3114358a] Finished in 0.049 seconds with exit status 0 (successful). INFO[2b7f47d8] Running /usr/bin/env touch /home/zcj/www/d.baozoubisai.com/releases/20140821094650/tmp/restart.txt on d.baozoubisai.com DEBUG[2b7f47d8] Command: /usr/bin/env touch /home/zcj/www/d.baozoubisai.com/releases/20140821094650/tmp/restart.txt INFO[2b7f47d8] Finished in 0.038 seconds with exit status 0 (successful). INFO[26792411] Running /usr/bin/env service resque restart on d.baozoubisai.com DEBUG[26792411] Command: /usr/bin/env service resque restart cap aborted! SSHKit::Runner::ExecuteError: Exception while executing on host d.baozoubisai.com: service exit status: 1 service stdout: Nothing written service stderr: Nothing written /home/vagrant/.rvm/gems/ruby-2.1.1/gems/sshkit-1.5.1/lib/sshkit/command.rb:97:in exit_status=' /home/vagrant/.rvm/gems/ruby-2.1.1/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:148:inblock (5 levels) in _execute' /home/vagrant/.rvm/gems/ruby-2.1.1/gems/net-ssh-2.9.1/lib/net/ssh/connection/channel.rb:551:in call' /home/vagrant/.rvm/gems/ruby-2.1.1/gems/net-ssh-2.9.1/lib/net/ssh/connection/channel.rb:551:indo_request' /home/vagrant/.rvm/gems/ruby-2.1.1/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:561:in channel_request' /home/vagrant/.rvm/gems/ruby-2.1.1/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:465:indispatch_incoming_packets' /home/vagrant/.rvm/gems/ruby-2.1.1/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:221:in preprocess' /home/vagrant/.rvm/gems/ruby-2.1.1/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:205:inprocess' /home/vagrant/.rvm/gems/ruby-2.1.1/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:169:in block in loop' /home/vagrant/.rvm/gems/ruby-2.1.1/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:169:inloop' /home/vagrant/.rvm/gems/ruby-2.1.1/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:169:in loop' /home/vagrant/.rvm/gems/ruby-2.1.1/gems/net-ssh-2.9.1/lib/net/ssh/connection/channel.rb:269:inwait' /home/vagrant/.rvm/gems/ruby-2.1.1/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:170:in block (3 levels) in _execute' /home/vagrant/.rvm/gems/ruby-2.1.1/gems/net-ssh-2.9.1/lib/net/ssh/connection/channel.rb:514:incall' /home/vagrant/.rvm/gems/ruby-2.1.1/gems/net-ssh-2.9.1/lib/net/ssh/connection/channel.rb:514:in do_open_confirmation' /home/vagrant/.rvm/gems/ruby-2.1.1/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:545:inchannel_open_confirmation' /home/vagrant/.rvm/gems/ruby-2.1.1/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:465:in dispatch_incoming_packets' /home/vagrant/.rvm/gems/ruby-2.1.1/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:221:inpreprocess' /home/vagrant/.rvm/gems/ruby-2.1.1/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:205:in process' /home/vagrant/.rvm/gems/ruby-2.1.1/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:169:inblock in loop' /home/vagrant/.rvm/gems/ruby-2.1.1/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:169:in loop' /home/vagrant/.rvm/gems/ruby-2.1.1/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:169:inloop' /home/vagrant/.rvm/gems/ruby-2.1.1/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:172:in block (2 levels) in _execute' /home/vagrant/.rvm/gems/ruby-2.1.1/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:186:inwith_ssh' /home/vagrant/.rvm/gems/ruby-2.1.1/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:131:in block in _execute' /home/vagrant/.rvm/gems/ruby-2.1.1/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:128:intap' /home/vagrant/.rvm/gems/ruby-2.1.1/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:128:in _execute' /home/vagrant/.rvm/gems/ruby-2.1.1/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:66:inexecute' config/deploy.rb:33:in block (5 levels) in <top (required)>' /home/vagrant/.rvm/gems/ruby-2.1.1/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:54:ininstance_exec' /home/vagrant/.rvm/gems/ruby-2.1.1/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:54:in run' /home/vagrant/.rvm/gems/ruby-2.1.1/gems/sshkit-1.5.1/lib/sshkit/runners/parallel.rb:13:inblock (2 levels) in execute' SSHKit::Command::Failed: service exit status: 1 service stdout: Nothing written service stderr: Nothing written /home/vagrant/.rvm/gems/ruby-2.1.1/gems/sshkit-1.5.1/lib/sshkit/command.rb:97:in exit_status=' /home/vagrant/.rvm/gems/ruby-2.1.1/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:148:inblock (5 levels) in _execute' /home/vagrant/.rvm/gems/ruby-2.1.1/gems/net-ssh-2.9.1/lib/net/ssh/connection/channel.rb:551:in call' /home/vagrant/.rvm/gems/ruby-2.1.1/gems/net-ssh-2.9.1/lib/net/ssh/connection/channel.rb:551:indo_request' /home/vagrant/.rvm/gems/ruby-2.1.1/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:561:in channel_request' /home/vagrant/.rvm/gems/ruby-2.1.1/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:465:indispatch_incoming_packets' /home/vagrant/.rvm/gems/ruby-2.1.1/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:221:in preprocess' /home/vagrant/.rvm/gems/ruby-2.1.1/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:205:inprocess' /home/vagrant/.rvm/gems/ruby-2.1.1/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:169:in block in loop' /home/vagrant/.rvm/gems/ruby-2.1.1/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:169:inloop' /home/vagrant/.rvm/gems/ruby-2.1.1/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:169:in loop' /home/vagrant/.rvm/gems/ruby-2.1.1/gems/net-ssh-2.9.1/lib/net/ssh/connection/channel.rb:269:inwait' /home/vagrant/.rvm/gems/ruby-2.1.1/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:170:in block (3 levels) in _execute' /home/vagrant/.rvm/gems/ruby-2.1.1/gems/net-ssh-2.9.1/lib/net/ssh/connection/channel.rb:514:incall' /home/vagrant/.rvm/gems/ruby-2.1.1/gems/net-ssh-2.9.1/lib/net/ssh/connection/channel.rb:514:in do_open_confirmation' /home/vagrant/.rvm/gems/ruby-2.1.1/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:545:inchannel_open_confirmation' /home/vagrant/.rvm/gems/ruby-2.1.1/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:465:in dispatch_incoming_packets' /home/vagrant/.rvm/gems/ruby-2.1.1/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:221:inpreprocess' /home/vagrant/.rvm/gems/ruby-2.1.1/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:205:in process' /home/vagrant/.rvm/gems/ruby-2.1.1/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:169:inblock in loop' /home/vagrant/.rvm/gems/ruby-2.1.1/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:169:in loop' /home/vagrant/.rvm/gems/ruby-2.1.1/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:169:inloop' /home/vagrant/.rvm/gems/ruby-2.1.1/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:172:in block (2 levels) in _execute' /home/vagrant/.rvm/gems/ruby-2.1.1/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:186:inwith_ssh' /home/vagrant/.rvm/gems/ruby-2.1.1/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:131:in block in _execute' /home/vagrant/.rvm/gems/ruby-2.1.1/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:128:intap' /home/vagrant/.rvm/gems/ruby-2.1.1/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:128:in _execute' /home/vagrant/.rvm/gems/ruby-2.1.1/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:66:inexecute' config/deploy.rb:33:in block (5 levels) in <top (required)>' /home/vagrant/.rvm/gems/ruby-2.1.1/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:54:ininstance_exec' /home/vagrant/.rvm/gems/ruby-2.1.1/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:54:in run' /home/vagrant/.rvm/gems/ruby-2.1.1/gems/sshkit-1.5.1/lib/sshkit/runners/parallel.rb:13:inblock (2 levels) in execute' Tasks: TOP => deploy:resque:restart (See full trace by running task with --trace) The deploy has failed with an error: #<SSHKit::Runner::ExecuteError: Exception while executing on host d.baozoubisai.com: service exit status: 1 service stdout: Nothing written service stderr: Nothing written

vagrant@vagrant-ubuntu-precise-64:/vagrant$

添加 set :log_level, :trace,然后再跑一下看出错吧。参考一下这个吧:https://github.com/capistrano/capistrano/issues/895

#6 楼 @zhenning 和我不是一个问题啊。他是 assets:precompile 命令,我是 service resque restart 命令。重点是不知道怎样还原 cap 执行『service resque restart』的真实场景。

#7 楼 @zicjin 你的出错信息提示在 Tasks: TOP => deploy:resque:restart (See full trace by running task with --trace)

加 trace,是希望能显示出具体的出错信息。

楼主你在你部署的服务器上打 /usr/bin/env service resque restart 直接敲这个,看看能不能执行

#10 楼 @hging 执行没有问题

#8 楼 @MrPasserby 我用的就是这个啊

group :development do # Deploy tool gem 'capistrano', '~> 3.1.0' gem 'capistrano-rvm', '~> 0.1.1' gem 'capistrano-bundler', '~> 1.1.2' gem 'capistrano-rails', '~> 1.0.0' end

我也不知道,如果再写一次我会把启动脚本写在 cap 里面,然后在系统启动项写一行启动脚本,不搞 init.d 了。

#13 楼 @zicjin 我看你 rvm 用的都是 default 的 gemset,最好指定下 gemset, 还有可能是 Capfile 里面忘了 require 了 gem 了

# Load DSL and Setup Up Stages
require 'capistrano/setup'

# Includes default deployment tasks
require 'capistrano/deploy'
# Includes tasks from other gems included in your Gemfile
#
# For documentation on these, see for example:
#
#   https://github.com/capistrano/rvm
#   https://github.com/capistrano/rbenv
#   https://github.com/capistrano/chruby
#   https://github.com/capistrano/bundler
  # https://github.com/capistrano/rails
#
require 'capistrano/rvm'
# require 'capistrano/rbenv'
# require 'capistrano/chruby'
require 'capistrano/bundler'
require 'capistrano/rails/assets'
require 'capistrano/rails/migrations'
# require 'capistrano/unicorn_nginx'

完全无解 - - 个人感觉像是写的 task 有点问题吧。执行下 cap production deploy:resquie:restart --trace

#16 楼 @hging 确实是 task 有问题 vagrant@vagrant-ubuntu-precise-64:/vagrant$ cap production deploy:resque:restart --trace ** Invoke production (first_time) ** Execute production ** Invoke load:defaults (first_time) ** Execute load:defaults ** Invoke rvm:hook (first_time) ** Execute rvm:hook DEBUG[10348b58] Running /usr/bin/env [ -d ~/.rvm ] on 115.28.233.141 DEBUG[10348b58] Command: [ -d ~/.rvm ] DEBUG[10348b58] Finished in 0.458 seconds with exit status 0 (successful). ** Invoke rvm:check (first_time) ** Execute rvm:check DEBUG[a2c2756a] Running ~/.rvm/bin/rvm version on 115.28.233.141 DEBUG[a2c2756a] Command: ~/.rvm/bin/rvm version DEBUG[a2c2756a] rvm 1.25.28 (stable) by Wayne E. Seguin [email protected], Michal Papis [email protected] [https://rvm.io/] DEBUG[a2c2756a] Finished in 0.260 seconds with exit status 0 (successful). rvm 1.25.28 (stable) by Wayne E. Seguin [email protected], Michal Papis [email protected] [https://rvm.io/] DEBUG[996c4f83] Running ~/.rvm/bin/rvm current on 115.28.233.141 DEBUG[996c4f83] Command: ~/.rvm/bin/rvm current DEBUG[996c4f83] ruby-2.1.2 DEBUG[996c4f83] Finished in 0.255 seconds with exit status 0 (successful). ruby-2.1.2 DEBUG[ddc0d0e3] Running ~/.rvm/bin/rvm default do ruby --version on 115.28.233.141 DEBUG[ddc0d0e3] Command: ~/.rvm/bin/rvm default do ruby --version DEBUG[ddc0d0e3] ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-linux] DEBUG[ddc0d0e3] Finished in 0.488 seconds with exit status 0 (successful). ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-linux] ** Invoke bundler:map_bins (first_time) ** Execute bundler:map_bins ** Invoke deploy:resque:restart (first_time) ** Execute deploy:resque:restart INFO[df148033] Running /usr/bin/env service resque restart on 115.28.233.141 DEBUG[df148033] Command: /usr/bin/env service resque restart cap aborted! SSHKit::Runner::ExecuteError: Exception while executing on host 115.28.233.141: service exit status: 127 service stdout: Nothing written service stderr: Nothing written /home/vagrant/.rvm/gems/ruby-2.1.1/gems/sshkit-1.5.1/lib/sshkit/command.rb:97:in `exit_status=' 。。。。。

只是这个 task 一字未改在之前是可用的,服务器上目录也没有任何改动,我不知道是我代码改了其它什么地方导致这个 task 失败

resque 脚本:

#!/bin/bash

BEGIN INIT INFO

Provides: Campo

Required-Start: $all

Required-Stop: $network $local_fs $syslog

Default-Start: 2 3 4 5

Default-Stop: 0 1 6

Short-Description: Start the Campo resque worker at boot

Description: Enable Campo at boot time.

END INIT INFO

set -e set -u

APP_ROOT=/home/zcj/www/d.baozoubisai.com/current USER=zcj

TIMEOUT=${TIMEOUT-60} PIDFILE="$APP_ROOT/tmp/pids/resque.%d.pid" QUEUES="*" COUNT=1

run () { if [ "$(id -un)" = "$USER" ]; then eval $1 else su -c "$1" - $USER fi }

case "$1" in start) for i in $(seq 1 $COUNT); do pidfile=$(printf "$PIDFILE" $i)

if test -s "$pidfile" && run "kill -0 cat $pidfile"; then echo "Worker cat $pidfile alread running" else run "cd $APP_ROOT; bundle exec rake environment resque:work QUEUE=$QUEUES PIDFILE=$pidfile TERM_CHILD=1 BACKGROUND=yes RAILS_ENV=production > /dev/null 2>&1" echo "Start worker cat $pidfile" fi done ;; stop) for i in $(seq 1 $COUNT); do pidfile=$(printf "$PIDFILE" $i)

if test -s "$pidfile" && run "kill -QUIT cat $pidfile"; then echo "Stop worker cat $pidfile" run "rm $pidfile" fi done ;; restart|reload) $0 stop $0 start ;; *) echo >&2 "Usage: $0 " exit 1 ;; esac

上面没有贴好……

set -e
set -u

APP_ROOT=/home/zcj/www/d.baozoubisai.com/current
USER=zcj

TIMEOUT=${TIMEOUT-60}
PIDFILE="$APP_ROOT/tmp/pids/resque.%d.pid"
QUEUES="*"
COUNT=1

run () {
  if [ "$(id -un)" = "$USER" ]; then
    eval $1
  else
    su -c "$1" - $USER
  fi
}

case "$1" in
  start)
    for i in $(seq 1 $COUNT); do
      pidfile=$(printf "$PIDFILE" $i)

      if test -s "$pidfile" && run "kill -0 `cat $pidfile`"; then
        echo "Worker `cat $pidfile` alread running"
      else
        run "cd $APP_ROOT; bundle exec rake environment resque:work QUEUE=$QUEUES PIDFILE=$pidfile TERM_CHILD=1 BACKGROUND=yes RAILS_ENV=production > /dev/null 2>&1"
        echo "Start worker `cat $pidfile`"
      fi
    done
    ;;
  stop)
    for i in $(seq 1 $COUNT); do
      pidfile=$(printf "$PIDFILE" $i)

      if test -s "$pidfile" && run "kill -QUIT `cat $pidfile`"; then
        echo "Stop worker `cat $pidfile`"
        run "rm $pidfile"
      fi
    done
    ;;
  restart|reload)
    $0 stop
    $0 start
    ;;
  *)
    echo >&2 "Usage: $0 <start|stop|restart|reload>"
    exit 1
    ;;
esac

#14 楼 @Rei 我现在通过 echo 标注已经能够确定到是 resque 中 run "cd $APP_ROOT; bundle exec rake environment ... " 这一行的执行错误了。单独执行 run 函数的参数是没有问题的,但我现在看不懂这个 run() 函数是什么作用,能否说明一下?谢谢

#19 楼 @zicjin 系统启动的时候执行用户是 root,cap 执行用户是部署用户,run() 用来切换到部署用户。

擦,被这问题搞死…… 结贴。 缘由是某个 gem 被移除了,但/app 里依然有废弃代码调用了这个库。只是在 rails server 环境没报错。 问题是,为什么在 Capistrano task 中 eval 执行的代码没有正常的报错呢? run "cd $APP_ROOT; bundle exec rake environment ... " 我把这一行提取出最终执行代码去服务端运行,报错信息就正常了……

需要 登录 后方可回复, 如果你还没有账号请 注册新账号