/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.
You're C executable probably requires some environment variables to be set to function. For example the env. variable $PATH
or $LD_LIBRARY_PATH
. There also other variables such as $HOME
which won't be set until a user has logged in.
This last one might be necessary for your app to access config files and/or log files, for example.
Best Answer
A runlevel is a state of the system, indicating whether it is in the process of booting or rebooting or shutting down, or in single-user mode, or running normally. The traditional init program handles these actions by switching to the corresponding runlevel. Under Linux, the runlevels are by convention:
Runlevels 2 through 5 are known as multiuser runlevels since they allow multiple users to log in, unlike runlevel 1 which is intended for only the system administrator.
When the runlevel changes, init runs rc scripts (on systems with a traditional init — there are alternatives, such as Upstart and Systemd). These rc scripts typically start and stop system services, and are provided by the distribution.
The script
/etc/rc.local
is for use by the system administrator. It is traditionally executed after all the normal system services are started, at the end of the process of switching to a multiuser runlevel. You might use it to start a custom service, for example a server that's installed in/usr/local
. Most installations don't need/etc/rc.local
, it's provided for the minority of cases where it's needed.