Creating a System Account in Mac OS X 10.5 Leopard
Introduction
With the upcoming release of leopard there are many changes under the hood. One of the small but quite annoying changes if you are used to the old ways is the removal of the NetInfo manager application. This is a blessing in disguise because the new implementation of user creation and account management.
Create the users home directory
sudo mkdir -p /Users/USER
Creating the users primary group
sudo dscl . -create /Groups/USER
sudo dscl . -create /Groups/USER PrimaryGroupID UID
Creating the user and setting options
sudo dscl . -create /Users/USER
sudo dscl . -create /Users/USER RealName "USER FULL NAME"
sudo dscl . -create /Users/USER NFSHomeDirectory /Users/USER
sudo dscl . -create /Users/USER UserShell /bin/SHELL
sudo dscl . -create /Users/USER UniqueID UID
sudo dscl . -create /Users/USER PrimaryGroupID UID
Setting the users passwd
passwd USER
Adding users to a secondary group
sudo dscl . -append /Groups/OTHERGROUP GroupMembership USER
Set the ownership of the users home directory to the users home dir
sudo chown -R USER:GROUP /Users/USER
Ruby on Rails Deployment
Introduction
Ruby on Rails is a wonderful platform for web applications and rapid web development. That being said when running an application using the ruby interpreter as well as the plethora of deployment options one can get confused quite quickly. I am writing this post to try and clear the muddy water of deploying Ruby on Rails web applications.
Platform Choices
Disclaimer: None of the recommendations below are tested for the Win 32 platform and there is a high probability that nothing will work correctly or at all.
All of the following deployment recommendations I will be writing about are achievable on most if not all of the UNIX/Linux/BSD operating systems that are available today. Now that we have those very important logistics out of the way lets get started with the foundation for rails deployment!
Note: Mac OS X Leopard (The next release slated for October) will ship with the Ruby on Rails stack already installed and ready to start development.
If you are running Mac OS X Tiger then head over to my Mac OS X Ruby on Rails setup How-To to get yourself up and running with an optimized server-grade Ruby on Rails installation.
Don't be too thrown off by that title because it can be used on any UNIX/BSD Operating System. Just switch up to a source based installation or use the package manager built into your OS.
Foundation
I have two recommendations for optimized Ruby on Rails hosting. I will go over the benefits of each and when to choose one over the other. Both options require an external listening web server and a process to access the Ruby on Rails web application.
Web Servers
I have two favorite WebServers that I use currently. One which runs the blog and one that I run on my internal servers. Each of the below web servers each offer their own advantages to the mix which you can weigh and choose the one based on your requirements.
- Nginx (Pronounced "Engine X")
- LiteSpeed
For example LiteSpeed is not open source and there are two version one which is "more optimized" which costs quite a bit of money. Both the free and commercial versions are managed via a web interface. There is also an option at the time of installation to enable AWstats to monitor the traffic on your website. This is quite simple to setup and maintain. The upgrade process detailed blow is extremely simple to do and requires minimal time and effort.
Ruby on Rails Dispatcher
There are two methods of dispatching the Ruby on Rails web application that I use. One which is handled though an API which is installed via a gem (Ruby LSAPI) and one that runs a backend server which handles the dynamic Ruby content (Mongrel).
- LiteSpeed Ruby LSAPI
- Mongrel HA Cluster
If you have never setup a High-Available cluster before don't worry mongrel makes this process very simple. The configuration for a mongrel cluster is also extremely easy to create and understand. The config file itself can be as small as three lines. I would recommend against this as there are some options that would allow for a more secure mogrel cluster. As you can see below mine is a little bit longer but still you can agree with me that it is quite easy.
---
cwd: /path/to/railsapp/
log_file: log/mongrel.log
port: "8000"
environment: development
address: 127.0.0.1
pid_file: tmp/pids/mongrel.pid
servers: 3
Comparison
Both of the above options are very good choices when deploying Rails web applications. Each have drawbacks. For example if you are on a resticted VPS or other RAM limited server then the choice would be to use the Ruby-LSAPI because it requires only one ruby process to be run thus saving you tons of memory. On average a ruby process takes about 32MB of RAM. This can be quite detrimental if you only have 256MB on a VPS if you are running a 3 server HA mongrel cluster which would require (you guessed it) 96 MB of RAM! That is without the web proxy running which is required by mongrel cluster to proxy between the mongrel servers.
On to the comparison of the web servers that we use as a reverse proxy, Litespeed and Nginx. Both are wonderful web servers that are efficient and have a very small memory footprint. Each taking about only 2MB of RAM to run with minimal load. As the load increases the RAM usage does not increase that much. That being said Litespeed with Ruby-LSAPI is a wonderful choice when RAM is a consideration. When running development mongrel and Nginx might seem more responsive depending on the load and the amount of mongrel servers you have running in the cluster.
Tip of the Day - Live Remounting of Filesystems
If you need to remount a in-use filesystem like / or /usr without rebooting the operating system, use the mount command with the -o remount option.
To remount the root partition using settings found in /etc/fstab.conf run:
mount -o remount /
This is handy if a filesystem has been mounted read only during a recovery process. For example to remount the root partition read/write do:
mount -o remount,rw /
If there is no /etc/fstab entry for the root partition (or any partition you are using) you may need to specify the root partition (/dev/sda1 in this example):
mount -o remount,rw /dev/sda1 /
Installing Ruby on Rails
Introduction
Ruby on Rails is a agile web development framework written in Ruby. Ruby is a very easy to use and easy to learn language. The syntax is quite enjoyable to work with and it "just makes sense." I like to consider Ruby a no-intimidation programming language.
In this post I will go into the installation of the Ruby on Rails web application framework. Talk about best practices and creating your first rails application.
The Installation
I would recommend when setting up a Ruby on Rails server that you compile the packages from source. You are guaranteed to have a solid installation which in turn provides a solid foundation for your rails web applications.
Create Necessary Directories
mkdir -p /opt/local/src
cd /opt/local/srcDownload Necessary Files
wget ftp://ftp.cwru.edu/pub/bash/readline-5.2.tar.gz
wget http://rubyforge.org/frs/download.php/20989/rubygems-0.9.4.tgz
wget ftp://ftp.ruby-lang.org/pub/ruby/ruby-1.8.6.tar.gzExtract Downloaded Packages
tar xzf ruby-1.8.6.tar.gz
tar xzf readline-5.2.tar.gz
tar xzf rubygems-0.9.4.tgzSetting Your Environment
echo 'PATH=/opt/local/bin:/opt/local/sbin:$PATH' >> ~/.bash_profileThe command above will automatically setup your PATH environment variable when you login. At this point run the following command to skip logging out and back in again.
. ~/.bash_profileInstalling Readline
cd readline-5.2
./configure
make
sudo make installInstalling Ruby
cd ../ruby-1.8.6
./configure --prefix=/opt/local --enable-pthread --with-readline-dir=/opt/local
make
sudo make installCheck Ruby Installation
bash $ ruby -v
ruby 1.8.6 (2006-08-25)If it does not look like this then the ruby installation either failed or your path is not correct
Installing RubyGems
cd ../rubygems-0.9.4
ruby setup.rbInstalling Ruby on Rails
sudo gem install rails -- --include dependenciesIf this step above fails just press the up arrow and run it again. It will work, there is some sort of bug in rubygems that causes this to fail on the first run.
Creating Your First Application
mkdir -p /var/www
cd /var/www
rails firstapp
cd firstapp
./script/generate controller hello index
echo "Hello World" > app/views/hello/index.rhtml
./script/serverNow open a web browser and navigate to the server's IP address, if it is on the local machine use 127.0.0.1:3000. This will display the web application that you just created. Now type the following into the URL.
http://127.0.0.1:3000/hello/Now the Hello World web application should appear in your web browser.
Where To Go From Here
Now that you have a fully working development environment setup on any operating system you are all set to either start developing in Rails or upgrading this machines purpose to be a production Ruby on Rails server.