首页 > 解决方案 > 在 mina deploy rails app 后文件夹消失时,在哪里保存独角兽 PIDS 和套接字路径

问题描述

我已经设置了一个服务器来部署我的 rails 应用程序。我无法启动独角兽服务。它给了我一个失败的状态。我对此完全陌生。因此,按照本教程https://www.digitalocean.com/community/tutorials/how-to-deploy-a-rails-app-with-unicorn-and-nginx-on-ubuntu-14-04。我在服务器上为套接字创建了共享文件夹、PID。但是我在每次发布后都使用 mina 进行部署,我手动创建的共享文件夹消失了,并与带有独角兽文件的旧版本一起消失了。因此,我在本地桌面上创建了该共享文件夹,但它们没有通过 git 推送到服务器。那么我应该在哪里以及如何放置我的独角兽 pid 和套接字以使其在下面工作是我的文件

我的 unicorn.rb 文件

root = "/home/deployer/apps/rails_app/current"
working_directory root
pid "#{root}/shared/unicorn.pid"
stderr_path "#{root}/log/unicorn.log"
stdout_path "#{root}/log/unicorn.log"

listen "/shared/unicorn.railsapp.sock"
worker_processes 2
timeout 30

preload_app true

我的 /etc/init.d/unicorn_rails_app 文件

set -e

    USAGE="Usage: $0 <start|stop|restart|upgrade|rotate|force-stop>"

    # app settings
    USER="ggg"
    APP_NAME="rails_app"
    APP_ROOT="/home/$USER/$APP_NAME/current"
    ENV="production"

    # environment settings
    PATH="/home/$USER/.rbenv/shims:/home/$USER/.rbenv/bin:$PATH"
    CMD="cd $APP_ROOT && bundle exec unicorn -c config/unicorn.rb -E $ENV -D"
    PID="$APP_ROOT/shared/pids/unicorn.pid"
    OLD_PID="$PID.oldbin"

    # make sure the app exists
    cd $APP_ROOT || exit 1

    sig () {
      test -s "$PID" && kill -$1 `cat $PID`
    }

    oldsig () {
      test -s $OLD_PID && kill -$1 `cat $OLD_PID`
    }

    case $1 in
      start)
      sig 0 && echo >&2 "Already running" && exit 0
        echo "Starting $APP_NAME"
        su - $USER -c "$CMD"
        ;;
      stop)
        echo "Stopping $APP_NAME"
        sig QUIT && exit 0
        echo >&2 "Not running"
        ;;
      force-stop)
        echo "Force stopping $APP_NAME"
        sig TERM && exit 0
        echo >&2 "Not running"
        ;;
      restart|reload|upgrade)
        sig USR2 && echo "reloaded $APP_NAME" && exit 0
        echo >&2 "Couldn't reload, starting '$CMD' instead"
        $CMD
        ;;
      rotate)
        sig USR1 && echo rotated logs OK && exit 0
        echo >&2 "Couldn't rotate logs" && exit 1
        ;;
      *)
        echo >&2 $USAGE
        exit 1
        ;;
    esac

我的 mina deploy.rb 文件

需要 'mina/bundler' 需要 'mina/rails' 需要 'mina/git' 需要 'mina/rbenv' # 用于 rbenv 支持。( http://rbenv.org )

set :domain, 'mydomain'
set :term_mode, :nil
set :deploy_to, 'path'
set :repository, 'myrepo'
set :branch, 'master'
set :user, 'gg'    # Username in the server to SSH to.
set :keep_releases, 5


set :shared_paths, ['config/database.yml', 'config/secrets.yml', 'log','tmp']

task :environment do
  invoke :'rbenv:load'
end

task :setup => :environment do
  queue! %[mkdir -p "#{deploy_to}/#{shared_path}/log"]
  queue! %[chmod g+rx,u+rwx "#{deploy_to}/#{shared_path}/log"]

  queue! %[mkdir -p "#{deploy_to}/#{shared_path}/config"]
  queue! %[chmod g+rx,u+rwx "#{deploy_to}/#{shared_path}/config"]

  queue! %[touch "#{deploy_to}/#{shared_path}/config/database.yml"]
  queue! %[touch "#{deploy_to}/#{shared_path}/config/secrets.yml"]
  queue  %[echo "-----> Be sure to edit '#{deploy_to}/#{shared_path}/config/database.yml' and 'secrets.yml'."]
  if repository
    repo_host = repository.split(%r{@|://}).last.split(%r{:|\/}).first
    repo_port = /:([0-9]+)/.match(repository) && /:([0-9]+)/.match(repository)[1] || '22'

    queue %[
      if ! ssh-keygen -H  -F #{repo_host} &>/dev/null; then
        ssh-keyscan -t rsa -p #{repo_port} -H #{repo_host} >> ~/.ssh/known_hosts
      fi
    ]
  end
end

desc "Deploys the current version to the server."
task :deploy => :environment do
  to :before_hook do
  end
  deploy do
    invoke :'git:clone'
    invoke :'deploy:link_shared_paths'
    invoke :'bundle:install'
    invoke :'rails:db_migrate'
    invoke :'rails:assets_precompile'
    invoke :'deploy:cleanup'

    to :launch do
      queue "mkdir -p #{deploy_to}/current/tmp2/"
      queue "touch #{deploy_to}/current/tmp2/restart.txt"
    end
  end
end

我收到这个错误

unicorn_rails_app.service - LSB:启动独角兽应用程序服务器已加载:已加载(/etc/init.d/unicorn_rails_app;已生成)活动:自 2019 年 6 月 4 日星期二 07:35:52 UTC 起失败(结果:退出代码);10 秒前 文档:man:systemd-sysv-generator(8) 进程:30422 ExecStart=/etc/init.d/unicorn_rails_app start (code=exited, status=1/FAILURE)

标签: ruby-on-railsnginxunicornapache-mina

解决方案


将它们保存在共享文件夹中,您可以在 shared 中创建指向 tmp 文件夹的符号链接。


推荐阅读