Archive for the ‘Unix/Linux’ Category

Rotating Rails Log Files

Monday, September 10th, 2007

Logrotate

One of the chores I dislike most is cleaning up and clearing out the log files in my Rails applications. On some of my higher profile sites, I get a lot of spiders probing my applications for security holes. They don’t succeed (knock on wood) but they do fill up my log files with errors.

I finally decided to get smart and get lazy (the two best traits a programmer can have), and I set up automatic log rotation on all of my Rails applications. The idea behind log rotation is simple: make a back up of the current log file, continue logging into a new or cleared log file, and discard log files that are older than a certain date.

Your webserver probably already rotates its own log files. For Apache, they are probably located in /etc/httpd/logs and they are probably rotated weekly. These logs store everything Apache does. Simple webserver stats and traffic analysis tools make use of these log files to show who visits a site when and what pages are viewed.

While it is possible to configure your Rails application to log to your Apache log files, I do not think it is a good practice. It’s much better to give each Rails application its own log file—it will be easier to find important Rails errors, it will keep your Apache logs cleaner and Rails is set up to keep its own logs by default. Fortunately, on a Linux server the built-in logrotate program will make the process super-easy. After the jump, I’ll walk you through the steps to get it set up.

(more…)

Fedora 7 Released

Thursday, May 31st, 2007

Fedora 7

Fedora, the Linux-based operating system developed as a partnership between Red Hat and the open source community, released version 7 today. This version, code named “Moonshine”, is the first to be 100% developed by the community.

You can get more information about the release and download the new version.

Useful Shell Commands

Tuesday, May 29th, 2007

Nuby on Rails has posted some Useful Shell Shortcuts. I can see how these will come in very handy for me. I’ve been using Unix for over 15 years and I didn’t know all of these tricks!

Time for strftime

Wednesday, May 16th, 2007

Big Ben clockface

The strftime function is a common way for programmers to convert a computer time into a human-readable string. You can pronounce it “string-f-time”, “string-from-time”, or “string-format-time”. While Ruby and PHP each have their own implementation, the function is actually part of the Unix open spec. That’s great news for developers because it means that we can reuse the formatting techniques in any language. I’ve also found that the Ruby/Rails docs are a little lacking and you might not have known that there were more options available. Since it’s not just for Ruby, we don’t have to rely on them as our sole source of information.

Keep reading and I’ll show you how to use strftime, give you a full list of format codes (downloadable even), and demonstrate a useful helper function for working around one of the quirks of strftime.

(more…)

“Shall we play a game?”

Monday, May 14th, 2007

W.O.P.R. close up

The Fortune magazine article “Microsoft takes on the free world” has gotten a lot of press today. It’s a long article that outlines generally the history of the free and open-source software movement and in particular how Microsoft is readying for patent claims against Linux. The complete article is well-written and full of details, but I’ll attempt to sum it up for you.

Microsoft claims that Linux infringes 235 of its patents and wants royalties for what it sees as its intellectual property. The Free Software Foundation (FSF), started by Richard Stallman, wrote and maintains the GNU General Public License (GPL) which applies to Linux. The GPL requires that the software be entirely free (making royalty payments to Microsoft problematic), that the source code be open to the public and free to reuse, and, most importantly, that any software that uses GPL code also follow the same GPL terms.

(more…)