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

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 = Logger.new(config.log_path, 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 {
  weekly
  missingok
  rotate 8
  compress
  delaycompress
  notifempty
  copytruncate
}

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

without comments

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
#Reference: https://www.redhat.com/docs/manuals/enterprise/RHEL-3-Manual/ref-guide/s1-nfs-server-export.html

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

/home/just_testing 192.168.0.0/24(rw,async,wdelay,root_squash)

#Run exportfs to refresh NFS exports

exportfs -av

Be sure the proper ports are open on iptables
Reference: http://pario.no/2008/01/15/allow-nfs-through-iptables-on-a-redhat-system/

## 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 192.168.0.2:/home/just_testing /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 10 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

#http://wiki.centos.org/AdditionalResources/Repositories/RPMForge

#Now install fuse

yum install fuse
modprobe fuse

#Download s3fs and make

cd /usr/local/src
wget http://s3fs.googlecode.com/files/s3fs-r191-source.tar.gz
cd s3fs
make

#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:

s3fs bucketname -o accessKeyId=XXXXXXXXXXXXXXXXXXXX -o secretAccessKey=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX /mnt/s3drive

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 , , , , ,

OpenOffice Headless Mode Installation Word doc to pdf conversion

with 2 comments

How to set up OpenOffice to run in headless mode on Fedora 9

What we wanted was a system set up to convert any OpenOffice document to PDF. Most importantly, we needed to convert Word .doc files to .pdf, but in fact, any OpenOffice file types (.xls, .odt, .txt, .rtf, etc) will work, as long as you install the proper packages / dependencies!

Also important:
We will be starting OpenOffice in headless mode, which means no GUI. This should be started on boot up, and should just run in the background.

Install:
You don’t need to install all the OpenOffice packages if you don’t need them. We are mainly concerned with Word docs, so OoWriter is a must. We are running in headless mode, which means we don’t have a GUI to openoffice. So we can leave out a bunch of unnecessary packages.

- Here’s what we have installed:

openoffice.org-core.x86_64  1:2.4.2-18.3.fc9 installed
openoffice.org-headless.x86_64 1:2.4.2-18.3.fc9 installed
openoffice.org-pyuno.x86_64 1:2.4.2-18.3.fc9 installed
openoffice.org-sdk.x86_64 1:2.4.2-18.3.fc9 installed
openoffice.org-writer.x86_64 1:2.4.2-18.3.fc9 installed
openoffice.org-writer2latex.x86_64 0.5-2.fc9 installed

If you need to convert Excel spreadsheets, ppt Powerpoint presentations to pdf, you will need to install the corresponding package (ie. openoffice.org-calc, openoffice.org-draw, etc.)

After you have these packages installed, be sure you have the soffice command. By default it is here:
/usr/lib64/openoffice.org/program/soffice.bin

Next, try to start up the service with this command:

$ /usr/lib64/openoffice.org/program/soffice.bin -headless accept="socket,host=localhost,port=8100;urp;" -nofirststartwizard &

#Note: the ampersand (&) allows the command to run in background so you get your shell back.
You can specify whichever port you would like. The -nofirststartwizard flag does exactly that.

Next step is to find a script (client) that can interact with this OpenOffice service.
A few options are:
1. dag’s unoconv (Available from yum)
http://dag.wieers.com/home-made/unoconv/
2. PyODConverter – a cool Python script to do conversions
http://www.artofsolving.com/opensource/pyodconverter
3. Write your own!

We chose to use PyODConverter. It’s simple to use:

$ PyODConverter.py example.doc example.pdf

Lastly, I mentioned that we want this soffice to start up everytime we reboot.

Simply add the line to your /etc/rc.d/rc.local

# Start up openoffice for fax conversion
$ /usr/lib64/openoffice.org/program/soffice.bin -headless accept="socket,host=localhost,port=8100;urp;" -nofirststartwizard

And there you have it. Hope that helps somebody. Happy Conversions!

Hint: If you are getting strange unintelligible errors about “URL seems to be an unsupported one”, it may be that you have not installed a necessary openoffice package. That’s how I discovered I needed OoWriter …

Written by Andrew Waage

September 17th, 2009 at 2:30 pm