在ubuntu服务器启动时启动unicorn app服务器

Jee*_*gre 9 ruby ruby-on-rails unicorn ruby-on-rails-3

我使用ruby企业版运行我的rails应用程序,独角兽作为app服务器.我运行这个命令

bundle exec unicorn -D -c /home/ubuntu/apps/st/config/unicorn.rb
Run Code Online (Sandbox Code Playgroud)

我需要在系统重启或启动后立即运行此命令.我在ubuntu 10.04 LTS EC2实例上运行应用程序.我尝试了本网站以及本网站上提到的几个例子,但它对我不起作用.任何抬头

war*_*sbr 16

尝试作为暴发户.为此,您需要使用以下内容在/ 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
Run Code Online (Sandbox Code Playgroud)

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

start myapp
stop myapp
restart myapp
Run Code Online (Sandbox Code Playgroud)

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


ben*_*mer 13

您可以将此文件用作模板,设置此文件中提到的相应路径,使其成为可执行文件和符号链接/etc/init.d/my_unicorn_server.现在您可以使用以下命令启动服务器

sudo service my_unicorn_server start
Run Code Online (Sandbox Code Playgroud)

然后你可以这样做:

sudo update-rc.d my_unicorn_server defaults
Run Code Online (Sandbox Code Playgroud)

在系统重启时自动启动unicorn服务器.


Yak*_*idi 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
Run Code Online (Sandbox Code Playgroud)

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

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