Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
kayakyakr
Feb 16, 2004

Kayak is true

Nybble posted:

I would recommend this highly. DigitalOcean is phenomenal.

(Heck, you could just put your app there, too.)

I do enjoy a full stack server for $5, 2 cores for $20.

Adbot
ADBOT LOVES YOU

prom candy
Dec 16, 2005

Only I may dance
I would just put your app on Digital Ocean.

Mystery Machine
Oct 12, 2008
I've recently gotten into Rails, and I wanna put an app up on JustHost. I tried for a while, but completely fell flat. Does anyone have a step by step guide on how to set up a Rails app on that service? Or another hosting service? I tried a bunch of things, but had an incredibly off putting time. I'm assuming I'm the one who royally hosed up, but really weird things were going on. Like, I accessed the command line for the hosting, and I couldn't do things as a super user. I couldn't apt-get anything, just a bunch of weirdness.

In short, I'm excited to build a site for a friend using Rails, and while I can use Rails just fine locally on my computer, I'm completely at a loss on how to do it on my friend's hosting. Can anyone point me in the right direction?

prom candy
Dec 16, 2005

Only I may dance
Getting rails set up on shared hosting can be a real pain. Your best bet is almost always to get hosting from a service where you get root access to a dedicated or virtual server. Digital Ocean is popular with this thread and I think they even have an image that has rails pre-set up for you.

Mystery Machine
Oct 12, 2008

prom candy posted:

Getting rails set up on shared hosting can be a real pain. Your best bet is almost always to get hosting from a service where you get root access to a dedicated or virtual server. Digital Ocean is popular with this thread and I think they even have an image that has rails pre-set up for you.

Ah, so my experience isn't abnormal? Well, I feel better about myself. Okay, I'll look into it, thanks.

vv Yeah, I knew the hosting was awful. I'm doing this thing both as a fun project for me and as a small favor for my friend, so I didn't want to shake up her hosting situation. I'll try to see if I can convince my friend to switch to one of those.

Mystery Machine fucked around with this message at 09:00 on Dec 14, 2013

kayakyakr
Feb 16, 2004

Kayak is true

Mystery Machine posted:

I've recently gotten into Rails, and I wanna put an app up on JustHost. I tried for a while, but completely fell flat. Does anyone have a step by step guide on how to set up a Rails app on that service? Or another hosting service? I tried a bunch of things, but had an incredibly off putting time. I'm assuming I'm the one who royally hosed up, but really weird things were going on. Like, I accessed the command line for the hosting, and I couldn't do things as a super user. I couldn't apt-get anything, just a bunch of weirdness.

In short, I'm excited to build a site for a friend using Rails, and while I can use Rails just fine locally on my computer, I'm completely at a loss on how to do it on my friend's hosting. Can anyone point me in the right direction?

Don't do it on your friend's hosting. His hosting is awful. It's seriously not even worth the pain of trying.

I would suggest going here first because free server, super easy:
https://www.heroku.com/

That will work for you, but if you insist on being different, I'd suggest going here:
https://www.openshift.com/

If you really want to futz with servers, then yes, launch a $5 server on https://www.digitalocean.com

But really, for your level, Heroku will get you up and running fastest.

prom candy
Dec 16, 2005

Only I may dance
The problem with Heroku is that the minimum monthly cost to get rid of the really long application spin-up time is like $36. The free tier is fine for testing stuff out but if your app is low traffic a person's initial request can take like 10s which the app spins up.

The Journey Fraternity
Nov 25, 2003



I found this on the ground!

prom candy posted:

The problem with Heroku is that the minimum monthly cost to get rid of the really long application spin-up time is like $36. The free tier is fine for testing stuff out but if your app is low traffic a person's initial request can take like 10s which the app spins up.

You can get around that by adding the free tier of New Relic. It can be configured to use a heartbeat URL to determine if the server is still up. Since it pings the server more frequently than the dyno sleep time, it'll never sleep.

