Showing posts with label vps. Show all posts
Showing posts with label vps. Show all posts

Saturday, August 15, 2009

Moving Past Beta

‹prev | My Chain | next›

I got the beta site up and running yesterday. Since then, it has worked just fine, thank you very much. It is still running right now. Why am I a bit defensive? Well, because I started it in non-daemon mode. It is still running in one of my GNU screen windows.

That's fine for development mode, borderline OK for a limited beta, but is completely unacceptable for a production system. A good start would be to start the server as a daemon:
$ thin -d -R config.ru start
That might be OK for one time, but I would have to remember to do that each time I restart the system—not so OK.

The answer to that is, of course, an init.d script. Happily, I do not have to roll my own with thin:
sh-3.2$ sudo /var/lib/gems/1.8/bin/thin install
>> Installing thin service at /etc/init.d/thin ...
mkdir -p /etc/init.d
writing /etc/init.d/thin
chmod +x /etc/init.d/thin
mkdir -p /etc/thin

To configure thin to start at system boot:
on RedHat like systems:
sudo /sbin/chkconfig --level 345 thin on
on Debian-like systems (Ubuntu):
sudo /usr/sbin/update-rc.d -f thin defaults
on Gentoo:
sudo rc-update add thin default

Then put your config files in /etc/thin
Hmmm... Not only am I running on a Debian-like system, I am running on Debian itself, so:
sh-3.2$ sudo /usr/sbin/update-rc.d -f thin defaults
Adding system startup for /etc/init.d/thin ...
/etc/rc0.d/K20thin -> ../init.d/thin
/etc/rc1.d/K20thin -> ../init.d/thin
/etc/rc6.d/K20thin -> ../init.d/thin
/etc/rc2.d/S20thin -> ../init.d/thin
/etc/rc3.d/S20thin -> ../init.d/thin
/etc/rc4.d/S20thin -> ../init.d/thin
/etc/rc5.d/S20thin -> ../init.d/thin
I will run the application out of /var/www rather than my home directory:
sh-3.2$ sudo mkdir /var/www
sh-3.2$ cd /var/www
sh-3.2$ sudo chown www-data:www-data .
sh-3.2$ cd /var/www/
sh-3.2$ sudo cp -r /home/cstrom/repos/eee-code .
sh-3.2$ sudo mkdir log
sh-3.2$ sudo chown -R www-data:www-data .
With the app in place, I can edit my /etc/thin/eee.yml file to contain:
--- 
user: www-data
group: www-data
pid: log/thin.pid
log: log/thin.log
timeout: 60
port: 4567
address: 127.0.0.1
chdir: /var/www/eee-code
environment: production
daemonize: true
rackup: config.ru
I did try running directly from port 80 at first, but found this in the log:
/var/lib/gems/1.8/gems/eventmachine-0.12.8/lib/eventmachine.rb:565:in `start_tcp_server': no acceptor (RuntimeError)
from /var/lib/gems/1.8/gems/eventmachine-0.12.8/lib/eventmachine.rb:565:in `start_server'
from /var/lib/gems/1.8/gems/thin-1.2.2/lib/thin/backends/tcp_server.rb:16:in `connect'
from /var/lib/gems/1.8/gems/thin-1.2.2/lib/thin/backends/base.rb:49:in `start'
...
Sooo....
sh-3.2$ sudo apt-get install nginx
To get nginx to reverse proxy to my thin server running on port 4567, I need a sites-enabled file along the lines of:
# vi /etc/nginx/sites-enabled/eeecooks.com 
upstream beta_eeecooks_com {
server 127.0.0.1:4567;
}

