CentOS Amazon EC2 – Adding Script to Run at Startup Without rc.local

amazon ec2centos

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.

Best Answer

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.

Related Topic