Run Script At Startup

Home » CentOS » Run Script At Startup
CentOS 6 Comments

Hello,

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@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@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.

*–*
*Best regards.*
*Alex Berber*
*+9 72 54 285 952 3*
*www.linuxspace.org*

6 thoughts on - Run Script At Startup

  • Alan Holt wrote on 20/08/2014 15:07:

    You can re-enable it with this command:

    systemctl enable rc-local.service

    that enables the Unit /etc/systemd/system/rc-local.service

    Once you are familiar with systemd it is better to create a custom Unit for your purposes rather than using old rc.local

    Ciao, luigi

  • 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.

  • One of the nice things about the rc-local.service is that you don’t need to enable it with systemctl. It has a conditional check whether
    /etc/rc.d/rc.local is executable, and if it is, it runs it, otherwise, it ignores it. This was set up so people could basically act like they did in prior releases, and just drop executable scripts into
    /etc/rc.d/rc.local, and it just worked.

  • Short answer:

    http://forums.fedoraforum.org/showthread.php?t00234

    If you read through the thread, you’ll see that you probably need to put the rc.local file under the /etc/rc.d directory.

    Longer answer:
    As the file says, if you plan to stick with Linux, eventually, you’ll have to work with systemd. This list has already discussed it to death, but, much as many hate it, it’s not going to go anywhere for awhile.

  • And one of the options that had been discussed was: if you want to use
    “UNIX-like” system in a future, you may look for alternatives, e.g. BSD
    successors (like FreeBSD, NetBSD, PC-BSD, OpenBSD…). Or get used to “M$
    Windows – like” system.

    Good luck on whatever you decide for yourself!

    Valeri

    ++++++++++++++++++++++++++++++++++++++++
    Valeri Galtsev Sr System Administrator Department of Astronomy and Astrophysics Kavli Institute for Cosmological Physics University of Chicago Phone: 773-702-4247
    ++++++++++++++++++++++++++++++++++++++++