kayakyakr
Feb 16, 2004

Kayak is true

The Journey Fraternity posted:

You can get around that by adding the free tier of New Relic. It can be configured to use a heartbeat URL to determine if the server is still up. Since it pings the server more frequently than the dyno sleep time, it'll never sleep.

This is pretty brilliant.

waffle enthusiast
Nov 16, 2007



Does your app have to be up all the time? This is a little complicated, but you can leverage EBS + EC2 spot instances + Autoscaling group + Elastic IP to basically use AWS at about 1/10th the on-demand price. You could probably run on an m1.medium (3.7GB ram, 2 ECUs) for like $15-$20 per month.

Also check out lowendbox.com - you can get a decent VPC for $5-$10. Though there's no guarantee your provider won't get raided by the IRS (like the one I was using apparently did).

Oh My Science
Dec 29, 2008

The Journey Fraternity posted:

You can get around that by adding the free tier of New Relic. It can be configured to use a heartbeat URL to determine if the server is still up. Since it pings the server more frequently than the dyno sleep time, it'll never sleep.

In addition you can use HireFire to scale your dynos automatically for increased traffic (assuming you even need this). It allows you to set limits as well so your maximum cost is always predictable.

prom candy
Dec 16, 2005

Only I may dance

The Journey Fraternity posted:

You can get around that by adding the free tier of New Relic. It can be configured to use a heartbeat URL to determine if the server is still up. Since it pings the server more frequently than the dyno sleep time, it'll never sleep.

That's not really sustainable though, I think Heroku's free tier only works if people aren't artificially keeping their apps alive.

kayakyakr
Feb 16, 2004

Kayak is true

prom candy posted:

That's not really sustainable though, I think Heroku's free tier only works if people aren't artificially keeping their apps alive.

And all of this is why, outside of a hobby app (where it's ok that it takes 10s to launch), you should look into alternatives like digital ocean and openshift (not sure about openshift's capabilities, had just started looking at it).


In other news, I've been playing with the new capistrano, version 3, today. They changed a lot of the way it works, but now that I'm getting the hang of how it WANTS to do things, I'm finding that it's really, really powerful. Like it very much.

The Journey Fraternity
Nov 25, 2003



I found this on the ground!

prom candy posted:

That's not really sustainable though, I think Heroku's free tier only works if people aren't artificially keeping their apps alive.

They offer you a hair over 31 full days worth (750) of dyno hours for free. If they didn't want you using it they wouldn't offer it.

Obsurveyor
Jan 10, 2003

The Journey Fraternity posted:

They offer you a hair over 31 full days worth (750) of dyno hours for free. If they didn't want you using it they wouldn't offer it.

That's not how businesses able to offer a free tier work. You will see the free tier quickly be replaced or the hours reduced if every free account starts using every single dyno hour of a month.

kayakyakr
Feb 16, 2004

Kayak is true

Obsurveyor posted:

That's not how businesses able to offer a free tier work. You will see the free tier quickly be replaced or the hours reduced if every free account starts using every single dyno hour of a month.

Dunno, Heroku is about as mature as a company that sprang up from rails gets. If they were going to remove their free tier, you'd think they'd have done it by now. They make conversions because the single dyno is rarely ever enough for a mature app (and as mentioned before, they put inactive dynos to sleep). If someone uses their full free tier monthly then so be it.

The Journey Fraternity
Nov 25, 2003



I found this on the ground!

Obsurveyor posted:

That's not how businesses able to offer a free tier work. You will see the free tier quickly be replaced or the hours reduced if every free account starts using every single dyno hour of a month.

Every single application that uses multiple dynos gets one of those for free all month. I've done this for multiple work projects that I want to stand up easily but do not require more than one process, like Hubot. I have yet to hear a peep. Salesforce has more than enough throwaway cash to earn that small bit of goodwill for one of the few products of theirs that people like.

*edit* And this is the Ruby thread, not a Heroku one, so I'm going to stop this derail.

