One of the big changes CentOS introduced on version 7 was the lack of native execution for custom scripts to boot from /etc/rc.d/rc.local file.
/etc/rc.d/rc.local was one of the most classic ways to add custom scripts to automatically boot after all the init.d scripts were started on old CentOS 5 and CentOS 6 versions.
However, many things changed in the new CentOS 7.x, that includes the way it handles services because of the new service managemet system.
On CentOS 7 that file is no longer executed by default (as it happened on previous CentOS versions) because of the adoption of systemd.
How to automatically run scripts at boot time on CentOS 7?
In order to execute / run scripts automatically from rc.local file (/etc/rc.d/rc.local) you need to apply execution permsisions to that file
Let’s make it executable by running this command as root:
chmod +x /etc/rc.d/rc.local
if that doesn’t work try
chmod u+x /etc/rc.d/rc.local
This chmod command activates activates the new rc-local which depends on Systemd service.
Once done, you can run scripts automatically by editing /etc/rc.local, which is a symbolic link to /etc/rc.d/rc.local file.
Now just add your scripts to the bottom of that file and that’s all, at this point you should automatically run scripts at boot time on CentOS 7.
How can I test my scripts run automatically after boot in CentOS 7?
Easy. Test the rc-local service by running:
systemctl start rc-local
Other way to test it is to reboot your server:
shutdow now -rf
Further reading: