1

I need to start my script during boot time. I have read that the scripts under /etc/init.d & /etc/profile.d are sourced during system startup. How different are these directories?

Other than the above two ways, seems we can also configure cron to start the service using an entry like @reboot /path/to script.

Please suggest the right/efficient way of executing the script during system startup.

1

/etc/profile.d is a vendor-specific means of customizing the environment of a shell session (setting PATH and so forth), and would not typically be related to the startup of a daemon; some would even argue that daemon startup should in no way involve /etc/profile.d, so that user shell customizations cannot cause a daemon to fail to load, or to load with incorrect environment settings (timezone, locale, or so forth).

/etc/init.d is part of the SystemV init system as implemented on Linux (Digital UNIX by contrast placed it under /sbin/init.d); one could write a proper init script (study the existing scripts to see how to do this properly) that would launch your daemon. This would give you compatibility with both RHEL6 and RHEL7.

An @reboot cron job could start your daemon, though systemd under RHEL7 does offer better management features than a fire-and-forget from cron (what happens if the daemon crashes? should it be restarted automatically? how bad would it be if multiple instances were started? if bad, what sort of locking would be necessary to only start one instance?).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.