The Journey Fraternity fucked around with this message at 18:32 on Dec 15, 2013

A Big... Dog
Mar 25, 2013

HELLO DAD

The Journey Fraternity posted:

*edit* And this is the Ruby thread, not a Heroku one, so I'm going to stop this derail.

This is a Rails thread. Surely Heroku is synonymous enough with Rails that discussion of it is worthy of a place in this thread?

KoRMaK
Jul 31, 2012



a_big_dog posted:

This is a Rails thread. Surely Heroku is synonymous enough with Rails that discussion of it is worthy of a place in this thread?

I'd think any talk about getting a rails app working on the Internet is appropriate for this thread.

prom candy
Dec 16, 2005

Only I may dance

kayakyakr posted:

(and as mentioned before, they put inactive dynos to sleep)

Yeah and what we're discussing is tricking Heroku into thinking your dyno is active in order to not get it put to sleep. If everyone was to keep their free-tier dynos active at all times they wouldn't be able to offer the free-tier.

KoRMaK
Jul 31, 2012



prom candy posted:

Yeah and what we're discussing is tricking Heroku into thinking your dyno is active in order to not get it put to sleep. If everyone was to keep their free-tier dynos active at all times they wouldn't be able to offer the free-tier.
I agree, what was described by using new relic is essentially an exploit and would mess up their payment model.

kayakyakr
Feb 16, 2004

Kayak is true

prom candy posted:

Yeah and what we're discussing is tricking Heroku into thinking your dyno is active in order to not get it put to sleep. If everyone was to keep their free-tier dynos active at all times they wouldn't be able to offer the free-tier.

But everyone doesn't and so it's not an issue, no? It's a neat workaround for sites that get little enough traffic that they go into standby mode but are critical enough that a delay on the first load when someone does use it would be a significant issue.

There aren't many sites like that, really. Maybe an early, small startup that might get 10-15 organic visits/day and needs a high conversion? But still, that's not what you'd use Heroku for anyway.

Is it a big deal?

Sil
Jan 4, 2007
I don't see the New Relic trick being a trick at all. Heroku could just as easily restrict their free offering to half a dyno month or a quarter dyno month without affecting people's experimental apps, while requiring tiny production apps to pay.

The way I see it, they have New Relic as a small additional thing you need to figure out and do so that every account's forgotten blog app experiment with 2 git commits doesn't stay active for all eternity. I don't think anyone outside Heroku has a clue if using New Relic to keep a free dyno alive will affect their bottom line too much. If it's a problem, they're a business and they'll let us know.

raej
Sep 25, 2003

"Being drunk is the worst feeling of all. Except for all those other feelings."

prom candy posted:

Getting rails set up on shared hosting can be a real pain. Your best bet is almost always to get hosting from a service where you get root access to a dedicated or virtual server. Digital Ocean is popular with this thread and I think they even have an image that has rails pre-set up for you.

Time to search for this! The only thing scaring me from DO is getting everything setup.

Smol
Jun 1, 2011

Stat rosa pristina nomine, nomina nuda tenemus.
If you guys have trouble setting servers up, just get your hands dirty and start doing it anyway. It's a valuable skill and you won't be deploying every project for the rest of your life to Heroku.

raej
Sep 25, 2003

"Being drunk is the worst feeling of all. Except for all those other feelings."
Is there a good way to practice before buying in? Just set up an old box and install debian?

Or just do something like this? https://www.digitalocean.com/community/articles/how-to-use-the-digitalocean-dokku-application

EAT THE EGGS RICOLA
May 29, 2008

raej posted:

Is there a good way to practice before buying in? Just set up an old box and install debian?

It's five dollars, but if you want to try first, the pre-built image is a Ubuntu 12.10 image with rails, unicorn and nginx, just spin up a vm with virtualbox.

kayakyakr
Feb 16, 2004

Kayak is true

raej posted:

Is there a good way to practice before buying in? Just set up an old box and install debian?

