通过Capistrano3.9.1启动nginx时,nginx.pid消失了

时间:2019-06-03 00:54:34

标签: nginx capistrano

我在RoR应用程序中使用Capistrano,在服务器上使用nginx。有2个应用程序使用彼此不同的nginx.conf,因此对于每个应用程序,我杀死以前的nginx进程,然后启动新进程。当我手动执行操作时,就可以了。但是,当我通过Capistrano启动nginx时,nginx.pid不知何故消失了(偶而),因此我无法杀死主进程并无法启动它。服务器无法连接到除我以外的其他人,并且没有其他启动脚本。另一个nginx的pid(nginx_2.pid)从未消失,所以我不知道为什么只有一个nginx.pid被消除。

这是我的预编译和重新启动任务。

...

task :precompile_assets do
    on roles(:application) do
      execute %(cd #{fetch(:application_path)}; bundle exec rails assets:clobber assets:precompile RAILS_ENV=staging RAILS_RELATIVE_URL_ROOT=#{ENV['PROJECT_ROOT']}; if [[ -f /run/nginx.pid ]]; then sudo kill -QUIT $(cat /run/nginx.pid); fi; sudo /usr/sbin/nginx -c /etc/nginx/nginx.conf; )
    end
  end

  desc 'restart server for the other server'
  task :restart_server do
    on roles(:otr) do
      execute 'if [[ -f /run/nginx_2.pid ]]; then sudo kill -QUIT $(cat /run/nginx_2.pid); fi; sudo /usr/sbin/nginx -c /etc/nginx/nginx_2.conf;'
    end

这是我的nginx.conf。

user nginx_user;
worker_process auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf

events {
         worker_connections 768;
       }
...

0 个答案:

没有答案