Init.d vs Cron - which to use?

6,117

Solution 1

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.

Solution 2

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

Solution 3

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.

Share:
6,117

Related videos on Youtube

Ibrahim
Author by

Ibrahim

Updated on September 17, 2022

Comments

  • Ibrahim
    Ibrahim almost 2 years

    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
    Ibrahim over 14 years
    Well, the email is sent to a local user, but that's probably a valid concern.
  • Ibrahim
    Ibrahim over 14 years
    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
    Ibrahim over 14 years
    Ah, that seems to be the simplest way to do it without leaving a lot of cruft everywhere.
  • Ibrahim
    Ibrahim over 14 years
    Oh, does /etc/rc.local get run on shutdown or reboot (runlevels 0 and 6 if I understand correctly)?
  • Dennis Williamson
    Dennis Williamson over 14 years
    An extension of cron is the ability to specify a time as "@reboot". Being an extension means, of course, the some versions don't support it.
  • Shiva Saurabh
    Shiva Saurabh over 14 years
    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.