Or just do something like this? https://www.digitalocean.com/community/articles/how-to-use-the-digitalocean-dokku-application

Or you can use Amazon's free tier to get a year's worth of an EC2 micro server. Use an ubuntu image and roll with it.

When I build my servers, I have a few steps along the way:

1: Set up the user
Digital Ocean's bare Ubuntu distros (I like to use 12.04x64 for "production" servers, which I'll upgrade to 14.04 next year, will play with other versions) come set up with just a root user out of the box. I like the way that the EC2 server looks when set up, so I emulate that.

Logged in as root:
code:
useradd -m -s /bin/bash ubuntu -G sudo
mkdir /home/ubuntu/.ssh
cp ~/.ssh/authorized_keys /home/ubuntu/.ssh/authorized_keys
chown ubuntu:ubuntu /home/ubuntu/.ssh -R
visudo
Add "ubuntu ALL (ALL:ALL) NOPASSWD: ALL" to the sudoers file and save.

2: Prep for server

Exit, log in as ubuntu, and run:
code:
sudo bash -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main" >> /etc/apt/sources.list.d/pgdg.list'
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get install nginx postgresql-9.3 libpq-dev
sudo ufw allow ssh
sudo ufw allow http
sudo ufw enable
You should set up your postgres server now:
Bash code:
sudo su - postgres
psql
CREATE ROLE ubuntu WITH LOGIN;
CREATE DATABASE application_production WITH OWNER ubuntu;
\q
exit
3: Capify
I use capistrano for doing my deploys. Out of the box it does a whole lot of work for you.


This is my list of gems for capistrano:
Ruby code:
gem 'capistrano', :require => false
gem 'capistrano-rails', :require => false
gem 'rvm1-capistrano3', :require => false
gem 'capistrano3-unicorn', :require => false
I also use figaro for my environment variables.

These are the important changes I make to my deploy.rb script that took me a while to figure out (the remote file thing that is):
code:
set :deploy_to, "/home/ubuntu/#{fetch(:application)}"

set :linked_files, %w{config/application.yml}
set :linked_dirs, %w{log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}

set :keep_releases, 5

set :rvm1_ruby_version, '2.0.0-p353'

set :unicorn_pid, -> { File.join(shared_path, "tmp", "pids", "unicorn.pid") }

namespace :deploy do  
  desc 'Restart application'
  task :restart do
    invoke 'unicorn:restart'
  end
  
  namespace :check do
    task :linked_files => shared_path.join('config/application.yml')
  end
end

remote_file shared_path.join('config/application.yml') => 'config/application.yml', roles: :app

file 'config/application.yml' do |t|
  on roles(:app) do |host|
    upload! t.name, shared_path.join(t.name)
  end
end
That's not the whole file, but it's enough of it, you should be able to figure out the rest. You also need to required all the gems you added in Capfile:
code:
require 'capistrano/bundler'
require 'capistrano/rails'
require 'rvm1/capistrano3'
require "whenever/capistrano"
require "capistrano3/unicorn"
Set your server in config/deploy/production.rb

4: Unicorn
You have to configure unicorn, I suggest like so:
code:
# Set your full path to application.
app_path = "/home/ubuntu/application/current"

# Set unicorn options
worker_processes 2
preload_app true
timeout 180

# Spawn unicorn master worker for user apps (group: apps)

# Fill path to your app
working_directory app_path

listen "#{app_path}/tmp/sockets/unicorn.sock", :backlog => 64

# Should be 'production' by default, otherwise use other env
rails_env = ENV['RAILS_ENV'] || 'production'

# Log everything to one file
stderr_path "log/unicorn.log"
stdout_path "log/unicorn.log"

# Set master PID location
pid "#{app_path}/tmp/pids/unicorn.pid"

