Rss Feed Tweeter button Facebook button Technorati button Reddit button Linkedin button Webonews button Delicious button Digg button Flickr button Stumbleupon button Newsvine button

A Waage Blog

Ruby, Rails, Life

Archive for the ‘linux’ Category

Quick! create a self-signed SSL certificate in Ubuntu

with 2 comments

Especially for testing SSL, I can never remember how to create a self-signed certificate. Here’s a quick and dirty guide to setting up a self-signed certificate. Obviously, not recommended for production setups :)

We will create the certificate in the “/etc/ssl/self-signed” directory

# Become root first !
$ mkdir /etc/ssl/self-signed && cd /etc/ssl/self-signed
$ openssl genrsa -des3 -out server.key 1024
$ openssl rsa -in server.key -out server.key.insecure
$ mv server.key && mv server.key.insecure server.key
$ openssl req -new -key server.key -out server.csr
$ openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt

Now, you can use the files server.key and server.crt in your web server setups. See my post on Setting up Node.js with to accept HTTP and HTTPS connections for a quick example of using this SSL certificate with Node.js!

Written by Andrew Waage

February 27th, 2012 at 4:20 pm

Posted in linux, ubuntu

CSV Escaping Double Quotes

with 3 comments

What is the proper way to escape double-quotes in CSV files?

When you try to export from MySQL in CSV format, the MySQL reference manual itself suggests using


Now, I thought I had a nicely formatted CSV file where fields that have double quotes would be properly escaped. Looking through this .csv file, I can see that sure enough, all the double-quotes are turned from ” into \”.

This is fine, except that when I tried to use Excel to open the CSV file or FasterCSV (a nice Ruby library for working with CSV files), I find that the double quotes were not escaped “properly”. They are expecting to escape double-quotes with TWO double-quotes (”"). According to, this is a known discrepancy between the way different programs escape double-quotes in CSV files. Great.

Well, don’t worry – here’s a sed 1-liner that you can use on the command line to convert those \” (backslash double-quote) into “” (two double-quotes):

$cat file.csv | sed -E 's/\\"/""/g' > file2.csv

Hope that helps someone out there!

Written by Andrew Waage

February 16th, 2012 at 12:51 am

Rails Rotating Log Files with logrotate

with one comment

I know there’s a way to specify Rails log rotation parameters directly in the app. This works for some people:

# Can place this in environment.rb
# 2nd argument - number of log files to keep
# 3rd argument - size (bytes) that log files are allowed to reach before rotation
config.logger =, 8, 1024)

However…. I like the customizability of using logrotate better!
Here’s my logrotate config file that handles weekly log rotation, delayed compression and uses the copy-truncate method:

I place this config in the /etc/logrotate.d folder (ubuntu)
(ie. /etc/logrotate.d/<rails_app_name>)

/var/www/rails//shared/log/production.log {
  rotate 8

This config will rotate my production.log file weekly, keeping at most 8 log files. It delays compression until next rotation (extra precaution, simply to make sure the log file is not in use), and uses the ‘copytruncate’ method which basically copies the current log file, and then truncates this log file, so the Rails app maintains file pointer for continued writing.

Written by Andrew Waage

June 15th, 2011 at 11:56 am

CentOS NFS How-to Guide: Exporting and Mounting a NFS Drive

with one comment

This guide shows you how to start an NFS service on one (host) machine, export the NFS drive, and then connect to that NFS drive from a client machine.

## On the NFS host machine:

#Start Portmap service if needed.
#NFS uses portmap and a bunch of ports (that you can set in /etc/sysconfig/nfs) if you want.
See this link for more details on NFS ports.

#Start portmap service

service portmap status
service portmap start (if needed)

#Start NFS

service nfs start

#Edit /etc/exports

Format is (select the options you want):
[Directory to export] [Hosts to allow](options)


#Run exportfs to refresh NFS exports

exportfs -av

Be sure the proper ports are open on iptables

## Now on your NFS client machine:
Start portmap

service portmap start

Create a mount point and mount the NFS drive. Remember to use your own server’s IP address:

mkdir /mnt/nfs-usbdisk
mount /mnt/nfs-usbdisk

Voila ! Tail your logs if you have any problems !

Written by Andrew Waage

April 8th, 2010 at 7:22 pm

Posted in Networking, linux

Tagged with , , , ,

How to mount an Amazon S3 bucket as virtual drive on CentOS 5.2

with 12 comments

#Note: If you are using CentOS 4, it’s the same general process. You might have more difficulty finding the packages to install fuse and dependencies.

This is a simple guide on how to mount your S3 bucket as a “virtual drive”. This is great for backing up your data to S3, or downloading a bunch of files from S3.

#First, make sure you have the fuse package installed.

#On CentOS, fuse is available from RPMforge


#Now install fuse

yum install fuse
modprobe fuse

#Download s3fs and make

cd /usr/local/src
cd s3fs

#Copy the binary to /usr/local/bin (or wherever you prefer)

cp s3fs /usr/local/bin

#Make a mount point

mkdir /mnt/s3drive

#Mount your bucket like this:


That’s it ! You can change directory to your virtual drive or start copying files !
Go ahead and use a visual client such as CyberDuck or S3Hub to verify with your own eyes that this actually worked. :)
Good luck!

Written by Andrew Waage

April 6th, 2010 at 6:38 pm

Posted in Amazon Web Services, linux

Tagged with , , , , ,