SlackwareThis Forum is for the discussion of Slackware Linux.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I'm using some scripts in /etc/profile.d to define JAVA_HOME among other things. I also have some rc scripts in /etc/rc.d, such as rc.tomcat and rc.pgsql that depend on environment settings in /etc/profile.d.
However, at startup the scripts in /etc/profile.d are apparently not sourced, as I see errors from rc.tomcat saying JAVA_HOME not defined, etc.
I added ". /etc/profile.d/jdk.sh" to rc.tomcat and it works fine.
Does anyone know why I have to do this? Is there a better way?
/etc/profile clearly sources the scripts in /etc/profile.d, and if I just log in as root and then start up my rc scripts, they are fine. My guess is that at bootup, it is not a login shell, but I'm really not that familiar with the process.
On a side note, when this happens, I can see the error message such as "JAVA_HOME not defined" on the screen, but it doesn't show up in dmesg or the systemlog. Is that normal? Is there an easy way to log these things?
/etc/profile and /etc/profile.d/* are accessed on login, not startup, so none of the values they set are in effect when you boot the box. What you've done isn't wrong in that it works although you can just add the environment variables to rc.tomcat. There's a similar thread to this here.
The "JAVA_HOME not defined" message being displayed on the screen and not the logs may be because it is sent to stdout instead of stderr (it's something I've never checked). The logger command can be used in your startup scripts to send output to syslog (man logger).
In a normal Slackware installation, the /etc/profile script will execute all executable scripts located in the /etc/profile.d directory.
A couple of things to easily overlook:
1. Ensure the script you created in /etc/profile.d is executable and readable (755 file permissions).
2. Ensure the script is tagged with the normal shell declaration at the beginning of the file (#!/bin/sh).
Sourcing and executing a script are not the same. Sourcing means that a script is run as though the external code is actually written into the calling script. Executing a script means that the script is run externally. Thus, sourcing a script (. /etc/profile.d/jdk.sh or source /etc/profile.d/jdk.sh) will set the environment variables you want and the script need not be tagged as executable or declared internally as a shell script. To be run externally as within /etc/profile or directly from the command line, then the jdk.sh script needs to be executable (chmod +x) and properly declared internally as a shell script (#!/bin/sh).
FWIW, generally, in Slackware, use the /etc/rc.d directory for running scripts to run services and the /etc/profile.d directory for running scripts to set global environment variables.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.