About the Environment Variables and init in linux - linux

In linux, some program/process is created by the init, and also those process also need to set some Environment Variables.
I think, when the init start to run, the shell just don't started.
So, How can the init set the Environment Variables without a shell.

Environment variables can be exported from a process to its parent(s) then is then inherited to other children and grand children including the shell

Related

Environment for rc.local

I need to create an environment variable that is set within a bash script. I want this environment variable to be a system wide environment variable and I also want to be able to use it in an if condition in rc.local. So far I have tried /etc/profile but rc.local does not see it when I set it there.
Which script should I set this environment variable in so that rc.local can see it when I boot?
Other question while I’m at it. Who starts rc.local?
Cheers,
Dave
Rc.local runs before the operating system is fully booted but has not yet started the login shell, so the environment variables we configured in /etc/profiles or bashrc are not executed, so no environment variables are visible during the rc.local implementation phase.
The solution is:
Add export ENVNAME=*********** before the command in rc.local

Nodejs module oracled cannot find LD_LIBRARY_PATH

I'm getting the following error in my nodejs script using the oracledb module on a Centos 6 VM:
Error: libclntsh.so.11.1: cannot open shared object file: No such file or directory
We're using the full Oracle client. My google searches have led me to LD_LIBRARY_PATH being the problem. It is set in /etc/profile.d/ in an oracle script, and I can see it in my linux user's env output. But when I check process.env within the node script, LD_LIBRARY_PATH is simply not there. (If I add other variables to my /etc/profile.d script, those test variables appear in process.env)
The other weirdness is that when I run the script as root, the variable gets set properly and the script executes as expected.
So why is LD_LIBRARY_PATH disappearing when my non-root user runs the script?
You didn't explain how you are invoking the script. If you are sudo-ing, do you need to call a shell script that sets LD_LIBRARY_PATH before invoking node?

How to set up Environment java variable in Ubuntu bash?

I am trying to set up Java in my new laptop. I have installed java jdk and I am trying to set up the environment variable now, But I am really confused between the file .bash_profile, .bashrc, .profile. I understand the concept behind login and non login shells, but when I wrote the JAVA_HOME, PATH variable in .bash_profile I needed to manually run the command
. .bash_profile
It did not get executed at the start when I restarted the computer to make it run as .bash_profile is supposed to be called by login shells. Can anyone explain to me what is the reason behind .bash_profile not being called up?
Since .bash_profile was not being called, I decide to type the PATH, JAVA_HOME variable to the file .bashrc, While this is working is this the right way to set up environment variables?

why, when i restart the terminal the environment variables are restarted?

i do the next:
export M2_HOME=/usr/local/apache-maven/apache-maven-3.0.4
export M2=$M2_HOME/bin
export PATH=$M2:$PATH
then to verify that all is correct :
mvn -version
and it works but when i close the terminal and open other terminal the environment variables are erased
Because that's how variables work. You're setting them for that session. If you want them to persist, put them in your .profile so they're set each time a new instance of your shell starts.
A process inherits its environment variables from its parent, at the time it was started. If you want to set some environment variable for all new processes, edit ~/.profile or /etc/profile, which are read by the login shell.

IZPack Setting Linux Environment Variables

I am sure this has to be out there somewhere, but after about a day of searching I am stuck. I am trying to use IZPack to do an installation on Linux and trying to call a shell script that sets some environment variables. However I don't know how to "source" the script instead of just running it. Running the script using:
<executable type="bin" stage="postinstall" targetfile="$INSTALL_PATH/myscript.sh" os="unix"/>
This only executes the script, it does not source it. So all exports of ENV variables are lost once the script completes.
How can I source my scripts from IZPack instead of just running them?
IMHO you simply cannot influence the shell environment your Java process of your IzPack installer is running in from that process itself.
Torsten is right. This is not an issue of IzPack, Java or anything else, this is just the way operating system process work with respect to environment variables ;-)

Resources