1

I'd like to run a script at startup without actually adding it as a command to rc.local, just by copying a script somewhere.

I know in theory I can put it into /etc/init.d but that's really for services, not scripts that are just supposed to run on startup.

I know about the cron @reboot option as well but I really would prefer something where I just copy a script over to a directory and then can forget about it.

Basically, in the same way you can just put a file in /etc/cron.daily or /etc/logrotate.d I'm wondering if there's an equivalent folder where you just put in a file and it runs at startup.

If necessary I'm willing to install a program that does this for you, so long as it's stable.

1 Answer 1

5

I've managed this with the following which works well.

Create /etc/cron.d/reboot with the contents below. Note - It's been a while, you should check syntax.

@reboot root run-parts  /etc/cron.reboot

Create a folder /etc/cron.reboot

From there it's a matter of dropping files in to the cron.reboot folder.

4
  • This sounds perfect, even down to ending up with a directory structure that reflects my purpose. Commented Jan 21, 2016 at 15:53
  • Just one important change: @reboot run-parts /etc/cron.reboot should be @reboot root run-parts /etc/cron.reboot. The cron file has to have the user indicated. Commented Jan 21, 2016 at 18:37
  • @JordanReiter as an alternative you can add this the run-parts command to the rc.local just once. Commented Jan 21, 2016 at 21:57
  • Yeah, part of why I like your solution is it lets me keep rc.local untouched. This is a setup for a auto-launched instance so it's much nicer to be able to have the install script just copy the files over to a folder rather than modify existing files in rc.local. This way I can even commit these cron files to source control. Commented Feb 1, 2016 at 16:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .