[CentOS] Run script at startup

Wed Aug 20 13:27:11 UTC 2014
Jonathan Billings <billings at negate.org>

On Wed, Aug 20, 2014 at 04:07:59PM +0300, Alan Holt wrote:
> I just install the newest version of Centos 7 and I am a bit disappointed
> with new /etc/rc/local file
> I found that it's not usable anymore.
> 
> *[root at lab3 ~]# cat /etc/rc.local*
> " THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES"
> It is highly advisable to create own systemd services or udev rules
> to run scripts during boot instead of using this file.
> 
> Usually I was added my script to /etc/rc.local
> 
> *[root at lab3 ~]# echo /usr/bin/bash /opt/ssh_tunnel.sh >> /etc/rc.local*
> 
> And it was working perfect.
> 
> What I should do in new Centos 7, please help.

As the file says, it is highly advisable to create your own systemd
service to replace what you put in /etc/rc.d/rc.local (the actual
location, /etc/rc.local should be a symlink to /etc/rc.d/rc.local).  

/etc/rc.d/rc.local still works under CentOS7.  You can continue to use
it, however you'd be better served creating a systemd service unit.
Look at the documentation here:
http://www.freedesktop.org/software/systemd/man/systemd.service.html

Depending on what you're doing, you could probably use a service with
Type=oneshot.  You might want to tell it to also add a
Requires=network-online.target, since judging from the name of the
script, it needs networking to be active. 

-- 
Jonathan Billings <billings at negate.org>