Posts belonging to Category Scripting



Ruby 1.9.3 on Mac OS X version 10.7 (10.7.3 to be precise)

I already know a number of programming languages, but as we are moving to a couple of tools that utilize Ruby, it became clear that I needed to break down and learn ruby. Working on MS Windows and Linux getting various versions installed has not been an issue. It is only when I went to use version 1.9.x on my MacBook that I realized this was not as simple as I hoped.

There are two main branches when it comes to Ruby: 1.8.x and 1.9.x. While both work fine, there are a number of improvements in the 1.9 stream, and as such I wanted to learn on this one. On my linux machines I was using RVM to manage different installations of Ruby without issue. You can go over to RVM for instructions on how to install RVM. Note: Close your Terminal and reopen so that the environment is properly sourced.

The problem is when you go to install 1.9.x or anything with RVM. I was getting the following errors:

mymachine:~ myusername$ rvm install 1.9.3
Compiling yaml in /Users/myusername/.rvm/src/yaml-0.1.4.
Error running 'make ', please read /Users/myusername/.rvm/log/ruby-1.9.3-p125/yaml/make.log

Database file /Users/myusername/.rvm/config/packages does not exist.

Turns out ‘make’ was not installed.

To install ‘make’you have to do a couple of things. First, you need to install Xcode. You can get this from Apple.

This will only get you part of the way. Next you need to login to the Apple Developer network. At least you can use your Apple ID to register, and install the command line tools. This is the page with ‘Command Line Tools for Xcode’. Download this and install it, and you will be 90% of the way to getting RVM working.

Now, when you go to run ‘rvm install 1.9.3′ you will get an error similar to ‘There has been an error while running configure. Halting the installation.’ You need to add an option to rvm to get it to work.

$ rvm install 1.9.3 --with-gcc=lang

After running it like this you should have the following.


interloper:rightscale myusername$ rvm install 1.9.3 --with-gcc=clang
Fetching yaml-0.1.4.tar.gz to /Users/myusername/.rvm/archives
Extracting yaml-0.1.4.tar.gz to /Users/myusername/.rvm/src
Configuring yaml in /Users/myusername/.rvm/src/yaml-0.1.4.
Compiling yaml in /Users/myusername/.rvm/src/yaml-0.1.4.
Installing yaml to /Users/myusername/.rvm/usr
Installing Ruby from source to: /Users/myusername/.rvm/rubies/ruby-1.9.3-p125, this may take a while depending on your cpu(s)...

ruby-1.9.3-p125 - #fetching
ruby-1.9.3-p125 - #extracted to /Users/myusername/.rvm/src/ruby-1.9.3-p125 (already extracted)
ruby-1.9.3-p125 - #configuring
ruby-1.9.3-p125 - #compiling
ruby-1.9.3-p125 - #installing
Retrieving rubygems-1.8.15
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  245k  100  245k    0     0   356k      0 --:--:-- --:--:-- --:--:-- 1386k
Extracting rubygems-1.8.15 ...
Removing old Rubygems files...
Installing rubygems-1.8.15 for ruby-1.9.3-p125 ...
Installation of rubygems completed successfully.
ruby-1.9.3-p125 - adjusting #shebangs for (gem irb erb ri rdoc testrb rake).
ruby-1.9.3-p125 - #importing default gemsets (/Users/myusername/.rvm/gemsets/)
Install of ruby-1.9.3-p125 - #complete
interloper:rightscale myusername$

TLDR — for those with add or no need to read it all.
1. Install RVM
2. Source shell or restart Terminal program
3. Install Xcode
4. Insall command line tools for xcode
5. Run command ‘rvm install 1.9.3 –with-gcc=clang’

Hope this helps.

Rightscale Centos Security Updates

I recently started working with RightScale to manage servers in various cloud environments. The servers that I am working with are in the Amazon EC2 cloud, but RightScale provides an interface to manages servers in multiple cloud spaces.

The underlying operating system for the servers that I am managing are running CentOS. While I prefer RedHat, CentOS is fine. I understand the reason for going with both, and when cost is an issue CentOS commonly wins out. The version is CentOS version 5.4.

The problem is that the servers are not getting updates. Based on the RightScale blog, you should be able to choose a RightScale supported frozen image of the CentOS mirrors from any given day, and they will have the most up to date patches to that day. As the servers do not maintain state between reboots, this means you can set the repo for a specific date, and the patches would be consistent for multiple machines no matter when they were booted.

This is the concept. The problem is that there was a glitch in the way that RightScale was updating the CentOS mirrors. As such, there is a length of time, approximately March of 2011 to Oct 13, 2011, where none of the CentOS mirrors were being updated. I am glad to say that working with RightScale support we were able to get them to correct this. The reporting of the glitch was actually documented in a forum discussion, but we also received it during a phone session we had with them.

One would think this would be all well and good, and that you could just choose the release date you wanted to use and be on your merry way. Wrong. Due to the way that the CentOS mirrors work, once a new release is available, they quit releasing updates into the older streams. This means that you have to change the repos to point to the 5/ mirror path instead of 5.4/ . To do this I have created a RightScript that takes to inputs and uses them to update the repo files.

You should run it early on in the process. I put it as my second or third script.

#!/usr/bin/env python

import re
import os
import sys
import subprocess

repoDir = "/etc/yum.repos.d/"

BASE_REPO_VERSION = os.getenv("BASE_REPO_VERSION", "5.4")
NEW_REPO_VERSION = os.getenv("NEW_REPO_VERSION", "5")

# Go through the list of repos, and change the Version from 5.x to base of 5 to get updates.
try:
	for filename in os.listdir(repoDir):
		if re.search("\.repo$", filename):
			try:
				os.rename (repoDir + "/" + filename, repoDir + "/" + filename + ".base")
			except Exception, e:
				sys.stderr.write("Error renaming file: %s\n" % (e))
			try:
				o = open( repoDir + filename, "w")
				data = open( repoDir + filename + ".base").read()
				o.write( re.sub(BASE_REPO_VERSION, NEW_REPO_VERSION, data))
				o.close()
			except Exception, e:
				sys.stderr.write("Error writing modified repo: %s\n" % (e) )
				sys.exit(1)

except Exception, e:
	sys.stderr.write("Error Listing Directory Contents: %s\n"  %  (e))
	sys.exit(1)

# Now we need to update the server with running patches.
# Done.
try:
	sysUpdate = subprocess.Popen(['yum', '--exclude', "kernel'*'", '-y', 'update'], shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
	sysUpdateOutput = sysUpdate.communicate()
	retcode = sysUpdate.returncode
	if retcode != 0:
		sts.stderr.write("Yum update returned an error\n%s\n%s" % (stdout, stderr))
	else:
		print ("Output from yum command:\n%s\n" % (stdout))

except Exception, e:
	print ("Output from yum command:\n%s\n" % (stdout))
	sys.stderr.write("Error Running yum update: %s\n" % (e))
	sys.exit(1)