before_fork do |server, worker|
  defined?(ActiveRecord::Base) and ActiveRecord::Base.connection.disconnect!

  # Before forking, kill the master process that belongs to the .oldbin PID.
  # This enables 0 downtime deploys.
  old_pid = "tmp/pids/unicorn.pid.oldbin"
  if File.exists?(old_pid) && server.pid != old_pid
    begin
      Process.kill("QUIT", File.read(old_pid).to_i)
    rescue Errno::ENOENT, Errno::ESRCH
      # someone else did our job for us
    end
  end
end

after_fork do |server, worker|
  defined?(ActiveRecord::Base) and ActiveRecord::Base.establish_connection
end
5: Deploy
Locally run "cap production deploy --trace" handle any issues that come up. I had a few.

6: Nginx
Back on the server, add something like this to /etc/nginx/sites-available/application:
code:
upstream application_rails{
  server unix:/home/ubuntu/application/current/tmp/sockets/unicorn.sock fail_timeout=0;
}

#server {
#  listen 80;
#  server_name _;
#  return 301 https://application.com$request_uri;
#}

server {
  listen 80;

#  ssl on;
#  ssl_certificate /etc/ssl/certs/application.com.combined.crt;
#  ssl_certificate_key /etc/ssl/certs/application.com.key;

  server_name _;

  root /home/ubuntu/application/current/public;
  index index.html;
  try_files $uri.html $uri @app;

  location ~ ^/assets/ {
    gzip_static on;
    expires max;
    add_header Cache-Control public;
  }  

  location @app {
    # If the file exists as a static file serve it directly
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto http;
    proxy_set_header Host $http_host;
    proxy_redirect off;

    # Oh yeah, hand over the request to Rails! Yay! :-D
    proxy_pass http://application_rails;
  }
}
And honestly there's probably something I'm doing poorly in there. That also includes, commented out, how you would use SSL.

Also on the server do:
code:
sudo ln -s /etc/nginx/sites-available/application /etc/nginx/sites-enabled/application
sudo rm /etc/nginx/sites-enabled/default
sudo service nginx restart
7: Done
Seriously, sit back and open a beer, you just became capable of doing devops using Digital Ocean. Hit your website and rejoice.

kayakyakr fucked around with this message at 21:59 on Dec 16, 2013

Chilled Milk
Jun 22, 2003

No one here is alone,
satellites in every home
The New Relic/Heroku "trick" is fairly widely known and has been for a good long while. If it truly was a problem they would have done something about it by now.

That said, Digital Ocean is a great alternative if you don't mind getting your hands slightly dirty setting things up. Once you have capistrano rolling it's just as turnkey.


Edit: And that's a good write up above this post

Smol
Jun 1, 2011

Stat rosa pristina nomine, nomina nuda tenemus.
After you manually set up servers a couple of times like that though, start using some kind of configuration management tool, like Puppet or Chef. Makes setting up new boxes from scratch truly a one click affair.

kayakyakr
Feb 16, 2004

Kayak is true

Smol posted:

After you manually set up servers a couple of times like that though, start using some kind of configuration management tool, like Puppet or Chef. Makes setting up new boxes from scratch truly a one click affair.

Yeah, if you find yourself doing that a lot, I would look into puppet or chef or maybe just write yourself a custom capistrano task that does it all for you.

But really, the part that Puppet/Chef handles takes me about 3 minutes to do after the server's been spun up, and outside of horizontal scaling how often do you have to perform an initial server configuration? Most of the first half of that post was done by memory (other than copy/pasting postgres's apt repo) and the rest was copy/pasted from my most recent project. It'd take years to have the time for a puppet/chef setup equal the time used typing into terminals.

kayakyakr
Feb 16, 2004

Kayak is true
yeah, yeah, double posting, but what would you guys think about starting a new thread? The OP is from over 6 years ago, everything in it is horribly out of date, the poster hasn't posted here since 2008, and with a 122 page thread, the same questions have tended toward being asked many times already.

I'm thinking: OP would have resources, links to tutorials, and suggestions for setting up an environment. Probably mention hosting. A 2nd post would be a copy of my Digital Ocean deploy tutorial above.

