【问题标题】:start unicorn app server when the ubuntu server startsubuntu 服务器启动时启动独角兽应用服务器
【发布时间】:2013-04-03 04:23:01
【问题描述】:

我正在使用 ruby​​ 企业版和独角兽作为应用服务器运行我的 rails 应用程序。我运行这个命令

bundle exec unicorn -D -c /home/ubuntu/apps/st/config/unicorn.rb

我需要在系统重新启动或启动后立即运行此命令。我在 ubuntu 10.04 LTS EC2 实例上运行该应用程序。我尝试了几个在on this siteas this site 中提到的例子,但它对我不起作用。任何提醒

【问题讨论】:

  • 怎么不工作了?你看到错误了吗?进程是否实际上没有运行(检查 ps aux)
  • 我添加了这个脚本并重启了实例,但是独角兽也启动了,我检查了 syslog 没有找到和记录,还检查了 ps aux,这个过程还没有开始
  • 我需要运行 bundle exec,它通常不是 unicorn_rails。有所作为

标签: ruby-on-rails ruby ruby-on-rails-3 unicorn


【解决方案1】:

尝试作为新贵。为此,您需要在目录 /etc/init/ 中创建一个 myapp.conf 文件,其内容如下:

description "myapp server"

start on runlevel [23]
stop on shutdown
exec sudo -u myuser sh -c "cd /path/to/my/app && bundle exec unicorn -D -c /home/ubuntu/apps/st/config/unicorn.rb"

respawn

之后,您应该能够使用以下命令启动/停止/重新启动您的应用:

start myapp
stop myapp
restart myapp

使用 ps -aux | grep myapp 检查您的应用是否正在运行。

【讨论】:

  • 让我试试这个,很快就会回复你。非常感谢。
  • 运行启动 myapp 时,提示未知工作。
  • 我得到:initctl: Rejected send message, 1 matched rules; type="method_call", sender=":1.7" (uid=1000 pid=4533 comm="initctl start staging-myapp ") interface="com.ubuntu.Upstart0_6.Job" member="Start" error name="(unset)" requested_reply="0" destination="com.ubuntu.Upstart" (uid=0 pid=1 comm="/sbin/init")
  • @MichieldeMare 很抱歉,我还没有收到关于您的评论的通知,所以我才知道。我想你可以得到一些帮助here。这似乎与您遇到的错误相同。
  • @MaxKonin 不知道这个宝石。我会尽快尝试。谢谢!
【解决方案2】:

您可以使用this file 作为模板,设置此文件中提到的适当路径,使其可执行并符号链接到/etc/init.d/my_unicorn_server。现在您可以使用以下命令启动服务器:

sudo service my_unicorn_server start

那么你可以这样做:

sudo update-rc.d my_unicorn_server defaults

在系统重启时自动启动独角兽服务器。

【讨论】:

  • 只有在没有暴发户的情况下才建议这样做。我不记得 10.04 是否有。你有没有把这个排序?
  • 在 12.04 上为我开箱即用。确保在生成符号链接时提供绝对路径而不是相对路径。
【解决方案3】:

就我而言,我只是希望它快点,所以我将启动命令放在/etc/rc.local 中,如下所示。请注意,我使用的是RVM

# By default this script does nothing.
cd <your project dir>
/usr/local/rvm/gems/ruby-2.2.1/wrappers/bundle exec unicorn -c <your project dir>/config/unicorn.conf -D
test -e /etc/ssh/ssh_host_dsa_key || dpkg-reconfigure openssh-server
exit 0

确保你的启动命令在exit 0上方。重启后,直接点击应用程序的url或使用ps -aux | grep unicorn命令检查它是否正在运行。

注意* 以前我使用 Phusion Passenger,但我无法查看它的错误日志,所以我回到了 unicorn。我也尝试了@warantesbr,但没有成功,我猜它失败了,因为我的整个环境都是使用 root 访问设置的。

【讨论】:

    【解决方案4】:

    如果您使用的是 unicorn_init 脚本
    您可以配置一个 cron 作业以在重启时启动独角兽服务器

    crontab -e
    

    并添加

    @reboot /bin/bash -l -c 'service unicorn_<your service name> start >> /<path to log file>/cron.log 2>&1'
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-07-02
      • 2011-08-08
      • 1970-01-01
      • 1970-01-01
      • 2020-04-02
      • 1970-01-01
      • 2016-04-28
      • 1970-01-01
      相关资源
      最近更新 更多