server {
listen 80;
server_name beta.eeecooks.com;
access_log /var/www/eee-code/log/logfile.log;

location / {
proxy_pass http://beta_eeecooks_com;
}

}
The upstream server is running on the localhost at port 4567. I nickname it as "beta_eeecooks_com". The server then proxy_passes everything to that server. Easy enough (after 10 minutes of wondering why it wasn't working only to discover I had created that configuration in the sites-available directory, not the sites-enabled directory!).

With that, I am assured that my server(s) will start whenever there is a reboot. I could use a way to check that it keeps running after start, but that will have to wait until tomorrow.

Before calling it a day, I note with some amount of sadness that someone tried to send email feedback today. The sadness is not because I do not desire feedback, quite the opposite. The sadness is due to the loss of the feedback. From my logs:
Errno::ECONNREFUSED - Connection refused - connect(2):
/usr/lib/ruby/1.8/net/smtp.rb:551:in `initialize'
/usr/lib/ruby/1.8/net/smtp.rb:551:in `open'
/usr/lib/ruby/1.8/net/smtp.rb:551:in `do_start'
/usr/lib/ruby/1.8/timeout.rb:62:in `timeout'
/usr/lib/ruby/1.8/timeout.rb:93:in `timeout'
/usr/lib/ruby/1.8/net/smtp.rb:551:in `do_start'
/usr/lib/ruby/1.8/net/smtp.rb:531:in `start'
eee.rb:188:in `POST /email'
eee.rb:178Errno::ECONNREFUSED: Connection refused - connect(2)
/usr/lib/ruby/1.8/net/smtp.rb:551:in `initialize'
/usr/lib/ruby/1.8/net/smtp.rb:551:in `open'
/usr/lib/ruby/1.8/net/smtp.rb:551:in `do_start'
/usr/lib/ruby/1.8/timeout.rb:62:in `timeout'
/usr/lib/ruby/1.8/timeout.rb:93:in `timeout'
/usr/lib/ruby/1.8/net/smtp.rb:551:in `do_start'
/usr/lib/ruby/1.8/net/smtp.rb:531:in `start'
/var/lib/gems/1.8/gems/pony-0.3/lib/pony.rb:67:in `transport_via_smtp'
/var/lib/gems/1.8/gems/pony-0.3/lib/pony.rb:42:in `transport'
/var/lib/gems/1.8/gems/pony-0.3/lib/pony.rb:15:in `mail'
eee.rb:188:in `POST /email'
...
Dang! No email server. It is late and I do not want the hassle of setting up a full-blown mail server, so I:
sudo apt-get install ssmtp
That installs a simple sendmail replacement. After setting the mailhub option in /etc/ssmtp/ssmtp.conf, I can now receive emails from the site and actually send them onto myself:
127.0.0.1 - - [16/Aug/2009 02:47:00] "POST /email HTTP/1.0" 200 1076 6.1352
127.0.0.1 - - [16/Aug/2009 02:47:00] "GET /stylesheets/style.css HTTP/1.0" 304 - 0.0010
127.0.0.1 - - [16/Aug/2009 02:47:00] "GET /images/eee_corner.png HTTP/1.0" 304 - 0.0009
Apologies to anyone that tried to provide feedback today. Resending will work now!

Thursday, August 13, 2009

Getting Started with Linode

‹prev | My Chain | next›

Today I start deploying to a VPS. I opt for Linode for this—it has the right features for the money.

Creating the node is trivial with Linode. I will not bother with screenshots and a description—it is both intuitive and well documented. Once I have my Debian node up and running (<5 minutes, if that), I log in an create myself a user account and set the password:
li97-191:~# useradd -U -m cstrom
li97-191:/home/cstrom# passwd cstrom
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
I apt-get install sudo, visudo to enable myself to have sudo access, and vigr to put my user account into the proper group for that access. I logout and log back in as that user account.

As described yesterday, I need to use Debian testing (to get the right version of CouchDB), so I add testing repositories :
#...
deb http://http.us.debian.org/debian testing main contrib non-free
deb http://non-us.debian.org/debian-non-US testing/non-US main contrib non-free
deb http://security.debian.org testing/updates main contrib non-free
I then need to install these packages:
apt-get install sudo openssh-server \
couchdb \
ruby ruby-dev rubygems rake irb make curl git-core \
libopenssl-ruby \
libidn11 \
maven2 openjdk-6-jdk
That works, but I see all sorts of messages like this:
perl: warning: Please check that your locale settings:
LANGUAGE = (unset),
LC_ALL = (unset),
LANG = "en_US.UTF-8"
are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
Odd, it seems that locales is not installed. I install it via sudo apt-get install locales and then select en_US.UTF-8 as the default locale in sudo dpkg-reconfigure locales.

Next up, I install the couch_docs gem:
cstrom@li97-191:~$ sudo gem sources -a http://gems.github.com
http://gems.github.com added to sources
cstrom@li97-191:~$ sudo gem install eee-c-couch_docs
Building native extensions. This could take a while...
Successfully installed json-1.1.7
Successfully installed rest-client-1.0.3
Successfully installed eee-c-couch_docs-1.0.0
3 gems installed
Installing ri documentation for json-1.1.7...
Installing ri documentation for rest-client-1.0.3...
Installing ri documentation for eee-c-couch_docs-1.0.0...
Installing RDoc documentation for json-1.1.7...
Installing RDoc documentation for rest-client-1.0.3...
Installing RDoc documentation for eee-c-couch_docs-1.0.0...
After uploading my CouchDB seed data, I use curl to create my CouchDB database and couch_docs to upload the seed data:
cstrom@li97-191:~/seed$ curl -X PUT http://localhost:5984/eee
{"ok":true}
cstrom@li97-191:~/seed$ /var/lib/gems/1.8/bin/couch-docs load . http://localhost:5984/eee
To verify, I use ssh port forwarding:
cstrom@jaynestown:~$ ssh -L 15984:localhost:5984 97.107.136.191
Connecting to the forwarded port, I see:



Nice! I will get my application server up and running tomorrow.

Friday, March 20, 2009

VPS Notes

‹prev | My Chain | next›

I think I have all of my exploratory code / prototyping done at this point.

Rather than jump directly in real code tonight, I will gather some VPS hosting data for the ultimate deployment.

I am currently running EEE Cooks on a shared hosting site with Hosting Rails. I have had absolutely no problems with them and their service, but they are not going to allow me to run a CouchDB instance in their shared environment.

Hosting Rails does offer a VPS solution, so I will certainly consider them here. Along with them, I will also look at Slicehost and Linode.

Hosting Rails VM256Linode 360Slicehost 256 slice
Cost$17.92$19.95$20
Memory256360256
Disk Space (GB)201210
Bandwidth200200100


Aside from those variables, the three options are pretty much the same. All offer Debian & Ubuntu (the only distributions that I would manage). All offer root access. All offer a dedicated IP address.

So all I have to do is decide which of these variables (if any) really matters and maybe add one or two intangibles to the list.