Thoughts? Anything that'd need to be in the first set of posts that you'd like to see such as suggested gems or whatnot?

Oh My Science
Dec 29, 2008
Yeah, I did the same thing with the web dev thread and it's a pretty solid OP now. I used google docs and let the frequent posters edit or create new content, which worked well as a collaborative approach.

Chilled Milk
Jun 22, 2003

No one here is alone,
satellites in every home

kayakyakr posted:

yeah, yeah, double posting, but what would you guys think about starting a new thread? The OP is from over 6 years ago, everything in it is horribly out of date, the poster hasn't posted here since 2008, and with a 122 page thread, the same questions have tended toward being asked many times already.

I'm thinking: OP would have resources, links to tutorials, and suggestions for setting up an environment. Probably mention hosting. A 2nd post would be a copy of my Digital Ocean deploy tutorial above.

Thoughts? Anything that'd need to be in the first set of posts that you'd like to see such as suggested gems or whatnot?

Go for it.

I could probably write up a quick guide/tips n tricks about Active Admin if there's any interest.

kayakyakr
Feb 16, 2004

Kayak is true

Oh My Science posted:

Yeah, I did the same thing with the web dev thread and it's a pretty solid OP now. I used google docs and let the frequent posters edit or create new content, which worked well as a collaborative approach.

Do you just have a copy of the OP off in some google drive doc and you copy/paste update it every once in a while?

I think that guides and the like can be linked to from the OP. So you'd create a guide, and then the link to it and description would go in the OP.

I'll get that started. Google Doc. Gonna use this as the basis. For now I'm going to go ahead and allow open access to editing, but maybe in the future lock it down to people that request editing access?

Oh My Science
Dec 29, 2008

kayakyakr posted:

Do you just have a copy of the OP off in some google drive doc and you copy/paste update it every once in a while?

I think that guides and the like can be linked to from the OP. So you'd create a guide, and then the link to it and description would go in the OP.

I'll get that started. Google Doc. Gonna use this as the basis. For now I'm going to go ahead and allow open access to editing, but maybe in the future lock it down to people that request editing access?

Yeah I do, although I think the sharing permissions have been nixed just in case. The real pain was writing the bbcode to make it look decent and finding out that anchor links are not supported by SA.

I had it completely open to editing for about a month. Assuming no one in the thread is a jackass it should be fine.

Edit:

Dare I suggest we make the thread about ruby frameworks and not just rails?

Oh My Science fucked around with this message at 00:01 on Dec 17, 2013

kayakyakr
Feb 16, 2004

Kayak is true

Oh My Science posted:

Dare I suggest we make the thread about ruby frameworks and not just rails?

Oh my. That would be out there. I think that would be good, though. Ruby + frameworks.

e: editing open now.

Oh My Science
Dec 29, 2008
FYI don't go too crazy the with the internal guides and instead point to external documentation or blogs. I would say 90% of the commonly used frameworks and deployment tools have decent documentation now anyway.

Obsurveyor
Jan 10, 2003

Smol posted:

After you manually set up servers a couple of times like that though, start using some kind of configuration management tool, like Puppet or Chef. Makes setting up new boxes from scratch truly a one click affair.

I prefer sprinkle. Puppet and Chef are horrible nightmares to setup imho because they're designed for huge enterprise deployment, requiring a server just for managing recipes and such.

Adbot
ADBOT LOVES YOU

kayakyakr
Feb 16, 2004

Kayak is true

Oh My Science posted:

FYI don't go too crazy the with the internal guides and instead point to external documentation or blogs. I would say 90% of the commonly used frameworks and deployment tools have decent documentation now anyway.

Right. But things like the above deployment guide would be good, I would think, because it could stand on its own as a blog post. If I had the time/inspiration to maintain a blog, that post would have been there and linked to here.

But I'd rather spend my time with you guys, so it's an exclusive. Screw the Internet at large.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply