Todays topic to is tuneup a bit more server what was setup earlier.

Goal is to,

  • Improve logic for redeploy, thus to avoid breaking running server when doing new deploy
  • Remove dependency into private user account, but use instead account specific to this deploy only
  • To use server instance specific ruby version instead of globally installed OS default ruby version

1) Make my dreams true, aka. use separate release directory via symlink

Cleanup server directory structure
[code]
cd /home/www/virtual/host.kari.dy.fi
mkdir release_20150330
mv * release_20150330
mv .* release_20150330
ln -s release_20150330 current
[/code]

/etc/apache/vhosts.d/host.kari.dy.fi.conf
Update config
[code]

ServerName host.kari.dy.fi
# !!! Be sure to point DocumentRoot to ’public’!
DocumentRoot /home/www/virtual/host.kari.dy.fi/current/public

# if not specified, the global error log is used
ErrorLog /var/log/apache2/host.kari.dy.fi-error_log
CustomLog /var/log/apache2/host.kari.dy.fi-access_log combined

# to allow symbolic link for server release

Options FollowSymLinks


# This relaxes Apache security settings.
AllowOverride all
# MultiViews must be turned off.
Options -MultiViews
# Uncomment this if you’re on Apache >= 2.4:
Require all granted


[/code]

2) Get of my lawn, aka. use different user

[code]
adduser rails
/home/www/virtual
chown -R rails host.kari.dy.fi
[/code]

okey, server is going to broken at this point, and will be fixed into running stage in step (3). Meanwhile, need to setup ssh keys (Generating SSH keys) for ”rails” user to allow ”bundle install” to succeed later on

[code]
ssh-keygen -t rsa -C ”xxx@gmail.com”
[/code]

3) Use server specific ruby version.

This is a bit trickier, i.e. instead of using globally installed ruby version, desire is to use ruby version specific to account owning rails app (aka. user ”rails” in this case).

/etc/apache2/conf.d/mod_passenger.conf
[code]

# PassengerRuby ”/usr/bin/ruby”
PassengerRuby ”ruby”

[/code]

Setup ruby (using RVM)
[code]
cd /home/www/virtual/host.kari.dy.fi
\curl -sSL https://get.rvm.io | bash
rvm install 2.1.5
cd current
bundle
gem install passenger -v 4.0.53
[/code]

Restart apache2
[code]
service apache2 restart
[/code]

Done!

/ Development, Rails, Web