Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run Rack-based application (not Rails) with Unicorn

Tags:

ruby

rack

unicorn

How can I run a Rack-based application (not Rails) with unicorn? Let's assume I have a "hello world" response simple rack app with the name of server.ru, and config file at the same directory with the name of unicorn.conf, how am I supposed to run it? In Thin, for example, I would do something like:

bundle exec rackup server.ru -s thin -E production -p 4001

How would I do the same to run under Unicorn?

like image 807
Eki Eqbal Avatar asked Dec 20 '22 14:12

Eki Eqbal


2 Answers

Unicorn does not give any special treatment to Rails 3+ applications, so the behavior is exactly the same for Rails 3+ applications and non-Rails Rack applications. Just run

unicorn

in your app's root. To run with a specific port, pass -p/--port with the port:

unicorn -p 4001

You can also specify the rackup file:

unicorn server.ru

You can see all the options by running unicorn --help. Of course, you should prepend bundle exec to these commands as needed by your setup.

like image 145
Andrew Marshall Avatar answered Jan 05 '23 08:01

Andrew Marshall


You can make a setting file for unicorn like this:

working_directory "/path/to/your/app"
listen 4001
pid "/tmp/unicorn.pid"

And then launch unicorn with the following command:

unicorn -c /path/to/your/setting/file.rb
like image 41
Eric Avatar answered Jan 05 '23 06:01

Eric