How to make some initscript start after delay at boot?

9,889

"More or less cleanly" is my second name. Use the @reboot function in /etc/crontab as I show it here. Will be a line in /etc/crontab like

@reboot root (sleep 3600; /etc/init.d/whatever start) &

and of course update-rc.d disable whatever.

Share:
9,889

Related videos on Youtube

Vi.
Author by

Vi.

Updated on September 18, 2022

Comments

  • Vi.
    Vi. over 1 year

    I want to run a thing that may disrupt the system (or remote access to it) if something goes wrong (for example, misconfiguration).

    To reduce problems I want to have a "grace period" after the system already started, but before "dangerous" service started.

    Requirements:

    1. Delay is applied only on automatic starting of the initscript, not when I /etc/init.d/whatever start manually;
    2. The script is not started until its dependencies are ready (according to usual rules in initscript headers);
    3. Boot process should go on, without waiting for the full timeout.

    How to do it more or less cleanly?

    Related: https://superuser.com/questions/460112/how-do-i-run-a-script-5mn-after-startup

  • Olivier Dulac
    Olivier Dulac over 10 years
    wait 3600 should be sleep 3600 ?
  • Vi.
    Vi. over 10 years
    How will it protect from early start in case of boot sequence takes longer than usual? I.e. cron is started, then some dependency takes very long to start (more than 3600), then whatever being started out-of-order by cron.
  • Olivier Dulac
    Olivier Dulac over 10 years
    @Vi: "whatever" should then veriry&wait until "this" and "that" happened. But it will only have to wait after that first sleep (here, sleep 3600 which is 1 hour) ... And can wait also by using a while ( not_this_and_that_yet ) ; do sleep 60 ; done (for example). using sleep allow the kernel to just put the script "on the side" until the next wake period