Environment variables not set on headless server

I recently moved my Openhab-installation to a new, headless server. Everything works fine, despite using the karaf console, as the environment variables are set using profile.d, which is never executed on headless systems.

I installed the latest snapshot release via apt. The installation was done as root, openhab is running as openhab, I try to access the karaf console as another user via SSH.

What is the best practice to execute the content of profile.d at boot? Would it be better to run it at each SSH login?

profile.d for environment variables: https://github.com/openhab/openhab-linuxpkg/pull/68/files
Problems before introducing it: Karaf connection refused
profile.d on headless servers: https://unix.stackexchange.com/questions/152282/profile-d-on-headless-server

profile.d is sourced when ever you log in with bash as your shell, even when logging in over ssh. That has nothing to do with running headless. There must be something else going on.

unless you have changed the karaf config, you must log into the karaf console using the user openhab2 on port 1801 (I think).

you don’t. profile.d contains environment variables and aliases and config for your running interactive bash shell. when your machine boots there are no interactive bash shell running.

yes and if your default shell is bash, it will be sourced when you login over ssh automatically.

but I don’t think environment variables are your problem. there are none that need to be set to log into the karaf console.

To clarify further, the environment variables will be available to you when you log in to the server via SSH as @rlkoshak says.

The profile.d script isn’t executed when leaving the server to run by itself, the service file gets these variables from other means. That is to say, the profile.d script is for your visual benefit only, and you’ll never actually need these to log in to the console.

There are two ways of connecting to the Karaf console. The first is using an in-built command from openHAB, since you installed via APT you can use the command:

openhab-cli console

(Which is a shortcut to include the environment variables into your script). The second is using an SSH client:

ssh -p 8101 openhab@localhost

In either case the password by default is “habopen”.

Thank you both for answering! Logging in works

  • via manually setting the env variables and then running /usr/share/openhab2/runtime/bin/client
  • running openhab-cli console
  • running ssh -p 8101 openhab@localhost

Thank you, Benjy for giving the two least methods!

I just assumed, that not setting those env vars using profile.d was somehow related to me switching to a headless server. I don’t know why profile.d isn’t executed even when logging in via SSH. I will just stick with openhab-cli console from now on - it is easier to remember anyhow!

1 Like

No problem, I must admit that is strange to have this problem on a headless machine. What Linux distribution/OS are you using?

I’m using Ubuntu 16.04.03 LTS in server flavour.