1

I have a script that start my docker service and starts my container on RHEL7.3 machine when system reboots. Two ways are working for me: 1) Add script to rc.local 2) Add to crontab -e with path to my script.

Which one is better for me as both are working?

user432689
  • 11
  • 1

2 Answers2

2

Crontab is meant to regularly schedule jobs, not to start services at system startup. Doing this means doing it wrong.

Using rc.local is much better, but even better would be a regular systemd service file.

Sven
  • 97,248
  • 13
  • 177
  • 225
1

The rc.local script has the advantage that it runs at the end of the normal startup sequence. If you need most everything else started first rc.local is a better place for it. Disadvantages of rc.local are that it can grow in complexity quickly if it is used for too many things.

While cron works for this it may not do what you want by default with errors. It's sequence in startup may also vary a bit from system to system.

Finer control of sequence and error handling can be had by writing your own systemd units or init scripts. This is what I would consider the "proper" way and it has many advantages over both rc.local and cron.

David
  • 606
  • 4
  • 6