【问题标题】:how to restart unicorn manually如何手动重启独角兽
【发布时间】:2013-10-21 12:57:25
【问题描述】:

当我运行 cap deploy 时,我不确定 unicorn 是否正常重启,因为某些更改未显示在应用程序中,因此我想在我的远程服务器上手动重启 unicorn。我已经导航到etc/init.d 并看到unicorn_myapp 的列表,但它不是一个目录(即我不能 cd 进入它)。根据我的 deploy.rb 文件中的以下代码,我可以从这里做些什么来重新启动独角兽吗?

我尝试执行run unicorn_myapp restart,但它说run 不是命令

namespace :deploy do
  %w[start stop restart].each do |command|
    desc "#{command} unicorn server"
    task command, roles: :app, except: {no_release: true} do
      run "/etc/init.d/unicorn_#{application} #{command}"
    end
  end

【问题讨论】:

  • 仅供参考,这里的答案都是错误的。

标签: ruby-on-rails unicorn


【解决方案1】:

或者,不依赖于依赖于操作系统的/etc/init.d... 脚本,重新启动独角兽的一种简单方法是将HUP (1) 信号发送到其主进程。

例如,我如何在 git push 之后通过 post-receive 钩子自动重新加载应用程序:

#!/bin/sh
unicorn_pid=`cat /tmp/pids/unicorn.pid`
echo "Restarting Unicorn ($unicorn_pid)"
kill -HUP $unicorn_pid

在您的情况下,/etc/init.d/unicorn_myapp restart 脚​​本可能正在执行此操作。检查 unicorn.conf 以了解其 pidfile 的位置。

更多详情请见unicorn SIGNALS documentations

【讨论】:

  • fyi,相对 tmp/pids... 路径是故意的,而不是拼写错误...我的 git 钩子在项目路径中运行,包含一个本地 tmp 文件夹...无论如何! :)
  • kill -HUP $unicorn_pid <running PID>之后也需要一个进程ID
【解决方案2】:

您没有列出操作系统。但以下其中一项应该有效。

你需要是 root / 使用 sudo

/etc/init.d/unicorn_myapp restart 


/etc/init.d/unicorn_myapp stop 
/etc/init.d/unicorn_myapp start 


service unicorn_myapp restart

service unicorn_myapp stop
service unicorn_myapp start

首先尝试重新启动版本,但根据初始化脚本的编写方式,它可能没有重新启动命令,如果这不起作用,您可以执行停止/启动版本。

【讨论】:

    【解决方案3】:

    您可能必须是 root,但它应该只是 /etc/init.d/unicorn_myapp restart(不要包括 run,这不是 shell 命令)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-06-01
      • 2023-03-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多