Given a user with sudo (but not root) access on a remote box, the following deploy.rb script will perform a capistrano deploy of a ruby application:
Assumptions:
1. You’re using ‘git’. Although svn can be used, the script targets a git setup.
2. You’re using mongrel_cluster. Change the script accordingly if using passenger etc.
3. The application being deployed is dropped into a subfolder/subdirectory on the remote server. You can remove the task :recreate_public_link if you’re deploying to the root of a virtual directory.
4. A user and group called ‘mongrel’ has been created on the remote server. This owns the running mongrel_cluster processes. Relevant permissions are set by the script.
#-----------------------------------------------------
# deploy.rb - controls deployment setup/configuration
# using the capistrano or 'cap' deployment utility.
#-----------------------------------------------------
# requires mongrel_cluster recipes to allow restart of mongrel cluster
require 'mongrel_cluster/recipes'
set :application, "rentmanager"
set :user, "peter"
set :web_user, "apache"
set :location, "192.168.0.15"
# If you are using Passenger mod_rails uncomment this:
# if you're still using the script/reapear helper you will need
# these http://github.com/rails/irs_process_scripts
# namespace :deploy do
# task :start do ; end
# task :stop do ; end
# task :restart, :roles => :app, :except => { :no_release => true } do
# run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
# end
# end
ssh_options[:forward_agent] = true
default_run_options[:pty] = true
set :scm, "git"
set :scm_user, "git"
set :repository, "#{scm_user}@#{location}:/usr/local/share/gitrepos/#{application}.git"
set :scm_passphrase, "your password" #This is your custom users password
set :git_shallow_clone, 1
set :deploy_via, :remote_cache
set :branch, "master"
set :use_sudo, true
set :site_root, "app/rentmanager"
role :app, location
role :web, location
role :db, location, :primary=>true
set :deploy_to, "/var/www/html/test.threerock.com/#{application}"
#---------------
#mongrel details
#---------------
set :mongrel_conf, "#{deploy_to}/current/config/mongrel_cluster.yml"
set :mongrel_user, "mongrel"
set :mongrel_group, "mongrel"
set :runner, nil
set :mongrel_clean, true # helps keep mongrel pid files clean
#-----------------------
# migration parameters
#----------------------
set :rake, "rake"
set :rails_env, "production"
set :migrate_env, ""
set :migrate_target, :latest
before "deploy:update_code", "custom:set_permissions_for_checkout"
before "deploy:migrate", "custom:set_permissions_pre_schema_dump"
after "deploy:migrate", "custom:set_permissions_post_schema_dump"
before "deploy:migrations", "custom:set_permissions_pre_schema_dump"
after "deploy:migrations", "custom:set_permissions_post_schema_dump", "deploy:cleanup"
before "deploy:symlink", "custom:get_current_ownership"
after "deploy:symlink", "custom:update_application_controller",
"custom:yield_current_ownership",
"custom:set_permissions_for_runtime",
"custom:recreate_public_link"
namespace(:deploy) do
desc "Restart the Mongrel processes on the app server."
task :restart, :roles => :app do
mongrel.cluster.stop
sleep 2.5
mongrel.cluster.start
end
end
namespace(:custom) do
desc "Change ownership of target folders and files to current user"
task :set_permissions_for_checkout, :except => { :no_release => true } do
#chown of files to current user
sudo "chown -R #{scm_user}:#{scm_user} #{deploy_to}"
end
desc "Change ownership of target folders and files to current user"
task :set_permissions_for_runtime, :except => { :no_release => true } do
#chown of files to current user
sudo "chown -R #{web_user}:#{web_user} #{deploy_to}"
sudo "chown #{mongrel_user}.#{mongrel_group} -R #{deploy_to}/current/tmp/pids"
sudo "chown #{mongrel_user}.#{mongrel_group} -R #{deploy_to}/current/log"
sudo "chown #{mongrel_user}.#{mongrel_group} -R #{shared_path}/pids"
end
desc "Recreate link to serve public folders when hosting within subfolder"
task :recreate_public_link do
run <<-CMD
cd #{deploy_to}/current/public && sudo ln -s . #{application}
CMD
end
desc "Take temporary ownership of current folder to allow symlink updates"
task :get_current_ownership do
sudo "chown #{user}:#{user} #{release_path}"
end
desc "Take temporary ownership of current folder to allow symlink updates"
task :yield_current_ownership do
sudo "chown -R #{web_user}:#{web_user} #{release_path}"
end
desc "Change ownership of db folders and files to current user"
task :set_permissions_pre_schema_dump, :except => { :no_release => true } do
#chown of files to current user
sudo "chown -R #{user}:#{user} #{release_path}/db"
end
desc "Change ownership of db folders and files to current user"
task :set_permissions_post_schema_dump, :except => { :no_release => true } do
#chown of files to current user
sudo "chown -R #{web_user}:#{web_user} #{release_path}/db"
end
desc "Update application.rb to application_controller.rb"
task :update_application_controller, :roles => :app do
run <<-CMD
cd #{deploy_to}/current/ && sudo rake rails:update:application_controller
CMD
end
task :config, :roles => :app do
run <<-CMD
sudo ln -nfs #{shared_path}/system/database.yml #{release_path}/config/database.yml
CMD
end
desc "Creating symbolic link (custom namespace)"
task :symlink, :roles => :app do
run <<-CMD
sudo ln -nfs #{shared_path}/system/uploads #{release_path}/public/uploads
CMD
end
end
Share on Facebook
No Comments // Posted on 8 May, 2012 // Git, GNU/Linux, Ruby on Rails
Keeping your Ubuntu server up to date couldn’t be simpler
sudo apt-get update; sudo apt-get upgrade
That’s all folks!
Share on Facebook
No Comments // Posted on 6 April, 2012 // GNU/Linux, Security
Hopefully this will be a time saver for anyone else who goes through the following pain.
I have a brand spanking new OSX 10.6 installation.
I installed mysql 5.5.9-OSX10.6-X86 (because I thought everything was still i386 based…watch this space!)
I installed RVM and installed ruby 1.92 under RVM control.
I then do a ‘bundle install’ and it gripes about not having mysql2 gem installed. I do a manual install using the following command.
and after a bit of crunching, we get to the following error:
Building native extensions. This could take a while...
ERROR: Error installing mysql2:
ERROR: Failed to build gem native extension.
1.9.1/ruby/ruby.h:108: error: size of array ‘ruby_check_sizeof_long’ is negative
/Users/peter/.rvm/rubies/ruby-1.9.2-p180/include/ruby-1.9.1/ruby/ruby.h:112: error: size of array ‘ruby_check_sizeof_voidp’ is negative
In file included from /Users/peter/.rvm/rubies/ruby-1.9.2-p180/include/ruby-1.9.1/ruby/intern.h:29,
from /Users/peter/.rvm/rubies/ruby-1.9.2-p180/include/ruby-1.9.1/ruby/ruby.h:1327,
from /Users/peter/.rvm/rubies/ruby-1.9.2-p180/include/ruby-1.9.1/ruby.h:32,
from ./mysql2_ext.h:4,
from client.c:1:
/Users/peter/.rvm/rubies/ruby-1.9.2-p180/include/ruby-1.9.1/ruby/st.h:69: error: size of array ‘st_check_for_sizeof_st_index_t’ is negative
The Solution
Uninstall your MySQL using the commands below
sudo rm /usr/local/mysql
sudo rm -rf /usr/local/mysql*
sudo rm -rf /Library/StartupItems/MySQLCOM
sudo rm -rf /Library/PreferencePanes/My*
edit /etc/hostconfig and remove the line MYSQLCOM=-YES-
sudo rm -rf /Library/Receipts/mysql*
sudo rm -rf /Library/Receipts/MySQL*
Now go and download the 64 bit version of the MySQL package – get the dmg rather than the gzip file.
The rationale behind this is that your new beaut 10.6 is actually referencing 64 bit modules by default. How to prove this I do not know – I’m confused and still searching for the answer. If I do a uname – a I get…
Darwin MacBook-Air.local 10.6.0 Darwin Kernel Version 10.6.0: Wed Nov 10 18:13:17 PST 2010; root:xnu-1504.9.26~3/RELEASE_I386 i386
Now, if I’m not mistaken that’s an i386 at the end – go figure. If anyone has any further insights please let me know.
The next step is to download the gem for your ruby/rails use
sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- \
--with-mysql-dir=/usr/local/mysql --with-mysql-lib=/usr/local/mysql/lib \
--with-mysql-include=/usr/local/mysql/include
The next error encountered is when I try to start the rails server using ‘rails s’
/Users/peter/.rvm/gems/ruby-1.9.2-p180/gems/mysql2-0.2.6/lib/mysql2.rb:7:in `require': dlopen(/Users/peter/.rvm/gems/ruby-1.9.2-p180/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle, 9): Library not loaded: libmysqlclient.16.dylib (LoadError)
The answer to this problem is to run the following command…
sudo install_name_tool -change libmysqlclient.16.dylib /usr/local/mysql/lib/libmysqlclient.16.dylib ~/.rvm/gems/ruby-1.9.2-p180/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle/
Bear in mind, I’m running version 1.9.2-p180 fo ruby – you will need to change the command for whatever version you’re running.
Share on Facebook
2 Comments // Posted on 15 March, 2011 // GNU/Linux, OSX, Ruby on Rails, Uncategorized
A client who shall remain nameless recently required the installation of some spam filtering software (spamassassin) on their linux mail server. Not a problem I thought. “All I need is root access” I said. “Huh” he said. Turns out the their system administrator of 5 years had left to go travelling around Europe and no-one could remember where he left the folder with all the system documentation. No root password, no history of what was installed when, no history of custom configuration changes. Nichts, Nada!
Question: How to get root access to a machine without the root password.
1. Reboot and select the grub ‘recovery’ option – you can get to this from the boot menu or if you have a linux box with a single boot option, hold down the shift key during boot (occasionally the escape key works – watch the messages during the boot sequence).
2. The next screen to display will present you with a couple of sub-options. You need to select the ‘Drop to root shell prompt’.
3. You should now be presented with a prompt sign. Now’s your chance to reset the password for the appropriate user. Enter passwd [username] where [username] is the name of the …you get the drift.
4. Next enter the new password and buy a 15ft billboard ad to display across the road from your client’s site. Of course the ad will display the encrypted version of the password:)
Share on Facebook
No Comments // Posted on 4 March, 2011 // GNU/Linux
Up until earlier this week, I had my lovely little netbook working nicely with Ubuntu 8.04 and a 90% satisfaction rate with the network manager utility. I could connect to my home network, office network and with abit of hassle, other free wifi spots. I started to get a message that my version of ubuntu was now unsupported, so I thought I’d set about upgrading to 10.04 (maybe 10.10 if I had the time).
I chose the default upgrade process using the system update options progressively moving from 8.04 to 9.04, 9.10 and finally settling on 10.04. I did all the upgrading with a hard-wired ethernet cable.
Bang!! unplugged the network cable and moved to the comfort of my living room to finish some minor tweaks. No wireless network connectivity. I thought network manager may have been giving me hell and I heard some good stories about wicd (which I have running with 100% success on my laptop).
Here comes a lesson…are you paying attention? I decided to uninstall network manager and install wicd (in that order). Doh!! Ok, now I have an unconnected netbook with no wireless and ethernet connectivity and I’ve spent the last two mornings on the way to work on the train trying to patch the system with uploads from a usb stick. No fun, no glory.
What I’m going to have to do is burn 10.04 to a bootable memory stick and do a re-install from scratch. Then I’m going to have to pray I can fix the original issue with wireless card. It’s an RA2860 and there’s bundles of articles in discussion forums regarding it’s incompatibility with Linux distros. Here’s praying I don’t have to install XP to get my work done on the train.
Share on Facebook
No Comments // Posted on 12 November, 2010 // GNU/Linux
Author Ellie Quigley
ISBN 0-13-147572-X
Published by Prentice Hall
Priced in Australia at $87.99 (June 2010)
No matter which shell you run and how ever long you’ve been using it, you’ll probably pick up a trick or two from this book.
Now in it’s 4th edition, this book is stuffed with real world examples of all the useful GNU/Linux shell tools. It focuses on awk, sed, grep and their many variations. It builds from simple examples with extensive use of regular expressions.
Although running to over 1,000 pages, the first 450 are where I found the real meat. The remainder is a comparison of the different shells and their many quirks
As far as I can see, you can approach this book in one of two ways.
Firstly as a student, set aside a few quiet Sundays and go through the examples one by one, some of it may feel like repetition, but progressively you’ll get the picture and it will be well ingrained in your brain.
Secondly as a reference. I use the bash shell, but I often find useful scripts created on csh or heaven’s forbid zsh. So the trick is knowing what’s different and what needs changing. To this end Unix Shells By Example is very handy to have on the shelf.
Share on Facebook
No Comments // Posted on 5 August, 2010 // Books, GNU/Linux