4

I'm writing a silly little script to email people when a (Debian Lenny) server boots. Right now I've set it up as an init.d script using update-rc.d, but then I realized I could have just used cron jobs instead. Is it better to use cron jobs for something like this, or init.d?

I haven't actually tested whether the script runs at boot time but it should work. Haven't tried rebooting yet, but the underlying problem is that we randomly had the server reboot once and just shut down/power down randomly another time, so we're wondering whether it's power failures or something else. This would at least let us know when the server reboots.

Ibrahim
  • 394
  • 5
  • 12

3 Answers3

6

Since this sounds like a run-and-be-done script I would say that /etc/rc.local or cron (time: @reboot) is definitely the way to go.

On the other hand, anything which will stay daemonized should definitely has its own init script. If nothing else, to make sure it shuts down properly.

andol
  • 6,938
  • 29
  • 43
  • 1
    Ah, so making it an init script is kind of overkill? I thought it might be, but I wasn't sure. I think I'll go the `/etc/rc.local` route rather than mess with cron, since it's really just a one line script. – Ibrahim Dec 09 '09 at 22:06
  • Oh, does `/etc/rc.local` get run on shutdown or reboot (runlevels 0 and 6 if I understand correctly)? – Ibrahim Dec 09 '09 at 22:13
  • 2
    No, rc.local is start-only. If something needs to be shut down, it needs its own /etc/rc[0-6].d entries, or upstart (which is replacing sysv init to allow parallel booting). On Debian, /etc/rc.local is run from /etc/init.d/rc.local, which only has start entries. – Peter Cordes Dec 10 '09 at 00:57
5

/etc/rc.local gets executed on each boot, after all the other init scripts run. That would be another easy-to-implement option.

EEAA
  • 109,363
  • 18
  • 175
  • 245
2

Cron is a time based system. There are a lot of ways to do it. In lenny, you can use a script in /etc/rc.local. This file will be run at end of process, after all network startup that is needed to send mails.