Posted by jason on Dec 30, 2009 in
Mac,
MySQL
Somehow, I either forgot my password, or I did something to mess up my MySQL instance. it is a development machine, so I don’t really care about the databases on it. I just wanted to remove it completely from my machine. I actually had two copies of mysql installed. One from Mac Ports and the other was the package directly from MySQL for the Mac.
I used the following commands to completely remove mysql from my system.
sudo port uninstall mysql5-server
sudo port uninstall mysql5
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-
rm -rf ~/Library/PreferencePanes/My*
sudo rm -rf /Library/Receipts/mysql*
sudo rm -rf /Library/Receipts/MySQL*
Thanks to Rob Allen.
Posted by jason on Dec 30, 2009 in
MySQL
netstat -ln | grep mysql
Posted by jason on Dec 30, 2009 in
Ruby
This documents how I create Ruby on Rails applications and deploy them to my server. I have created a bare bones apache web server that hosts ruby applications using MySQL. It also assumes you have Ruby on Rails set up on a Macbook Pro.
Server Side
User
mkdir ~/myrumbleapp
mkdir ~/myrumbleapp/www
mkdir ~/myrumbleapp/www/current
mkdir ~/myrumbleapp/logs
GIT
sudo groupadd myrumbleapp
sudo usermod -a -G myrumbleapp {USER}
cd ~/myrumbleapp
mkdir git
sudo chown {USER}.myrumbleapp git
cd git
git init --bare --shared=group
MySQL
mysql -u root -p
mysql> create database myrumbleapp;
mysql> use myrumbleapp;
mysql> grant all on myrumbleapp.* to myrumbleapp@localhost identified by 'password';
Apache2
/etc/apache2/sites-available/myrumbleapp
<VirtualHost *:80>
ServerName www.myrumbleapp.com
ServerAlias myrumbleapp.com
DocumentRoot /home/{USER}/www.myrumbleapp.com/www/current/public
ErrorLog /home/{USER}/www.myrumbleapp.com/logs/error_log
TransferLog /home/{USER}/www.myrumbleapp.com/logs/access_log
</VirtualHost>
sudo ln -s /etc/apache2/sites-available/myrumbleapp /etc/apache2/sites-enabled/myrumbleapp
sudo /etc/init.d/apache2 restart
Client Side
On the client
First, create a skeleton rails application. For this example, I will be using “myrumbleapp”. We will also freeze the rails version into our application. That way we never have to worry about rails versions on serverrs.
cd ~/Sites/
rails myrumbleapp
cd ~/Sites/myrumbleapp
rake rails:freeze:gems
/.gitignore
tmp
log
mkmf.log
config/database.yml
Capistrano
cd ~/Sites/myrumbleapp
capify .
I use the following deploy.rb file. The important part is that it creates a link from my shared/system/config/database.yml file into the release folder. I keep the database.yml file out of GIT because it seems to be a best practice that other folks follow. Not exactly sure it is necessary with my code since I host my own GIT repos accessible only via SSH.
/config/deploy.rb
default_run_options[:pty] = true
set :application, "myrumbleapp"
set :repository, "{USER}@{SERVER.COM}:myrumbleapp/git"
set :user, "USER"
set :deploy_to, "/home/{USER}/myrumbleapp/www"
set :scm, :git
set :branch, "master"
role :web, "{SERVER.COM}"
role :app, "{SERVER.COM}"
role :db, "{SERVER.COM}", :primary => true
namespace :deploy do
desc "restart passenger"
task :restart, :roles => :app, :except => { :no_release => true } do
run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
end
[:start, :stop].each do |t|
desc "#{t} task is a no-op with passenger"
task t, :roles => :app do ; end
end
desc "Symlink shared configs and folders on each release."
task :symlink_shared do
run "ln -nfs #{shared_path}/system/config/database.yml #{release_path}/config/database.yml"
end
end
after 'deploy:update_code', 'deploy:symlink_shared'
GIT
Next we will check our application into GIT version control.
git init
cp config/database config/database.tmp.yml
git add .
git commit -m "initial checkin"
Configure the remote repository for GIT
git remote add origin {USER}@snowcaptech.com:myrumbleapp/git
Push the skeleton application to the server
git push origin master
Deploy the application
cap deploy:setup
cap deploy
cap deploy:migrations
Posted by jason on Dec 30, 2009 in
Ruby,
Ubuntu
General
Install Ubuntu 9.1 server using the Bare Server option
The first thing I like to do is add my account to the /etc/sudoers file. This just guarantees that I can always use sudo, even if I mistakenly mess up my group assignment.
sudo visudo
# /etc/sudoers
root ALL=(ALL) ALL
user ALL=(ALL) ALL
user should be replaced with the account you use to administer the box. I like to do this because one time I messed up my group assignment on the only account that was able to admin the box.
alias sudo='sudo -E'
The reason we have that alias nonsense in there is because Ubuntu compiles the sudo command with the –with-secure-path option. We want to pass our current path into the command. The alias command is explained here. I’m sure there are some security vulnerabilities with muti-user systems doing it this way, but I’m the only guy so no need to figure it out right now.
Next, update the apt-get configuration and then upgrade to make sure the latest packages are installed.
sudo apt-get update
sudo apt-get upgrade -y
Configure the server for static IP address.
SSH
Configure SSH.
Ruby
As I write this, the latest version of Ruby for apt-get is 1.8.7 patchlevel 174.
sudo apt-get install build-essential libssl-dev libreadline-dev rake -y
sudo apt-get install ruby rdoc ri rubygems libopenssl-ruby ruby-dev -y
I like to create a current symbolic link that links to the current gem so I can easily upgrade and not have to redo all my paths.
ln -s /var/lib/gems/1.8 /var/lib/gems/current
Now, source the file you just created. Sourcing a file uses the contents of the file as if you typed them at the command prompt. You just type a period followed by a space and then the filename.
. /etc/profile.d/gems.sh
You will notice that we did not install Rails. This is intentional. We will use
rake rails:freeze:gems
to freeze a known version of rails into our applications.
MySQL
sudo apt-get install mysql-server libmysqlclient-dev
sudo gem install mysql
Apache
We will install Apache2 as well as Passenger (mod_rails or mod_rack).
sudo apt-get install apache2 libapr1-dev apache2-prefork-dev -y
sudo gem install passenger
sudo /var/lib/gems/current/bin/passenger-install-apache2-module
After you run this, you will see instructions to add some lines to your Apache configuration file. Mine looked like this:
LoadModule passenger_module /var/lib/gems/1.8/gems/passenger-2.2.8/ext/apache2/mod_passenger.so
PassengerRoot /var/lib/gems/1.8/gems/passenger-2.2.8
PassengerRuby /usr/bin/ruby1.8
LoadModule passenger_module /var/lib/gems/1.8/gems/passenger-2.2.8/ext/apache2/mod_passenger.so PassengerRoot /var/lib/gems/1.8/gems/passenger-2.2.8 PassengerRuby /usr/bin/ruby1.8
Just copy this to it’s own file in the conf.d directory of apache2.
sudo vi /etc/apache2/conf.d/passenger.conf
GIT
Install and configure GIT on the server and the client.