top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Run script at startup in centos7

+1 vote
1,324 views

After installation of Centos 7 I am not able to use /etc/rc/local file

Usually I used to add my script to /etc/rc.local

$ echo /usr/bin/bash /opt/my_scr.sh >> /etc/rc.local*

and it used to work but not with centos anymore.

posted Aug 20, 2014 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button
rc.local is systemV whereas CentOS 7 is systemD

1 Answer

0 votes

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

answer Aug 20, 2014 by Salil Agrawal
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.
Similar Questions
+1 vote

I encountered a problem when creating a VLAN interface according to the Red_Hat_Enterprise_Linux-7-Networking_Guide. I configured the parent interface ifcfg-eno1 as follows:

DEVICE=eno1
TYPE=Ethernet
BOOTPROTO=none
ONBOOT=yes

And I created a new file named ifcfg-eno1.5, the content is:

DEVICE=eno1.5
BOOTPROTO=none
ONBOOT=yes
IPADDR=192.168.81.3
PREFIX=24
NETWORK=192.168.81.0
VLAN=yes

Then I restarted the network:

 systemctl restart network 

After that I found that I couldn't connect to the Internet, even couldn't ping the gateway. I thought it might be I didn't set the GATEWAY in ifcfg-eno1.5, so I added the GATEWAY=192.168.81.254(My local area network gateway), it didn't work.

Could anybody teach me how to create a VLAN interface in CentOS7, or tell me what' s wrong with my configuration, more detailed more better.

+1 vote

I have to change IP numbers across a number of virtual and physical machines because of network center move. This has to be done before network startup, of course. I'm thinking about the best method to do this.
Where should I include/init this script? Or would it rather make more sense to do this on the last shutdown?

Changes largely involve removing old files and putting new files in place (resolv.conf, hosts, sysconfig/network + network-scripts, firewall, postfix, httpd etc.). The only other change besides replacing files would be changing the IP address in a webcontrol interface in a MySQL table, so this part has to be done after MySQL startup.

Could be run-once or have to disable manually after successful startup.

0 votes

I need to upgrade a bunch of centos 5 servers to 6.x in the near future, mostly keeping the same connectivity and functionality. Are there any tools that will examine a running 5.x box and produce the appropriate /etc/udev/rules.d/70-persistent-net.rules (etc). to make the same box come up with the same interface names with the same IPs it had before?

+3 votes

Probably is simple and silly question, I should have googled but still want to ask.
I want to run a script at the login to the Linux system, what is the best way to achieve this.

+2 votes

I am used to traditional update-rc.d et all.

Now I wonder how to add a a script that used to called by init.d (with start/sop ..) to the new "service start xx" regime.

All the tutorials I found talk about how to use update-rc.d..

...