Does rc.local execute its commands after we login?
Since rc.local executes its commands after the multi user runlevel completes, does it also mean that we can/should set LIB paths in it instead of setting them in .bashrc?
- 401
- 3
- 8
- 21
1 Answers
The script /etc/rc.local is invoked at the end of normal system startup. It is executed as root and has no relationship whatsoever with a user logging in. Any environment variable assignments in /etc/rc.local are available only to the processes started by /etc/rc.local; they are not available to processes started in a user's login session.
/etc/rc.local has no direct effect on a user's login session. It is normally used to mount some disks, start some services and other such tasks. It cannot be used to set up a user's environment.
First, let's look into /etc/rc.local itself:
$ cat /etc/rc.local
#!/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
rc.local is an old feature of Unix-like system, older even than the System V initialization system (the one which used the directories /etc/rc[0-6S].d). Recent Ubuntu systems used systemd to control initialization; /etc/rc.local is invoked by the systemd unit rc-local.service:
$ sudo systemctl status rc-local
● rc-local.service - /etc/rc.local Compatibility
Loaded: loaded (/lib/systemd/system/rc-local.service; static; vendor preset: enabled)
Drop-In: /lib/systemd/system/rc-local.service.d
└─debian.conf
Active: active (exited) since Fri 2017-04-28 17:44:18 EEST; 2 days ago
Apr 28 17:44:18 factissa systemd[1]: Starting /etc/rc.local Compatibility...
Apr 28 17:44:18 factissa systemd[1]: Started /etc/rc.local Compatibility.
The unit is automatically generated at boot if the file /etc/rc.local exists, and is set by default to be invoked after achieving network.target; on Debian and derivatives such as Ubuntu, a drop-in configuration file modifies this so that the unit is run after network-online.target.
This is not exactly the same as the traditional place of /etc/rc.local at the end of a multi-user runlevel initialization, but it's similar enough so that in most cases no adjustments need to be done. (Look into those files, they are text and quite understandable; to make modifications please read the systemd documentation first.)
- 401
- 3
- 8
- 21
- 10,435