在mina部署Rails应用程序后,文件夹会自动消失,从而在哪里保存独角兽PIDS和套接字路径

时间:2019-06-04 07:40:04

标签: ruby-on-rails nginx unicorn apache-mina

我已经设置了用于部署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:启动unicorn应用服务器      已加载:已加载(/etc/init.d/unicorn_rails_app;已生成)      活动:自星期二2019-06-04 07:35:52失败(结果:退出代码)    世界标准时间; 10秒前       文件:man:systemd-sysv-generator(8)    进程:30422 ExecStart = / etc / init.d / unicorn_rails_app启动   (代码=退出,状态= 1 /失败)

1 个答案:

答案 0 :(得分:0)

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