Jul28th

Adding Rails cron jobs on Dreamhost

Okay, so I thought adding a cron job for my RoR application would be pretty easy. Having never done it before I started hitting the search engines to the how-to’s. I found this to be a lot harder than I thought due to some technical difficulties (on my part) so I want to detail how i FINALLY got it done.

First, http://wiki.dreamhost.com/index.php/Crontab is dreamhost’s writeup about crontab and it has mostly what you need for the syntax of each line in the crontab.

Here’s what I learned, a crontab holds a list of all the cron jobs you want to perform. At first i tried to create a local .txt file on my computer and ftp it up to the server. Due to the .txt file’s format and the fact that I’m using Dreamweaver for FTP (which I would not recommend), something did not work; something about ASCII format and the way it uploads the file (and also something about the last character in the file has to be cr\lf) <- dont worry about that.
So, this is how I got it done.

  1. I SSH’d to my dreamhost account (you can get there right?).
  2. Then type crontab -l to list the contents of your crontab file. If this is the first you’ve done of this kind of thing it will say that you dont have a crontab file.
  3. Next you need to change the default text editor to vim. Nano is the default editor for dreamhost and it will not work for creating a crontab. it has something to do with the way it writes an asterick (*). Type export EDITOR=vim to change the editor to vim. Note: I am horrbile with the commands for using vim as an editor and found this cheatsheet helpful: http://www.lagmonster.org/docs/vi.html
  4. Now you need to create the crontab file. Do so by typing crontab -e
  5. Ok, press ‘i’ to get into “insertion mode” in the text file. In my crontab the first line i specify my email address to send errors to. This is optional. If you want it, type MAILTO=”youremailaddress@somewhere.com” in the first line and press enter.
  6. We’re now going to add our first cron job to this file. Go to the link above to understand the components of the line you will be adding. In my crontab my first cron job looks like this 59 2 * * * ~/listyourwish.com/script/runner -e development 'ScheduledNotifications.send_out_notifications' > /cronlogs/notifications.log. This is telling crontab to run this job at 2:59am every day of every month of every year. A couple fo things to note here; the “~/” portion of the path referrs to your user’s home directory (/home/username). And the “> filename.log” tells crontab to write errors to that log file. Note about Ruby on Rails: in order to run a Ruby on Rails script from command line (cron) you must have the path of the script runner (command line ruby compiler ??) in the cron job line. It is located in your RoR app under script/runner
  7. if you want more than one script to run at different times then add a line for each script just like we did in the previous example.
  8. when you are done adding them, press the escape [ESC] key to exit out of “insertion mode”, then type :x [enter] to write and save your crontab.
  9. make sure your crontab is active by typing crontab -l to list it’s contents and you should see the new file you just saved

Jul23rd

Dreamhost Good and Bad

Nate Constant dreamhost, rant , Read on

I stumbled upon dreamhost fairly recently and have been pleased with a number of aspects of their service. First and foremost they’re cheap! Secondly, it’s been very easy to setup domains, email, databases, as well as getting my Rails apps working in a small amount of time.

Anyway, I guess I’m writing this because I’m also a little frusterated with the reliability of their service lately. Last week they were having severe network problems and their servers were in and out for 3 days making my apps unresponsive during parts of the day; outgoing email was not working at all and that was a nightmare. Well a few days ago they posted that all of their network issues were resolved and that things were back to normal.. not quite. Today were getting the same issues as before. Outgoing email not working, sites taking an enormous amount of time to load. MySQL acting slow.

I know that you get what you pay for and so that you may have to take Dreamhost’s good with the bad but there are so many people out there who rave about their service and how spectacular it is.

That’s it :)