#335 Deploying to a VPS pro
Deploying a Rails application can be overwhelming because there are so many different options. Here I present a pattern for deploying a Rails app to a VPS using nginx, Unicorn, PostgreSQL, rbenv and more.
- Download:
- source code
- mp4
- m4v
- webm
- ogv
Great screencast, Ryan! I'm comfortable setting servers and, over time, I have created my own system to it but I'm always learning and some of your techniques might be added to my workflow… :)
Question: I always add an nginx conf file for the domain I'm hosting. You simply deleted the default. How does deleting a default automatically make it load the application from the deployer's home directory? Magic sauce there? :)
The capistrano recipe symlinks it to
/etc/nginx/sites-enabled/
AWESOME! Gotta get that going on my systems… :o <3
Thanks man :)
Great question. I was just about to ask the same
Thanks Ryan, this is superb.
Reassuring to see that it's pretty similar to what I bodged together after watching your Vagrant/Unicorn screencasts https://gist.github.com/1985879
in Linux,instead of using:
cat ~/.ssh/id_rsa.pub | ssh user@host 'cat >> ~/.ssh/authorized_keys'
i prefer to use:
ssh-copy-id user@host
That's easy command, and can be found on OS X by homebrew as well
brew install ssh-copy-id
Thanks! Really useful. Didn't know about it.
+1
sha@cluncle.com
+1
+1
I wonder if this could apply to services like EC2.
Yep, you just need to do things a little differently when initially ssh'ing/setting up your keys
Okay, so I'm developing a web app that's going to have around 600 users - creating about 1500 records a day.
After watching this I'm tempted to check out a VPS, but I've only got experience deploying with Heroku ( <- total n00b ).
For my use case, would you recommend a VPS (such as Linode) or Heroku?
I've used three different VPS solutions and each are pretty good. They all provide different features for their price points as well.
ChicagoVPS - They offer a few solutions which are reasonably priced. OS options are somewhat limited. I'm pretty sure you're locked into CentOS 5.
ChunkHost - ChunkHost is slightly more expensive, but offers more options. OS options available are: Ubuntu (8.04 LTS, 10.04 LTS, 10.10), Debian (lenny, squeeze), and CentOS (5, 6). They're offering a free VPS for a limited time as a "beta test." Good for testing.
Linode - Linode is my ol' standard. I've used them for years and have never been disappointed. They offer several solutions and have quite a few features that the others don't have. They also offer flexibility with your Linode (add more storage or an extra IP instantly). OS options available are pretty much anything you can think of. Each option available also comes in a 64-bit flavor if that's your preference (or requirement).
So for my use case would you recommend a VPS over something like Heroku or EngineYard?
It depends on how much control you want over your environment. If you're not expecting your app to have to scale much, you might go with a VPS. However, if you're expecting the app to grow rapidly and for your userbase and daily record commit to increase by a large margin, you might consider a hosted solution like Heroku or EngineYard. Both of those solutions scale very well up and down.
I've been using Slicehost for a few years
this articles helped me a lot: articles.slicehost.com
I know you've gotten some responses but I'll throw in my 2 cents. If you're doing this for fun only then go with whatever you enjoy or challenges you. If you're doing it for money or for recognition, determine what your competitive advantage is/could-be and if either a VPS or Heroku can help you provide your customers with an advantage choose them. If neither of those are true pick one that you trust and can use effectively. I learned a ton by building systems in VPS and on various cloud providers, but at the end of the day rails is my passion (p.s. I work for Heroku). Everyone should know something about how servers are set up, only you can choose which provider is right for you.
Most rails applications have more dependencies, like a sphinx server for example. How would you go about launching these (e.g. in case of a server restart)?
Can something like Foreman be used for this task?
The key is to use foreman to export the proper config for your server http://ddollar.github.com/foreman/#UPSTART-EXPORT
+1
If Linode is your thing another quick way to setup a VPS is to use a StackScript.
http://www.linode.com/stackscripts/view/?StackScriptID=1291
Includes:
*Rails 3
*Ruby 1.9.2
*Nginx with Passenger
*MySQL
*git
*Updates rubygems
*Install rails 3
*Install mysql gem
*Add deploy user
Nice work again Ryan but would love a full cast on deployment.
I've never commented here before, but felt like this episode was worth the comment.
Fantastic. I wish this had been done weeks ago prior to my deployment headaches.
Lastly, I've been a fan of the railsready script found here: https://github.com/joshfng/railsready
What are some security concerns for VPS (linode) vs managed solution (heroku)?
Linode is less secure by default until you do some configuration changes when you get the box -- it comes very unsecure -- Ryan didn't go into it in the screencast (probably for the purposes of time) but you should lock down your VPS root access and only really sudo up to it from another user. Changing your SSH port and turning off password authentication can help too. Also setting up a firewall (even just ufw) will help lock it further down. You may also want to add some blacklisting software to handle multiple login attempts.
http://library.linode.com/security/basics
I'd follow those steps when setting up.
As for Heroku it's a great solution that makes scaling very very easy. The only problem I've had with it is you tend to have to bend off backwards at times to get things working (asset pipeline issues among other things) and you will bump into issues with some gems needing to be configured differently. It's also much pricier relative to using a solution such as Linode.
It does have free plans, however, so you should really try it out and see if you like the workflow. You pretty much make a local git repository for it (or just add another remote host to an existing) and push to it. It handles bundling, getting the server up and running, etc. You can even set environmental variables directly from the command prompt for the server using: heroku config:add KEY_NAME=value
Short answer: Heroku handles all that configuration for you since you don't get root access.
Thanks for the information, will definitely look into the linode security tips!
Sorry, but calling that setup 'Very unsecure' is a big exaggeration. It is not optimal, but definitely not insecure.
For some reason I'm getting this while doing a cold deploy, deploy:setup succeeds however, the repo is on the same server. Tried referencing it through the full ssh url or by giving a local absolute url, no avail.
I would double check that /home/deployer/projects/blog is actually a git repo like the error says.
When creating the repo on the server I usually name the directory #{app_name}.git for clarity, then you need
git init --bare
to make sure the there is no working directory just the repo.Im getting this error with deploy:cold..any ideas?
failed: "sh -c 'cd /home/deployer/apps/burden_farming/releases/20120322200251 && bundle install --gemfile /home/deployer/apps/burden_farming/releases/20120322200251/Gemfile --path /home/deployer/apps/burden_farming/shared/bundle --deployment --quiet --without development test'" on 74.207.240.214
Hey Guys,
Ryan helped me figure this out...I was having issues installing mysql, so I had to manually install the gem:
apt-get install libmysqlclient-dev
then I changed the mysql socket in database.yml to:
/var/run/mysqld/mysqld.sock
Hope that helps anybody who runs into this issue.
thanks a lot (+1)
That was the last piece of my puzzle!
Now everything is running properly!
I am so proud!
Thanks Ryan & Paul
Hi Paul,
I'm getting the same error, but after running the command you mentioned and retrying, i'm still getting it... the command ran properly as i see when trying to rerun it tells me it already has the latest version.
in my Gemfile i have:
gem 'mysql2'
and then the error when deploying:
failed: "sh -c 'cd /home/deployer/apps/sample_linode/releases/20120502195419 && bundle install --gemfile /home/deployer/apps/sample_linode/releases/20120502195419/Gemfile --path /home/deployer/apps/sample_linode/shared/bundle --deployment --quiet --without development test'" on 176.58.101.41
what do you think I'm doing wrong?
OK, I got it to get past this point, but now i'm getting the following error when trying to run the migration.
rake aborted!
database configuration does not specify adapter
I got this error because my VPS server had installed Rails 3.2.8 when my app was running Rails 3.2.6.
Definitely check your Gemfile and your database.yml file (of course). The problem here is clearly stated---Rails is not communicating with your database specifically due to an adapter (aka gem)
how have you passed this probleme ?
Excellent!! as usual...
Would like contribute a little tweek to this with installing gems on production.
create a gemrc (touch ~/.gemrc)
and then copy paste this to avoid fetching the gem docs on install, update and sources, plus some other defualts i use.
+1
+1
Anybody know how to fire up the ruby console in the linode?
Once you're ssh'd in you should just be able run irb at the command prompt.
In the rails app directory should be able to run
To access a ruby console on the production db
Thanks JP - I was using this:
RAILS_ENV=production bundle exec rails c
but your is much easier to type :)
I prefer Heroku, so I can focus on development not setting up and maintaining servers. ;-)
Hello,
I am interrested in Heroku as well, it seems so easy and restful. My only concern is about the price, for a small commercial web-site, let's say 200 visit a day, some mailing processing and a bit of image processing, how much will I pay.
I would be greatful to have an estimation... could you help me?
thx a lot.
You can do a whole lot with a single dyno - and that is for free.
One dyno can serve one request at a time, that is for example 10 100ms requests/sec.
See here for more info: http://devcenter.heroku.com/articles/dynos.
You can also send mails from that one dyno, unless you send bulk mails. I recommend sending those in a background process to not block your web dyno(s). Also note that dynos drop requests that are longer than 30 secs.
A permanently running background process needs at least 1 extra dyno which is 35$/month. But if you don't need a permanent process you can programatically start a dyno when a job is added to the job queue and stop it once it's finished. That way you keep cost low, as dynos are paid per hour.
For image processing I recommend storing the images on Amazon S3 which is rather cheap, check their pricing info for details. Heroku is not suitable for storing files, as dynos are not persisted so you'd loose all uploads after dyno restarts or deploys.
Hope this helps.
Thanks Nico!
I think the most immediate downside of Heroku is that the free tier comes with one dyno that must be booted back up after a short period of inactivity. In other words, the first user to visit your website in a while has to endure the wait until the dyno is spun back up.
Once you cough up the $35/month minimum for an extra dyno, then both dynos stay on. Just something to keep in mind when you're comparing practical price points.
There is a simple fix for this: Just use a pinging service that pings the site every minute or so. I do this with new relic. And voila, your app doesn't fall asleep anymore.
Shhh... that's a dev secret :P
I doubt heroku doesn't know about this possibility... ;-)
I'm not sure if heroku allows cron jobs or not but I had a similar issue with Passenger going to sleep after inactivity on a low traffic app. So in my crontab I added the following:
*/5 * * * * wget -O /dev/null -o /dev/null host.domain.com
This will issue a
GET
request every 5 minutes to your host and keep the app spun up. Note we output the results of wget to /dev/null to avoid any files being created on the server. Works like a charm.Only thing I dislike about Heroku is the lack of Ruby 1.9.3 support
Heroku is good in a lot of situations. However, what disappoints me a little is the lack of JRuby and Rubinius support. This is where EngineYard shines a little more. A lot of Ruby developers probably aren't aware how much more concurrency you can gain using a VPS running JRuby/Rubinius with Puma/Trinidad/TorqueBox rather than running Thin or Unicorn.
For example, TorqueBox (a JRuby-specific App Server) is a "real" application server that runs independently (it's practically a whole infrastructure, not something that just binds to a port), and you deploy your application to this app server. This one single instance uses threads (JVM, not MRI) for everything you would normally have to spin up processes for with MRI (which translates to Dynos on Heroku).
There have been people that took their worker farm (120 worker processes) from around 60gb in memory usage (yes, 60 gigabyte) spread across like 10 dedicated servers, down to about 1gb memory usage on a single server by switching from process-based scaling to thread-based with JRuby or Rubinius. That is huge. Not only does it scale well, you reduce a lot of costs, the infrastructure becomes more simple and imagine running 120 workers on Heroku, the bill goes through the roof. It really makes me wonder why there aren't more people supporting JRuby and Rubinius. (Note that this also applies to concurrent web requests of course, not just workers).
However, I definitely agree you when it comes to being more at ease when deploying to Heroku, simply because you cannot do any administrative tasks. When something breaks, needs updating, and what not, Heroku is the one taking care of it all while you sleep. It mainly depends on your application's requirements. If you have a basic app that doesn't really need a lot of concurrency (be it in the web process, or worker process) then it's all good. However, once you have use cases where you run large worker farms or tremendous amounts of traffic, it might change your game completely.
These are all interesting discussions, I guess basically it comes down to picking the right tools for the job and dealing with certain tradeoffs on each side. But it'd be good to let everyone know it's not just MRI, Thin and Unicorn out there.
What'd I'd love to see from Heroku is (real) support for JRuby (now) and Rubinius (once RBX hits 2.0), perhaps 1GB of ram per Dyno (at a higher price) and the ability to use TorqueBox flawlessly. I think this would be a total game changer for deployments and power per Dyno.
tl;dr:
+1
For what it's worth, if you want to use Torquebox (I heart Torquebox) but want the hands off style of infrastructure that you can get with Heroku it might be worth it to check out OpenShift from RedHat.
It's very similar to Heroku but a little more flexible for your configuration needs. It's worth noting that it's also in the same Amazon data center that Heroku resides in, so any 3rd party services or databases should be able to connect just as easily within the network.
https://github.com/openshift-quickstart/torquebox-quickstart
This has got to be one of the most thoroughly researched and comprehensive Screencast produced by Ryan and he shines.
Nico Ritsche has a great point though. As one lone developer working on a big project (relatively speaking of course), I can simply rely on Heorku to do all my sys admin work and focus on the development. The Developer's docs are also of a high quality and very helpful.
Perhaps Ryan can do one screencast on Heroku?
Hello,
I am interrested in Heroku as well, it seems so easy and restful. My only concern is about the price, for a small commercial web-site, let's say 200 visit a day, some mailing processing and a bit of image processing, how much will I pay.
I would be greatful to have an estimation... could you help me?
thx a lot.
I don't think you will pay much more than $40.00.
Though, as you see here, if you do this on Linode, the cost will easily be halved. This is a rough estimate based on my personal experience however and I may easily be off.
thx a lot
I would love to use Heroku but there servers are US based and for SEO purposes my clients are all UK and UK based services.
Would be nice if Heroku could supply UK based service.
What has SEO to do with server location?
It has everything. see link
Although this is a little old it still stands true.
I doubt that the server IP has much influence on search engine rankings these days. But I'm curious: does anyone have experience with this? Done some tests?
We have tested yes! A resent client with heavy SEO development was ranking around bottom of page one for a number of years. With just the movement to UK server we have seen a 4 place growth with no extra SEO work done. Its a clear indication that it has an effect.
SEOMOZ still stands true with this as well if you search out there forums. But I do think It has come the day for it not to with cloud being so big now.
Okay, good to know. I hope that server location will lose SEO significance. No idea why it keeps having influence these days. Wonder what's the reasoning behind it.
One issue could be speed. The latency for sites to get to our users is quite significant when hosting in the US and users are in Australia.
Great job Ryan. Question: what if you're deploying to a test server first, then up to production? like so: Dev --> Test <--> Prod. The arrow goes both ways between test and prod because the prod database is sent to testing db and the testing code sent to prod server for releases.
Pushing from dev -> test is fine. But how about copying the code from test to prod? I don't want to ever push code from dev --> prod because multiple developers are working on the project and they're all at different points in the code.
I could simply scp the code over, but is there a more efficient way? Thanks all.
Figured out a way from your recent post on Capistrano using Multistage-extension. thnx for that one.
In Europe we smile about the pricing of VPS and RootServers Hosting's in USA ...
Linode: 512mb, 20Gb, 200Gb Traffice => $19.95
Hetzner: 512mb, 20Gb, 1Tb Traffic => €7.90
Heroku..unpayable..
When you work with clients you def. also need an Adminplatform for them to install their own email accounts etc..
Anyway thanks for this screencast..and all the others. So helpful.
Werner
I pay €10.85 for my hetzner servers with 1024 MB RAM. They come highly recommended. They're in Germany.
I might be asking too much but where should seeds be run?
you can run rake db:seeds as a remote task under Capistrano's control. See the revised screencast.
Im using carrier wave to store uploaded files, but when I do a deploy, those files get overwritten and are not longer accessible, cause they are in previous releases...I know I could use something like a3 for file storage, but I don't really require that right now...
Any ideas on what I might be able to do copy the previous deploys "upload" dir back into the "current" app?
Thanks!
I just had this problem, you need to set capistrano to symlink youre public/whatever directory to a shared directory of your choosing.
See the answer to this stack overflow question
http://stackoverflow.com/questions/4648180/keep-unversioned-files-when-deploying-with-capistrano
anyone got a clue why this would happen to me?
sh -c 'cd /home/deployer/apps/appname/releases/20120324031224 && bundle exec rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile'
** [out :: 106.187.88.49] rake aborted!
** [out :: 106.187.88.49] FATAL: password authentication failed for user "deployer"
Can't figure it out to save my life. :)
I'd check if you aren't typing the correct deployer password.
strangely its in a script and doesn't ask for a password... perhaps thats why?
I would check the following:
1. Make sure that your target server, e.g., Linode is known to your source, e.g., GitHub server.
2. Make sure that you can follow your script manually, i.e., type in each command on the terminal and see where you get asked a password related question and try to use public/private key authentication to automate the authentication process.
That should help you isolate the problem.
Did you ever figure out what was going on there? I'm running into the same issue
All of a sudden I'm facing the same error as well, and it's happening on more then one projects, so shouldn't be in the asset files...any ideas anyone?
The issue will be that Rails tries to connect to the database even just for assets precompiling, and the login for it fails. Check your database.yml so that it works when run on the web server etc.
check your database.yml file. Rake tries to connect to DB.
I solved this by adding bundle exec like:
bundle exec cap deploy:setup
11 months later...the answer to this question is capistrano (as well as some other applications) expects to find a database owned by a user of the same name 'deployer' (read that in the postgres documentation). I'm wondering if you happen to be developing in windows so won't be using agent-forwarding, and I suspect this is the root cause of permissions errors.
A perhaps related problem...I'm getting a permission-denied error when the capistrano task deploy:start/restart attempts to run. Anyone know why? Anyone still read these 11 months later?
I still read these. :)
Did you resolve your permissions issue?
Were you able to solve this issue? I'm running into the same problem.
Did you solve this issue? I've having the same problem.
Yes I did. May have commented below somewhere but this is a windows specific problem because it doesn't support agent-forwarding. If you need more help I wrote everything down, but in short:
Make sure the postgresql database owner and password match the deployer username & password.
Then, I also needed to add
run "chmod +x #{release_path}/config/unicorn_init.sh"
to the symlink_config, so it would remember it has permission.
Set up the git repository on your vps, since again it won't forward from git.
How is the 3rd step? I'm getting the same problem on windows
Is it something like
git clone
?I had the same issue. I found that I needed to do the # ssh setup steps before I attempted cap deploy:setup. In the video, the ssh is done after and appears to be convenience only but in the show notes its before.
Problem with
assets:precompile
Thanks to ryan I can deploy my app with capistrano now but evertime come the
assets:precompile
command it takes longer and longer.In fact assets subdirectories are added everytime :
app/public/assets/assets/assets/assets/assets etc .....
It looks like it compiles all assets recursively.
I thought it because I have :
config.assets.precompile += ['*.js', '*.css']
but even if without the problem shows up.Any idea ?
I just tried on local. No link with capistrano.
But the problem still remains.
From scratch, first compilation, it generates 3 levels of assets directory. /public/assets/assets/assets
I found out, it's because in application.rb :
config.assets.paths << "#{Rails.root}/public"
Thank you!! I don't understand why this is causing this problem though. I've commented this line, and it seems to work, but doesn't this line tell Rails where to find other non-compiled assets that should be served statically? What is the right way to configure this? I've posted on StackOverflow as well: http://stackoverflow.com/questions/14506997/why-is-the-asset-pipeline-re-compiling-compiled-assets-creating-redundantly-nes
Fantastic screencast Ryan! So many rails developers are bewildered by the deployment process or have no idea how to setup the stack from scratch.
While capistrano is indeed a great tool and allows you to maintain very complex setups, but overtime found it to overkill for simple webapps with just single production server and maybe a staging server. Having tried heroku I really think git is the way to go in this case. Setting up post–receive hook on the the server is really very simple and all your deployment boils down to running 'git push production localbranch:master'.
With regards to unicorn I really see no reason you chose it as oposed to phusion passenger. It is an extra dependency that needs to be maintained. For me the beauty of using passenger lies in the fact that I don't need to maintain a separate service and make sure it is running at all times.
This is a great screencast, but I'm having an issue that I can't seem to get around.
I deployed my app, but it comes up with a 500 error every time (with my custom 500 error html page). I tried looking in the log, but it doesn't seem to be logging anything at all, so I'm at a loss to figure out what my error is.
Any ideas?
Thanks!
Which log have you looked at? You probably want to check your unicorn/production logs
I'm getting the same problem. I was actually able to go around it temporarily by running webrick from the app directory ($ rails s) and then hit my server at port 3000 (example.com:3000).
The last answer on this page suggests that maybe routes are not being created and thus the 500 error.
http://stackoverflow.com/q/9059712/1130736
Unfortunately the link to the fix is broken, but I flagged it so hopefully it will get fixed.
p.s. is the unicorn.log file supposed to loop/scroll without stopping? Seems odd to me when I'm not hitting the app.
YEAP !!
It is a problem! When you look at config/unicorn.log file, you will see that the release number is the wrong one and it is not the current one. Thereby, unicorn cannot find its gems.
I would really really appreciate any help on that.
These comments are more than 6 months old but I came across the same problem and the fix is to stop and start the unicorn service separately after cap deploy
unicorn_init.sh seems to have an issue for a restart with the following:
The unicorn service will not point to the latest release and recognize the new gems you might have added to the Gemfile since your last deploy.
Hope this helps.
Thank you.
'cap deploy:stop'
'cap deploy:start'
Fixed my route issues. Whenever I created a controller and updates everything, on my VPS it would not come up. After doing this then all my routes are working fine
I had a similar problem, wherein my updated code is not being loaded by unicorn even after reload. Turns out that it's because I have my unicorn config file set preload_app to true, and sending a HUP signal, which unicorn_init.sh uses for reload and restart, would not make unicorn load the code changes (see HUP under http://unicorn.bogomips.org/SIGNALS.html). So I modified deploy.rb to use
%w[start stop reload upgrade].each do |command|
instead and use 'reload' for changes in unicorn.rb and 'upgrade' for rails code changes
THANK YOU!
This screencast is brilliant -- much needed by many (obviously, from the comments!), and good to have out there.
I am a big fan of running the app as a special user, rather than root, so glad to see that.
It's also funny -- I love the occasional remarks like "this probably won't work the first time" for Capistrano. Understatement is the best form of humor ;-)
Finally a vote for a fantastic VPS host I have used since 2006 -- RimuHosting has great prices, many options, and best of all, really competent people to help when things go wrong.
How would you deploy to multiple stage environments with your unicorn configuration? Specifically, how to you change:
to
when you run
cap staging deploy
orcap production deploy
, respectively?One answer: pull
unicorn_init.sh
out of source control and put it in the#{shared_path}/config/
directory and symlink to it likedatabase.yml
.Hi Andrew,
Once we have the production working as we have in this video, is this just good enough to configure staging or any other environment of the same app? what about to run one more app in the same server.
Thank you
Troubleshooting tip:
If your cap deploy is failing, and you're logging into your server to troubleshoot manually, when you ssh to the server, if Agent forwarding is not already configured by default on your local machine, you'll need to enable it so you can communicate with github:
instead of:
ssh deployer@your-server.com
use:
ssh -A deployer@your-server.com
running postgresql fails. see error
Just a bit of configuration to do and it will be okay: http://www.flynsarmy.com/2011/04/fixing-perl-locale-errors-in-a-clean-ubuntu-install/
To fix the psql issue, make sure the postgresql version you installed is not 8.4 but 9.1
I had the same problem. Found the solution here:
http://ubuntuforums.org/showthread.php?t=1396862
Uninstalled postgresql-common and reinstalled postgresql and libpq-dev
apt-get purge postgresql-common postgresql libpq-dev
apt-get install postgresql libpq-dev
Great episode Ryan. My only question was is there a reason you used rbenv over rvm to install ruby? Has rvm fallen out of favor? Are you using rbenv on OS X?
Ryan,
I followed these directions exactly but when I visit http://[ip] I get "Not Found: /". However, when I visit http://[ip]/[appname] it hits the app. Is it possible one of the paths in one of the configs is wrong?
Well, turns out the rackup file was tampered with! :-/
Hey Ryan - it would truly be AWESOME if you could include your Linode server setup script and share it over there!
I have a problem, my nginx server is running with nginx user, and when the application try to access the /assets files i have a 403 http error. I changed the nginx user to deployer group but the issue persists. Can you help me to fix this? The only difference between your post and my server is i'm running in a centos distribution.
I correct this issue changing the permission of public/assets folder to this --> chmod o+rx, now works fine.
did you have to restart nginx or the app?
Hey, great video :)
Just a minor issue: I'm using branch other than master for deployment and in my opinion deploy.rb:44 should not include hard-coded branch.
I have an issue when I want to restart Unicorn, the pid and sock files aren't deleted when it is stopped so when Capistrano want to start Unicorn, it fails due to the files already present.
Anyone have an idea to fix this?
Delete the .pid et sock files before trying to start Unicorn again.
Yes but I don't want to do it manually each time I deploy an update...
I found that nginx was using /var/run/nginx.pid instead of /tmp/nginx.pid for the pid file by default. Just had to change nginx.conf:
I'm trying to use Passenger and have now twice hosed my install.
I can successfully complete this line of the script in the show notes
But when I go to run
I get a
sudo: gem: command not found
error.If I
exit
the deployer session andsu deployer
from root, I get this error:/home/deployer/.rbenv/bin/rbenv: line 20: cd: /root: Permission denied
Then running
ruby -v
gives me this errorbash: ruby: command not found
when previously that worked for deployer.Any ideas what I'm doing wrong?
Have you tried to install rbenv for the root user too?
Have you tried running
rbenv rehash
again.I had to re-run
rbenv rehash
after installing the passenger gem so thatpassenger-install-apache2-module
would work.Also, I didn't
sudo
the gem installation.Ryan,
I wrote a very simple provisioning tool to help people setup a new instance on VPS. It has a bonus feature to setup / teardown Linode instances interactively, by choosing plans and datacenters, etc.
https://github.com/kenn/sunzi
I hope this helps to anyone who scratched their head dealing with chef / chef-solo!
I really like sunzi ;)
Good work.
Hi,
I got some problem about my app.
And Have no idea about where to look the development.log?
Depends on the problem. But in general yeah you should be looking at the logs. There is the server log and also production logs. I don't think you want to be looking at the development log when in a production environment.
Great screencast :)
But I ran into a problem when Capistrano tries to build my assets. I have no idea what's going on, if I start rails locally, everything works fine!
But in my Gemfile I have bccrypt-ruby set up.
Edit: Executing the command on the server without Capistrano seems to work. :/
I had this issue. I develop on Windows 7, and certain gems have windows-specific versions. I went into my Gemfile.lock and removed all "x86-mingw32" in the gem version numbers. After commiting the changes and deploying again, it worked.
I also had this problem with postgres and the pg gem.
Is there a referral code for Linode we can use when we sign up, so Railscasts can receive a referral fee?
Ryan, Great show. One question though. Why Ubuntu 10.04 LTS and not Ubuntu 11.10? Is there any issues with Ruby or Rails on Ubuntu 11.10? The reason I'm asking is that I was going to try this with a spare machine I have lying around and it currently has 11.10 installed (nothing else). If there are issues then I will just re-roll it with 10.04 LTS
Chris you could set up Vagrant / Virtual box, which would give you the flexibility to test different OS versions.
Thanks Andy, I will try that. I still am wondering if 10.04 LTS is better than 11.10. because I have this extra box lying around. The plan is to set it up and put it in my routers DMZ and then access my test sites from outside my home office. Can't do this with a VirtualBox setup
Hi Guys,
i don't really understood, how can deploy:setup successfully completed?
Because we can't create symlinks to non existing files.
Only after deploy:cold we get current folder with nginx.conf and unicorn_init.sh files.
Or I don't understand something.
Did you get an answer to this? Facing the same issue.
how did you solved it ?
+1
How would I configure multiple websites on the same box? I know they would each be in a different directory by application name but how would I redirect using domain name. I know I would have to use apache virtual hosts but with Nginx I'm not sure.
Would it be better to have one IP address or multiple (looks like $1/IP on Linode).
Got it. I had to customize nginx.conf
I used this with my "main" app
listen 80 default deferred;
Do you see any ways to improve this?
+1
Hey jDeppen thanks for posting this. Is this the only change you made? I tried it and am getting this error when starting Nginx:
I have 2 apps, blog and blog2. Followed Ryan's recipe verbatim with both apps, with one change (besides using blog2 in 2nd app). I have 2 domains propagated to my VPS and am using those as the server_name on line 7 of nginx.conf. I've been doing some Googling to see if there's anything I need to be doing with my hosts file, but no enlightenment.
You can't use "upstream unicorn", you have to customize for each app "upstream unicorn_app1". I got stuck there too.
This saved my ass today. Thanks.
Hi jDeppen,
I moved
to /etc/nginx/nginx.conf (if your setup is similar to Ryan's)
Good idea to backup nginx.conf before changing it. Run
I hope this helps.
*remember to remove the "listen 80" line in each nginx.conf file in each app.
Here's what I got
So I had to keep these lines outside the server block to make it work:
All of my apps had:
listen 80;
except for my main app, it had:
listen 80 default deferred;
So the only difference is I don't have a default app (IP address gets 404 Not Found)
Thanks for your post, that DRYs it up a bit.
+1... Saved my day!
thanks, helped me a lot. +1
+1 Thanks!
Thanks Ryan!! Heroku and Engine Yard are great! But it is nice being able to test my applications live while keep cost in mind!
Hi, anyone got a clue why this would happen to me?
Thx :)
I am also getting the same error. please someone help...
Give this a try
After applying :primary => true, I am getting this error
me 2
Ryan wrote this deploy.rb file with Ruby 1.9 syntax for hashes, and you appear to be using Ruby 1.8. I was also using Ruby 1.8. Here's how I fixed it:
At each place where it says "roles: :{role}", you need instead ":roles => :{role}".
The same is true for that "except: {no_release: true}" formulation, which needs you to add two hash arrows. It should become ":except => { :no_release => true }".
Thanks..
Try
bundle exec cap deploy:setup
.You saved my day!
I followed this and am getting a 500 error complaining that
application.css
is not precompiled.I logged into the server and ran
rake assets:precompile
without issues, but running the app gives the same error again.Any ideas?
Ack, I knew I'd figure it out as soon as I posted a question. I needed to restart the server.
Not sure why this didn't work during
cap deploy
the first time, though.This is exactly the episode I was looking for. Ryan Bates is a leg-end!
One thing I'm not sure about:
Should there be a call to
rbenv rehash
inserted some where in one of the capistrano recipes. I tried adding paperclip to a project and deploying it but the application is not picking it up when it starts up. The recipe does run thebundle
command to install new gems when doing a standardcap deploy
but from what I can see from reading around I suspect therbenv rehash
needs to be called after thebundle
command and I'm not sure if it is included in the recipe provided by Ryan in this example. If this is the case it would explain why my app is not picking up paperclip and is not starting. I'm not sure myself where or how I would make the call torbenv rehash
in the capistrano recipe.Perhaps some would be kind enough to point me in the right direct?
Did you ever get an answer to your question? I'm having the same problem.
I'm stuck too with a similar issue : any gem added to Gemfile seems to not to be found by the application once deployed. This results in classes not found by autoload:
I, [2012-06-20T18:48:51.712022 #17056] INFO -- : worker=3 spawning...
I, [2012-06-20T18:48:51.723871 #15773] INFO -- : worker=3 spawned pid=15773
I, [2012-06-20T18:48:51.731071 #15773] INFO -- : Refreshing Gem list
E, [2012-06-20T18:48:51.868403 #15761] ERROR -- : uninitialized constant Refinery::Blog (NameError)
/home/deploy/apps/s2w_refinery/releases/20120620163007/config/initializers/refinery/blog.rb:1:in `'
+1
+100
I tried restarting Unicorn and nginx hoping Unicorn will notice the new gems, but it wouldn't work. It seems that you have to STOP unicorn, then START it again, it worked for me.
This fixed a TONNE of problems for me! I tried everything but this worked! Grrrrr....
Thanks very much :)
This stumped me as well and caused me to burn several days. In the end it was a simple restart of unicorn that fixed it
/etc/init.d/unicorn_my_app stop
/etc/init.d/unicorn_my_app start
Which i got from this ref
http://stackoverflow.com/questions/10756626/initializer-or-gem-not-loaded-with-unicorn-causing-500-internal-server-error
on the up side, while I was tearing out my hair and trawling the internet for knowledgez, I learned more about bundler and gemfile.lock and cap deploy:rollback and rails console (bundle exec rails console -e production
)
so all around not a loss.
Hello, i have questions about multi rails apps with unicorn. If we want to add two or more rails application with unicorn in nginx, how can we create the multi-unicorn-process startup/shutdown script?
I googled more of them somebody prefered god gem but i couldnt find proper solution for this.
Can you have any idea?
Great screencast! I'm wondering how I would configure the deployment to support an app that offers users basecamp style subdomains?
Any tips on getting hstore to work on Linode following these directions? I am seeing:
PG::Error: ERROR: could not open extension control file "/usr/share/postgresql/9.1/extension/hstore.control": No such file or directory
depending on your distro you might need to do some installation-fu
e.g. for an ubuntu install recently i had to do
apt-get postgresql-contrib
Thx :)
Huge help !
This did not fix my problem :( Do I need to restart my postgre server? Trying now. Will report.
**Back: restarting didn't work, the apt-get thing did that anyway. Rails required version 9.1 (TIMELY--THIS WILL CHANGE. Give rails what it asks for in the error message.). I installed the one listed on the github site (9.0) and it still didn't work. Then, like Mrs. Griswald., I tried sudo apt-get install postgresql-contrib-9.1 instead of sudo apt-get install postgresql-contrib-9.0 and walah, problem solved. Back to the other problem. :)
Hey guys, two questions. First, can anyone point me to a good tutorial that would help with adding a 2nd application on the same server with a configuration like this. Second, lets say I wanted my app on Heroku to act as a staging app. Could you use a setup like this to pull from Heroku rather than Github?
This is as close as I've come to finding a good tutorial. I'm not skilled enough to reconcile the differences between that walk-through and this Railscast.
Have you found anything?
Hello!
May scripts from /etc/init.d/ be run by root at startup time?
If so, we have vulnerability allows "deployer" user change unicorn_init.sh and get root access, havent' we?
sudo "ln -nfs #{current_path}/config/unicorn_init.sh /etc/init.d/unicorn_#{application}"
Hello!
Why rbenv, not rvm ??
I am using Mongodb/mongoid with my Rails project. I followed the steps given. Most of things worked. But I am stuck at making mongo to work.
2 I suppose I should install Mongodb on Linode server and just keep it runing and pointing the production server to localhost in my mongoid.yml file. Does that sound right?
3 I wanted to make things generally working without setting up mongoid.yml correctly. But then because I have database.yml there with unused sqlite3 reference, cap deploy:cold gives error about sqlite3 not in the gemfile. I suppose if I remove config/database.yml altogether, it should not ask me to include sqlite3 any more?
These questions might be too specific to my situation. But any links to relevant information that can help me would be really appreciated.
On 12.04, I ran into an error about the admin group not existing. All I had to do to fix it was run
groupadd admin
. The group is already listed in the sudoers file, it just wasn't created when the distro was installed.+1 thanks curtis
muchas gracias
I ran into this same problem. Turns out that Ubuntu is deprecating the "admin" group in favor of the "sudo" group, as that's more consistent with the upstream implementation and Debian.
I found this is the Precise release notes at https://wiki.ubuntu.com/PrecisePangolin/ReleaseNotes/UbuntuDesktop
Right. See also http://ubuntuforums.org/showthread.php?t=1889595 So, if you are on Ubuntu 12.04 or later, it better to use the 'sudo' group.
Very helpful!! Thanks
I wanted to check with the community is this is still working for everybody.
I am having issues when using unicorn with a Capistrano deployment. From what I have been able to understand Capistrano uses a scheme in wich every release is deployed inside the releases directory under a unique name and if the transaction was successful, creates a symlink named current that will point to that release.
So I end up with a deployment directory such as:
/home/deployer/apps/sample_app/current
Then when I try to start unicorn from the binstubs directory all the unicorn methods look for things in the following path, particularly in the configurator.rb module:
/home/deployer/apps/sample_app
I haven't been able to fully understand how unicorn sets the working_directory from here:
https://github.com/defunkt/unicorn/raw/master/lib/unicorn/configurator.rb
But I wanted to check with the community if I am missing something evident due to the noob nature in me.
I had to add /current to the working_directory and others on unicorn.rb
working_directory "/home/deployer/apps/sample_app/current"
pid "/home/deployer/apps/sample_app/current/tmp/pids/unicorn.pid"
stderr_path "/home/deployer/apps/sample_app/current/log/unicorn.log"
stdout_path "/home/deployer/apps/sample_app/current/log/unicorn.log"
Thanks for the great work!
Is there a way to view a log output from Unicorm like WEBrick? My app is deploying correctly, but isn't running correctly off the sever. I'm just getting the useless error pages.
Finally fixed it. I forgot to replace a couple other 'blog' with 's. I wasn't specifically able to push the change out by updating the unicorn.rb file. I ended up renaming the 'unicorn.blog.sock' and that fixed it.
I'm getting an error when I first run cap deploy. I have put up the error I'm getting here but can't seem to find the soloution anywhere.
Error with cp
Any ideas?
I get this error as well when I run cap deploy:
* executing `deploy:check_revision' fatal: ambiguous argument 'origin/master': unknown revision or path not in the working tree. Use '--' to separate paths from revisions WARNING: HEAD is not the same as origin/master
but it's worked fine to call cap deploy:cold every time.
Can anyone suggest an EC2 image to use?
My linode had to get restarted yesterday and I noticed that while the nginx service started properly, the unicorn socket didn't come back. I wonder how the deployment needs to be tweaked for events where the server has to get restarted. I assume it's a matter of running bundle exec unicorn on server startup.
I just noticed that too, Unicorn doesn't seem to start again after a server reboot even though it should, according to rcconf: http://minus.com/mbElBG9hS/
This is the last bit of config I need, I really don't feel comfortable having to manually start unicorn after a reboot, any help would be greatly appreciated :)
Did you find a solution for Unicorn not starting after a server reboot?
I have the same issue.
Never mind.
Had forgotten to run:
sudo update-rc.d -f unicorn_appname defaults
for some reason, at the last step on cap deploy:cold it is not allowing me access. this is the output:
* executing `deploy:start' * executing "/etc/init.d/unicorn_mock_app start" servers: ["MYIP"] [MYIP] executing command ** [out :: MYIP] sh: /etc/init.d/unicorn_mock_app: Permission denied command finished in 150ms failed: "sh -c '/etc/init.d/unicorn_mock_app start'" on IP
I tried changing the permission to the symlink by running:
chmod +x /etc/init.d/unicorn_mock_app
But then it outputs
any ideas?? on why it wont allow permissions for the app to start
nevermind im about to throw my pc out the window
had to use dos2unix on the unicorn_init.sh in order to get it to insterpret it righ
thanks!
I did all the instructions and successfully deployed, but then when i tried to access it, it was automatically redirect my browser to https://IP.
This is what Chrome said:
Error 102 (net::ERR_CONNECTION_REFUSED): The server refused the connection.
I though it was because i forced the SSL in production.rb and then i set it to false and redeployed. But nothing changed!
After that i set the ssl force back and try to install SSL using the instruction in http://railscasts.com/episodes/357-adding-ssl, and i had a problem in nginx when i tried to install:
Restarting nginx: nginx: [emerg] unknown directive "server" in /etc/nginx/nginx.conf:10
nginx: configuration file /etc/nginx/nginx.conf test failed
Can anyone give me a solution for this? Thanks in advance :)
Restarting nginx: nginx: [emerg] unknown directive "server" in /etc/nginx/nginx.conf:10
nginx: configuration file /etc/nginx/nginx.conf test failed
About this error, i found it because of my fault.. i should insert the SSL configuration inside nginx.conf in my rails config folder.
And i still have this error:
Error 102 (net::ERR_CONNECTION_REFUSED): The server refused the connection.
Does anyone know how to install the unaccent extension for pg?
PG::Error: ERROR: could not open extension control file "/usr/share/postgresql/9.1/extension/unaccent.control": No such file or directory
If you are using a Debian distro like Ubuntu, you can do what is suggested in this StackOverflow answer as it worked for me.
it happened to me
servers: ["my.com"]
[my.com] executing command
** [out :: my.com] cp:
** [out :: my.com] cannot create directory `/home/rails-apps/my-beta/releases/20120620085906'
** [out :: my.com] : No such file or directory
** [out :: my.com]
For some of the strangest reason i cannot seem to solve this to save myself .
Which leads to :
> failed: "sh -c 'cd /home/deployer/apps/app_name/releases/20120624151117 && bundle exec rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile'" on 106.187.36.187
This bug just appeared just out the blue . Have tried for hours so if anyone else knows how to fix , please save me.
I just updated the twitter-bootstrap-rails gem and it worked.
To 2.1.0 or to master? I still see the issue with master on Heroku as of today (it's been like that for a week).
I solved it downgrading to 2.1.0. I was using version 2.1.1.
had the same issue and was stuck for hours. issue is with font awesome, here's the solution: https://github.com/seyhunak/twitter-bootstrap-rails/issues/292
Great tut!
But does anyone of you have any problem with openssl savon and the guide above?
I get
OpenSSL::SSL::SSLError (SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: sslv3 alert unexpected message):
Any tips? Do a need to generate a certificate on the server (guide does not state that).
Problem
I've been fighting with that one for a while now. That is the cry for help. As suggested I've going through all the commands and executed them on the remote server.
The command that fails on the server is:
It says: \n not found. As far as I can tell, it doesn't like the new lines. When I put them away manually - everything goes OK.
The interesting this is - the deployment script seem to execute this command OK, and it is the next one it stables upon (bundle install). Although when executing manually on the sever - bundles get installed OK.
What can it be? And how, and where, do I edit those new lines "\\n" out?
Complete Output:
add the following to the top of your config/deploy.rb
require "bundler/capistrano"
set :default_environment, {
'PATH' => "$HOME/.rbenv/shims:$HOME/.rbenv/bin:$PATH"
}
did this work for you Andrew?
I tried this but am still running into the same error. Can't seem to find the solution anywhere
this worked for me. thanks. the system could not locate bundle.
Thanks!
Hey guys, I have followed the instructions to the line.. I got to here;
deployer@ve:~$ rbenv install 1.9.3-p125
... little help?
The VPS I'm using is Media Template. Apparently they mount /tmp with noexec.. To resolve this;
then go back and run rbenv install 1.9.3-p125 again.
Once done, just umount and reboot for it to put /tmp back as a noexec..
I tried to remove the noexec and remount but it wouldn't let me.. shrug
Thank you Ryan. After struggling for a few days with Linode/Debian6/rvm/capistrano/passenger/enginx I gave up and followed this screencast to success in a couple of hours. I decided to follow exactly so my stack is the same as yours. I am sure I was doing terrible things with rvm. My brain isn't quite as large as Wayne's and rvm does a lot of magic with system commands such as cd. Even rvm implode didn't seem to uninstall without side effects. Hence the reinstall of the OS. I think rvm is powerful & useful and would love to see an in depth railscast on it.
Great Railscast! I've always used Heroku. Is there an equivalent command to 'heroku logs' on VPS with Nginx?
Thanks!
Thanks Ryan. I am getting "500 Internal Server Error" error after installing nginx. Not sure what I am missing, even though I am following exact steps mentioned in the web cast.
I'm too.
I also. I'll look further tonight, but have either of you resolved this? Here is the error in the nginx/error.log:
rewrite or internal redirection cycle while internally redirecting to "/index.html"
so it's something in the default config settings.
ok. So I just edited /etc/nginx/sites-enabled/default and changed the root element in server {} to
root /usr/share/nginx/html
rather than
root /usr/share/nginx/www
and it works. Moving on. Once I get the kids. :)
yep i noticed the same problem, wonder why the default nginx install has that issue.
Anyways your fix worked.
Thanks
Hey guys i am getting this error:
any ideas?
this is at the cap deploy:cold step
Did you ever find an answer to this? I'm can't seem to beat this one.
Answered my own question. Rewrote the unicorn_init.sh file on a Unix machine instead of my usual Windows box.
I'm getting a
failed: "sh -c 'cd /home/deployer/apps/angel_list_api_research/releases/20120827050009 && bundle install --gemfile /home/deployer/apps/angel_list_api_research/releases/20120827050009/Gemfile --path /home/deployer/apps/angel_list_api_research/shared/bundle --deployment --quiet --without development test'" on 198.58.96.39
Has anyone any idea what this is trying to tell me?
I have no issues compiling assets with my rvm setup on my current hosted env. Going thru these steps (using rbenv) I can't get the assets to compile. Really strange stacktrace
RAILS_ENV=production bundle exec rake assets:precompile --trace
** Invoke assets:precompile (first_time)
** Execute assets:precompile
/home/deployer/.rbenv/versions/1.9.3-p194/bin/ruby /home/deployer/apps/Merj-Web/shared/bundle/ruby/1.9.1/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets --trace
** Invoke assets:precompile:all (first_time)
** Execute assets:precompile:all
** Invoke assets:precompile:primary (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
** Invoke environment (first_time)
** Execute environment
** Invoke tmp:cache:clear (first_time)
** Execute tmp:cache:clear
** Execute assets:precompile:primary
rake aborted!
Command failed with status (): [/home/deployer/.rbenv/versions/1.9.3-p194/...]
/home/deployer/apps/Merj-Web/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/file_utils.rb:53:in
block in create_shell_runner'
call'/home/deployer/apps/Merj-Web/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/file_utils.rb:45:in
/home/deployer/apps/Merj-Web/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/file_utils.rb:45:in
sh'
sh'/home/deployer/apps/Merj-Web/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/file_utils_ext.rb:39:in
/home/deployer/apps/Merj-Web/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/file_utils.rb:80:in
ruby'
ruby'/home/deployer/apps/Merj-Web/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/file_utils_ext.rb:39:in
/home/deployer/apps/Merj-Web/shared/bundle/ruby/1.9.1/gems/actionpack-3.2.8/lib/sprockets/assets.rake:12:in
ruby_rake_task'
invoke_or_reboot_rake_task'/home/deployer/apps/Merj-Web/shared/bundle/ruby/1.9.1/gems/actionpack-3.2.8/lib/sprockets/assets.rake:21:in
/home/deployer/apps/Merj-Web/shared/bundle/ruby/1.9.1/gems/actionpack-3.2.8/lib/sprockets/assets.rake:29:in
block (2 levels) in <top (required)>'
call'/home/deployer/apps/Merj-Web/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:205:in
/home/deployer/apps/Merj-Web/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:205:in
block in execute'
each'/home/deployer/apps/Merj-Web/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:200:in
/home/deployer/apps/Merj-Web/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:200:in
execute'
block in invoke_with_call_chain'/home/deployer/apps/Merj-Web/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:158:in
/home/deployer/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/monitor.rb:211:in
mon_synchronize'
invoke_with_call_chain'/home/deployer/apps/Merj-Web/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:151:in
/home/deployer/apps/Merj-Web/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:144:in
invoke'
invoke_task'/home/deployer/apps/Merj-Web/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:116:in
/home/deployer/apps/Merj-Web/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:94:in
block (2 levels) in top_level'
each'/home/deployer/apps/Merj-Web/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:94:in
/home/deployer/apps/Merj-Web/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:94:in
block in top_level'
standard_exception_handling'/home/deployer/apps/Merj-Web/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:133:in
/home/deployer/apps/Merj-Web/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:88:in
top_level'
block in run'/home/deployer/apps/Merj-Web/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:66:in
/home/deployer/apps/Merj-Web/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:133:in
standard_exception_handling'
run'/home/deployer/apps/Merj-Web/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:63:in
/home/deployer/apps/Merj-Web/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/bin/rake:33:in
<top (required)>'
load'/home/deployer/apps/Merj-Web/shared/bundle/ruby/1.9.1/bin/rake:23:in
/home/deployer/apps/Merj-Web/shared/bundle/ruby/1.9.1/bin/rake:23:in `'
Tasks: TOP => assets:precompile
hey guys tried the guide again and i am again getting the following error:
any ideas?
Did you find a solution to this?.. I am getting a similar error!
Awesome screencast! I've used this multiple times for reference and works great. However, I recently tried following this example, but instead of installing rbenv I had to use rvm. And when I get to the point of running 'cap deploy:cold' I keep getting the following error: sh: 1: bundle: not found. I installed bundler correctly and confirmed it by running 'bundle -v'. One thing I did notice in previous apps when following this tutorial (when using rbenv) that under my_app_directory/shared there would be a bundle/ directory, however now that directory doesn't exist, so maybe that is the 'bundle not found'? Any ideas?
i have the same error...
Greg,
My VPS is now runnig.
I made a list of commands that maybe you will find useful
https://gist.github.com/3701678
it's because capistrano is loading bundler incorrectly.
to fix this, in your Gemfile, add both
gem 'capistrano'
gem 'rvm-capistrano'
In deploy.rb,
insert the following line at the top: require "rvm/capistrano"
it should solve the bundle not found issue
I know this is a bit old now but I had this issue and followed this to solve it.
http://henriksjokvist.net/archive/2012/2/deploying-with-rbenv-and-capistrano/
So i'm having a weird issue - followed the instructions to the tee on a new EC2 instance running Ubuntu 12.04 (only wrinkle was in the rbenv install process, found a good tutorial explaining the differences here: http://www.stehem.net/2012/05/08/how-to-install-ruby-with-rbenv-on-ubuntu-12-04.html
So i THINK i'm in good shape! UNTIL I try to cap deploy: the connection hangs AFTER connecting successfully..?! Turned on SSH logging, and the key exchange is successful, but then the script doesn't continue. I CAN login without a password from the terminal, so I know my key is set up correctly on my deployer user.
It's all a little odd.
Thanks
I love this railscast. I have had to make some changes and such to the unicorn configurations to work with my platform, but overall it works well. Nice starting point.
Hi all...
I've tried to execute this railscast but i received this error.
failed: "sh -c 'cd /home/webadmin/apps/apptest/releases/20121002133503 && bundle install --gemfile /home/webadmin/apps/apptest/releases/20121002133503/Gemfile --path /home/webadmin/apps/apptest/shared/bundle --deployment --quiet --without development test'" on 10.X.X.X
It seems the copy cache is not copied in the release folder...
Thanks for your help
it was the rbenv path on the server
Hi,
I've a new question.
Which is the best way to completely remove an apps deployed by capristano.
nginx vhost unicorn_init script,....
Thanx
Bloody hell, that's complicated!
Sometimes it is better not to write
I am running on windows ,,,and I usually used to deploy to Heroku ,and I want to try linode . I have a question "deploying from different operating system like windows which I am using ,could work ?"
regards
the problem That I did the steps but when running service nginx start .....no welcome message ,,just only error message ...I dont know why.?..the steps were working great before installing nginx ...
I had the same problem. As "Steve Fox" mentioned before, you just have to change:
root /usr/share/nginx/www
to
root /usr/share/nginx/html
in this file:
/etc/nginx/sites-enabled/default
and then restart the server.
+1
+1
Hi, thanks for this Screencast.
I have some troubles installing postgresql.
When typing in:
apt-get install postgresql libpq-dev
I get: could not find libpg-dev
Does somebody knows the problem?
Thanks
This is nice it solved my problem
Thanks
I've found a very similar article:
http://rubysource.com/deploying-a-rails-application/
(maybe copied from you ryan)
do you know how to solve these problem ..I searched a lot with no answer
/etc/init.d/unicorn_depot_2: Permission denied
It deployed correctly the first time but after second deploy it stopped working. I was getting problems with nginx and unicorn.
The problem was related to permission for unicorn_blog service. In deploy.rb we are starting the app with normal permissions.
run "/etc/init.d/unicorn_#{application} #{command}"
After changing it to
sudo "/etc/init.d/unicorn_#{application} #{command}"
everything started to work.
I don't know why it is necessary. I followed all instructions correctly.
I've also had the same problem.
The reason is
unicorn_init.sh
file doesn't haveexecute
flag on server site.To do that let's add following line into
deploy.rb
at:symlink_config
task section:sudo "chmod +x #{release_path}/config/unicorn_init.sh"
Finally
:symlink_config
task's code is:You do not have replace any
run
intosudo
.For me it works fine.
Hi everyone,
First of all, many thanks Ryan for this amazing cast. I just wanted to know is there a way this can be applied in a scenario where I would like to use my VPN to host multiple rails applications?
For example if my domain is www.myrailsapps.com and I have three apps that I want to deploy on it which can be accessed at myrailsapps.com/app1, myrailsapps.com/app2, etc.
Anyone know if this can be accomplished with minor tweaks to this particular method?
Thanks again.
The screencast adn everyone's comments have really helped me through setting up the server. I feel a lot better about server setup, now.
Everything is working great - went through the whole screencast - the only difference for me is that I'm using mysql. Mysql is installed properly, and upon deploy, running the db migrations works and results in the tables being created in the database. So I know it's connected properly.
However, when I go to one of the URLs for that scaffolding (for me it was /users), I'm getting a "we're sorry, something went wrong" error.
The routes work perfectly locally. Not sure what the issues is because MySQL seems to be working and connected based on the migrations?
If anyone has any suggestions (or pointers to help debug these server errors), i would very much appreciate them.
I figured it out. in my nginx.conf file, I didn't change "blog" to "myapp" in the upstream command - but i had done so in the second place in that file that needed editing. Thanks again, Ryan!!
This is an absolutely ASTOUNDING tutorial/runthrough - one of the best I've ever come across on anything Rails-related. I will admit it took me around 2 days involving a couple of attempts and a bit of debugging to get everything working, but I got there in the end.
From memory, the main issues I had to deal with were as follows:
1) As Steve Fox mentions above, you will probably need to edit the /etc/nginx/sites-enabled/default file as per Steve's instructions in order to get nginx to work properly.
2) For some reason, when I tried to install PostgreSQL, version 8 was installed on my server, whereas version 9 appears to be installed in the video for Ryan's installation. I had to make sure I added this to the relevant command in the terminal. From memory (so you might want to check), it was:
apt-get install postgresql-9.2 libpq-dev
(Or whatever the current version is at the point you are reading this :-) ). See also this link.
3) An obvious one, but make sure that you install the same versions of Rails, PostgreSQL etc. on your server that you have on your local machine!
4) If your gems fail to install properly on the server, you may need to install the relevant development files:
See this StackOverflow question/response, and particularly the response with the most upvotes for further info.
HOWEVER, the most important piece of advice I can give based upon my experiences is as follows:
If you're intending to deploy your first ever app, do not build your complete app locally and then attempt to deploy it. There are probably minor differences in the different installations which are likely to cause your 500 page to appear, and which may end up being a nightmare to debug.
Instead, my advice would be to set up your server as soon as you write the first line of code for your app (even if it's just a "Hello World!") - and then deploy and debug as you go along. Believe me, this saves the frustration (particularly if you're a novice and not quite sure of what you're doing) of having a complete, working app on your local machine and one that refuses to work on a server. If you carry out a staged deployment, any issues should be identifiable and therefore rectifiable fairly quickly, rather than trying to debug a complete app at the end of the process. If you're worried about having an unfinished app publically available, I suppose you could set a username/password using the nginx equivalent of Apache's htpassword (do a Google search) to the root directory so that visitors to your site won't be able to access it.
Hope this helps others - and thanks again, Ryan!
Thank you Graeme, it was very helpful
Hi Ryan,
I followed this railscast and it helped me a lot in setting up a server recently however there is one weird issue I am encountering right now.
Whenever I enter my domain like www.example.com it gets redirected to the IP of the linode box having the rails application like xx.xxx.xx.xx. I have no idea why I am having this issue.I know it has something to do with Nginx configuration. Can you guide me what to modify to get this working ?
I've been struggling for a while now getting multiple apps online on one server so I hope someone can help me...
I've followed this tutorial to the letter apart from a few version changes (Ubuntu Server 12.04, rbenv 1.9.3p194).
Everything works fine with one website but as soon as I add another website things start to go wrong. At first nginx doesn't start and gives an error that I need to encrease my server_names_hash_bucket_size: to 64 which it's kinda weird because my domainnames for both sites aren't that long.
After changing that nginx starts again and the first site works but the second one gives an error. What's also weird is that my first sites stays the default site accessible by the ip of the server and all the domains pointing to it even though I have listen 80 default deferred; commented out.
I use this nginx.conf for both site with only the server_name different ofcourse:
Did you manage to get this figured out?
I was having trouble with the add-apt-repository command on Ubuntu 12.10 - Command not Found, even after doing sudo apt-get install python-software-properties
This was the error:
sudo: apt-add-repository: command not found
This was the solution:
sudo apt-get install software-properties-common
After that it started working finally.
+1. Thanks.
+1. Thanks.
+1. Thanks!
+1. Thanks.
Ignore my post 2 posts up. Turned my config was working fine.. Didn't realize they weren't being updated with normal cap deploys so my server still had the old ones in etc/nginx/sites-enabled...
To add to my original comment above, and to reiterate what a couple of other posters have suggested, I would love a follow-up tutorial to this showing how to deploy a new (separate) Rails app on the same server.
The reason I ask is that, given that I am a lone developer (and, probably like most folks here, my apps are generally quite small), my app only takes up around 5-10% of the allocated Linode so, when it comes round to deploying a second app (which will probably be just as tiny), it would appear to be more sensible to deploy it within the spare space rather than purchase an extra Linode.
There appear to be a few solutions above, but they are a bit daunting for a noob (particularly when one's current app just "works" and you're wary of breaking anything!), so a short screencast would be just dandy.
On a related note - Linode offer a backup service for around $5 a month (for the basic server option), so I'd recommend getting this if you're a noob like me. I think nightly backups are taken.
I'd like to see that tutorial too.
+1. I also need something like this. Have any of you figured this out?
Have sometimes problem with "Cannot allocate memory" when mail sending or image uploading... but I have 1 Gb ram for not high loaded app :(
Thanks a lot Ryan for this and the other Railscasts that you have done on deployment.
On Capistrano's from-the-beginning wiki, there is a section on avoiding
deploy:cold
which saysRyan, would you suggest to avoid
deploy:cold
?cap deploy:cold seems to break on executing deploy:start - followed every step along the way. Puzzled on this one. Anybody else have this issue?
For those of you having troubles when using routes containing subdomains in combination with Nginx (v1.2.5), you have to modify Ryan's Nginx configuration file like so:
Change this:
To this:
Restart, and you should be good to go!
The
$http_host
variable seems to only return the request subdomain.I try to add admin user on Ubuntu 12.04 LTS:
Does anyone know how to fix that?
I found the solution. Do this:
Also in Ubuntu 12 you should generate keys:
$ ssh-keygen -t rsa -C "your@mail.com"
First, create the user with:
sudo adduser
You can read more about this command in the man pages of your system with man adduser.
You can then add a user to the sudo group with with the command:
sudo adduser sudo
Note that versions of Ubuntu until 11.10 will use admin as group instead of sudo:
Until Ubuntu 11.10, the Unix group for administrators with root privileges through sudo had been admin. Starting with Ubuntu 12.04 LTS, it is now sudo, for compatibility with Debian and sudo itself. However, for backwards compatibility, admin group members are still recognized as administrators.
So let's start by saying Thanks, Ryan, great cast, really helpful and all that jazz.. (I mean it though)
Just one difference I'd like to share that I encountered on a fresh Ubuntu 12.04 VPS installation following the instructions of this screencast. After installing postgres, and adding a project specific user with password, I also had to modify the pg_hba.conf (/etc/postgresql/9.1/main/pg_hba.conf) file to enable the md5 authentication method, so that rails is able to connect to it with user and password specified in database.yml. Details are easily googleable, just wanted to point it out..
Hi Ryan et al.
Here's hoping someone can help. After setting up my linode acct & deploying, a couple links did not work (production only). So I made a few changes, thinking it was a cancan incompatibility with to_params, and now none of the link_to's work. In the production log it looks like it's trying to serve up a request to another host:
Started POST "/slingads/index.php" for 203.142.100.15 at 2013-02-08 16:50:22 -05
00
Error…500 error.
ActionController::RoutingError (No route matches [POST] "/slingads/index.php"):
actionpack (3.2.11)
Do I have a security breach & how should I handle this? Would it be best to just dump the database and start over? Any advice is much appreciated.
Thanks,
Cathy
PS) That ip address is for a company in HongKong!
Im struggling to get this solution to start with the environment set as staging.
I have tried updating the unicorn init file to pass the -E argument:
CMD="cd <%= current_path %>; bundle exec unicorn -D -c <%= unicorn_config %> -E <%= stage %>"
But Rails.env always says production.
Any ideas?
Hi Ryan!
It will be great if you can make a screencast showing us how to deploy an app on 2 servers, one for the Rails app itself and the other one for the database( Postgres). This is probably the first step I might do when I want to scale an app, but still, I can't find materials about how to do it right.
Thank you!
Hi can you help me
I'm trying to open rails console and getting this
deployer@microv:~$ rails console
-bash: rails: command not found
Are you sure you have the rails gem installed? Or ruby?
If it can't find the rails command then one of those is probably missing I would think.
I think you'd want to try rbenv or rvm to install some rubies, and then do:
hey can anyone please help me with the following problem:
I also get the bundle install error:
failed: "sh -c 'cd /home/deployer/apps/burden_farming/releases/20120322200251 && bundle install --gemfile
But it does not tell much, how to debug? How can I find out which gem dependency is causing the error?
Does Capistrano not create an error log?
I'm finding Capistrano a little daunting, and am trying to set up NGINX and Unicorn on my VPS.
Unicorn_rails works like a charm right now when called from the app_root, but then I'm stuck with my terminal open.
Can't get the unicorn command to work, let alone start it up on VPS reboot. I get:
Also, I keep hearing that unicorn is supposed to create a /tmp/unicorn.pid file, but I can only ever find /tmp/server.pid is that the right one?
Can Anyone help on that?
Hey all very green here, first time using Linode
(early on in the tutorial)
When running:
root@li511-230:~# service nginx start
I get:
Any suggestions would be greatly appreciated. Thanks.
It means you have another web server in your vps, close it.
How do you close it?
Yes I have done enough poking around on forums to understand that I have something running, its just that its a fresh rebuild... I didn't think anything would be running because of that.
That being said... How do I close this running thing?
Thanks,
Sam.
I don't know if this is your case, but that happened to me and i didn't have nothing on port 80... it was solved by commenting the listen [::]:80 default_server line on /etc/nginx/sites-enabled/default... hope it helps
thank you! your tip helped me :)
I just wanted to say thanks. Your tip just saved me after almost an hour of looking for a solution. I would guess that line has something to do with IPv6 address support.
thanks!
Thanks!
Hey everyone I figured out another solution. by adding:
listen [::]:80 ipv6only=on default_server;
after the
listing [::]:80
this answer was located here on stackoverflow here:
http://stackoverflow.com/questions/14972792/nginx-nginx-emerg-bind-to-80-failed-98-address-already-in-use
Thanks #Nathan
On line 22 (I think) you will see a line that says
listen [::]:80 default_server;
- comment that one out. then:wq [enter]
to save and close.Then try again:
sudo service nginx start
. Or just don't worry about it, as the file will be deleted later in the tutorial.I was able to figure out my issue from 'vi /var/log/nginx/error.log'
(using ubuntu 12.10)
vim ~/.bashrc # add rbenv to the top vim: command not found
So I used
This was also useful for ubuntu 12
http://blog.sudobits.com/2013/01/07/how-to-deploy-rails-application-to-vps/
I have a question on redeployment. Say if I have updated my application? Must I redeploy the entire application or can I use a pull request?
Does "cap deploy" flush the db every time I redeploy?
No, cap deploy doesn't flush the db when you redeploy.
Suggest setting up a $5 per month instance on www.digitalocean.com and creating a test application so you can experiment.
I just noticed they have "1-Click Install Ruby on Rails on Ubuntu 12.10"
https://www.digitalocean.com/community/articles/how-to-1-click-install-ruby-on-rails-on-ubuntu-12-10-with-digitalocean
Bitbucket hosts free private mercurial (hg) and git repositories and the capfile can just be changed to bitbuckets ssh link and it works like a charm. =)
As of time of posting, 7th April 2012 ,tutorial still works fantastically on Ubuntu 12.10.
A few updates:
Delete the line in /etc/nginx/sites-enabled/default if you get the error bind() to [::]:80 failed (98: Address already in use)
listen [::]:80 default_server
If using 12.10 or 12.04 use
rbenv bootstrap-ubuntu-12-04
Postgres can still be installed using the method noted in the tutorial, but it's being depreciated in lieu of:
https://wiki.postgresql.org/wiki/Apt
Thanks, i have similar problem, now problem got fixed.
Thank you for this screencast, Ryan!
Hello
When i try to deploy VPS after running service nginx start command i got following error:
What should i do to fix this problem?
Thanks @jeremydt by your solution my problem got fixed
I am trying to deploy my rails app to Linode VPS but after i finished all steps when i did
i got following error:
full log is below:
I tried all the ways and update following in deploy.rb
require "bundler/capistrano"
but problem still unresolved,Anyone can help me?
Problem got fixed using add this line in top of ~/.bashrc on remote server.
Assuming that i am using rvm in my remote as well as in my local computer.
Thanks Ryan
For Ubuntu 12.04 LTS and later, create the
deployer
user in thesudo
group instead of theadmin
group (thesudo
group has replaced theadmin group
, source).Thanks Florent. Exactly what I was looking for. :)
Just learning about Capistrano. Awesome tutorial!
Can you please explain what exactly is this line for?
sudo "ln -nfs #{current_path}/config/apache.conf /etc/apache2/sites-available/#{application}"
I can tell that the apache.conf included with the code in config directory is being symlinked in sites-available. But why is this necessary? I have already setup my apache by adding the exact same virtual host in my 'sites-enabled' directory and it works. So why copy it in sites-available, especially if apache doesn't read the config form that directory?
failed: "sh -c '/etc/init.d/unicorn_Blog_new start'" whats the work around I have tried to fix the symlink , replaced it but .. its broken everytime .. need help...
Done was not creating it properly!
I'm running a VPS on Ubuntu 12.04, the deployment works fine but i need to restart of the server to update the code !
Why ?
I've been waiting for this: 1-Click Install Ruby on Rails on Ubuntu 12.10
https://www.digitalocean.com/community/articles/how-to-1-click-install-ruby-on-rails-on-ubuntu-12-10-with-digitalocean
Has anyone checked it out?
I did try that but it didn't work and I found it difficult to figure out what was going wrong.. killed the droplet and started from scratch with an empty ubuntu image.
I am getting this when I do cap deploy:setup or bundle exec cap deploy:setup
I am not quite familiar with the scripts used on the railscast, mainly copy and paste/augment path (insert username/projectname) on the root path. I suspect that I configured the scripts incorrectly?
bundle exec cap deploy:setup
triggering load callbacks
* 2013-09-06 01:21:56 executing `deploy:setup'
* executing "mkdir -p /home/deployer2/apps/lintong /home/deployer2/apps/lintong/releases /home/deployer2/apps/lintong/shared /home/deployer2/apps/lintong/shared/system /home/deployer2/apps/lintong/shared/log /home/deployer2/apps/lintong/shared/pids"
servers: ["192.241.241.204"]
[192.241.241.204] executing command
** [out :: 192.241.241.204] bash: /home/deployer2/.rvm/bin/rvm-shell: No such file or directory
command finished in 9ms
failed: "rvm_path=$HOME/.rvm $HOME/.rvm/bin/rvm-shell 'default' -c 'mkdir -p /home/deployer2/apps/lintong /home/deployer2/apps/lintong/releases /home/deployer2/apps/lintong/shared /home/deployer2/apps/lintong/shared/system /home/deployer2/apps/lintong/shared/log /home/deployer2/apps/lintong/shared/pids'" on 192.241.241.204
I deployed my rails app yesterday on digital ocean.
Here is a pretty good tutorial
https://coderwall.com/p/yz8cha
and I put in a comment at the bottom because the deploy.rb needs to configure rvm capistrano properly.
I hope this may help someone down the line.
I have a VPS on digital ocean and I've been meaning to deploy a rails app to it. I have never done any server configuration before. Where can I read up on it?
Capistrano has just been updated to 3.0! Any advice?
Just wanted to let everyone know that this railscast is still proving to be successful on Ubuntu 13.04 server.
Remember, if you are going through any of Ryan's amazing Railscasts or any tutorial for that matter, make sure you clear your browser cache frequently!!!!(or turn it off)
I had everything working perfectly after a few fixes (unbeknownst to me) but I continued to see errors in my browser. I then stupidly searched for solutions to the problems (...that I had already fixed) for about 30 minutes, finally deciding to launch Chrome, which I mainly use for UI consistency...and, you guessed it, everything was working as it should. I shouldn't be making these rookie mistakes this late in the game.
Ryan you are amazing and I don't say that to many people. Quality, quality work as usual!
If anyone is trying to deploy to a server running Ubuntu 13.04, I will try my best to help you!
Mike, did you get this to work with Capistrano 3.0 or did you use 2.15? If so, would you mind pasting the code? I'm also using Ubuntu 13.04 on a DigitalOcean VPS. I'm getting this error after cap deploy:setup. I tried downgrading to Capistrano 2.15.5 and continued to get the same error.
connection failed for: 123.456.789.000 (Net::SSH::AuthenticationFailed: Authentication failed for user ...)
I just got the same error, on Capistrano 2.15. Looking back through my shell history, during the automatic ssh login I fat-fingered the command and so that wasn't working correctly either.
If this is the case for you, just redo that automatic login step and then retry
cap deploy:setup
once you have it working.I think there should be a revision that uses Capistrano 3 instead, as all the commands and config files have been updated
+1
+1
+1
+1
+1
If you need VPS just for stage you can use https://teatro.io/ instead.
Great Tutorial.
I can't get it to work. Been trying for four days now... I'm so close with this tutorial, but I can't get it finished.
I try cap deploy:cold and get
failed: "sh -c 'cd /home/deployer/apps/arcane/releases/20141113053658 && bundle install --gemfile /home/deployer/apps/arcane/releases/20141113053658/Gemfile --path /home/deployer/apps/arcane/shared/bundle --deployment --quiet --without development test'" on 173.230.151.17
I'm using Capistrano 2.15, but I don't even know where the problem lies because theres so many different things... Any ideas?
If anyone is interested in a more up-to-date video tutorial, I created one at http://www.rubytreesoftware.com/courses/deploy-ruby-on-rails-tutorial.
Creston, thanks, this is always the pain with development, outdated videos.
I found that this :Rake::Task[:production].invoke: needed to be added to the end of the Cap File
the video doesn't work anymore as of 2016/05. Please fix this