No more init scripts?? Cool. 2 comments

Posted by robon November 15, 2007

I don’t know why this took so long for me to find out about crontab “nicknames” but I figure if it’s news to me, then it may be to many others too.

You need a service to restart with your server. You’ve done this enough that you’re eyes roll when you `cd` into /etc/rc.d or whatever, to create and initialization script for your service. Init scripts are pretty damn handy to have around for whatever services you have. They provide a standardized way to stop, start, and restart your service.

Unfortunately, writing init scripts is a pain in the ass. Ancient Unix Rule: Anything that’s a pain in the ass will get put on the back burner in the near future. For now, you just want to make sure your damn service starts when the idiot down at the colo power cycles your rack.

Quick, use cron:

1
2
-bash-3.00# crontab -l
@reboot cd /var/www/RAILS-APP/current; rm tmp/pids/mongrel.*.pid; mongrel_rails cluster::start

Done! Now either get back to work, or post a comment about your experience with restarting services and why this may or may not help you.

Here are more of these handy crontab short-cuts (from `man 5 crontab`):

These  special  time  specification  "nicknames"  are supported, which replace the 
5 initial time and date fields, and are prefixed by the '@' character:
@reboot    :    Run once, at startup.
@yearly    :    Run once a year, ie.  "0 0 1 1 *".
@annually  :    Run once a year, ie.  "0 0 1 1 *".
@monthly   :    Run once a month, ie. "0 0 1 * *".
@weekly    :    Run once a week, ie.  "0 0 * * 0".
@daily     :    Run once a day, ie.   "0 0 * * *".
@hourly    :    Run once an hour, ie. "0 * * * *".

Comments

Leave a response

  1. Jeremy KemperNovember 16, 2007 @ 12:07 AM

    Check out runit to really put this one to bed. Managing pidfiles is so dead to me. See http://www.sanityinc.com/articles/init-scripts-considered-harmful for a good intro.

  2. NoahDecember 07, 2007 @ 08:17 PM

    Except starting things with cron doesn’t send them signals on shutdown etc…