I want to add a permanent iptables rule to my new VPS, and after brief google search i was surprised that there are two places this rule can be added, that seems like identical: /etc/rc.local and /etc/init.d/rc.local. Maybe someone knows why where is two places for simple startup code to place? Is it linux flavor specific (but ubuntu has both!)? Or one of them is deprecated?
-
1One should be a symlink to the other. – Ignacio Vazquez-Abrams Dec 31 '12 at 11:03
-
2@IgnacioVazquez-Abrams On Ubuntu Server 12.04 x86 LTS they are completely different :(. – grigoryvp Dec 31 '12 at 11:03
-
1@IgnacioVazquez-Abrams: On Debian they seem to be different as well. – Emanuel Berg Jan 01 '13 at 12:07
-
3Worth checking out: I asked a [question](http://unix.stackexchange.com/questions/49626/purpose-and-typical-usage-of-etc-rc-local) about `/etc/rc.local` a while back. – Emanuel Berg Jan 01 '13 at 12:10
-
possible duplicate of [What's the difference between /etc/rc.d/rc\*.d and /etc/rc\*.d](http://unix.stackexchange.com/questions/30728/whats-the-difference-between-etc-rc-d-rc-d-and-etc-rc-d) – n611x007 Jul 21 '15 at 11:17
-
@IgnacioVazquez-Abrams Perhaps you wanted to say that `/etc/rc.local` is a symlink of `/etc/rc.d/rc.local`? – John Red Feb 14 '17 at 10:26
2 Answers
/etc/init.d is maintained on ubuntu for backward compatibility with sysvinit stuff. If you actually look at /etc/init.d/rc.local you'll see (also from a 12.04 LTS Server):
#! /bin/sh
### BEGIN INIT INFORMATION
# Provides: rc.local
# Required-Start: $remote_fs $syslog $all
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop:
# Short-Description: Run /etc/rc.local if it exist
### END INIT INFO
And "Run /etc/rc.local" is exactly what it does. The entirety of /etc/rc.local is:
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
exit 0
I would guess the purpose in doing this is to provide a dead simple place to put shell commands you want run at boot, without having to deal with the stop|start service stuff, which is in /etc/init.d/rc.local.
So it is in fact a service, and can be run as such. I added a echo line to /etc/rc.local and:
»service rc.local start
hello world
However, I do not believe it is referenced by anything in upstart's /etc/init (not init.d!) directory:
»initctl start rc.local
initctl: Unknown job: rc.local
There are a few "rc" services in upstart:
»initctl list | grep rc
rc stop/waiting
rcS stop/waiting
rc-sysinit stop/waiting
But none of those seem to have anything to do with rc.local.
- 373
- 1
- 5
- 14
- 86,451
- 30
- 200
- 258
This is more of a distribution specific thing. (like, you will not find different rc.local in CentOS).
Now coming to your actual question, I think adding anything inside /etc/init.d/rc.local makes it to start as a "service" whereas, anything inside /etc/rc.local would simply launch that script at boot time.
I am not really sure on why Ubuntu still maintains both of them? (Perhaps someone else might shed some light over this part !!)
- 131
- 8
-
What is the difference between command that is executed "as a service" and a code that is "simply launched at boot time"? Is it some security or what? – grigoryvp Dec 31 '12 at 11:40
-
The core difference between the two is essentially of a Service and a process. ;) I guess the basic intent would be security only. You might find this link interesting: http://www.unixmen.com/managing-your-services-and-processes-in-linux/ – pragmatic Dec 31 '12 at 11:54
-
This is incorrect! They are not the same script, but they **are** one service -- `/etc/init.d/rc.local` does the stop start stuff on `/etc/rc.local` (see my answer for more details). – goldilocks Dec 31 '12 at 14:37
-
@goldilocks: Thanks for a very descriptive and thorough answer but I am not clear which part of my answer you referred to be incorrect? Saying one as a service means it can do the "start" and "stop" stuff, while the other as simply a process. Please correct me if I am making no sense here. – pragmatic Dec 31 '12 at 19:58
-
2@pragmatic Because the `/etc/rc.local` script is the executable process governed by the `/etc/initd/rc.local` script, just like (eg) `/bin/syslog` would be the executable process governed by `/etc/initd/syslog`. You say explicitly that `/etc/rc.local` is just a boot script, vs. `/etc/initd/rc.local` being a completely separate run level service. – goldilocks Dec 31 '12 at 23:37