Openshift rhc ssh IO error after env set JAVA_OPTS_EXTcommand - ssh

I've run into an issue with openshift - after setting the environment variable over rhc env set JAVA_OPTS_EXT=" -D spring.profile.active=production" my ssh access broke down giving me weird access rights error. Some ideas here?

I don't know for what reason after setting a different value onto the JAVA_OPTS_EXT it locked me out of permissions. It was sufficient to unset the variable and set it again to a desired value. Everything started to work smoothly again afterwards.
A command to unset the environment variable: "rhc env unset {VARIABLE1} -a {APP_NAME}"
A command to set the environment variable: "rhc env set {VARIABLE1}={VALUE1} -a {APP_NAME}"
For further info about the manipulation of environmnet variables refer to https://developers.openshift.com/managing-your-applications/environment-variables.html

Related

Apache Airflow command not found with SSHOperator

I am trying to use the SSHOperator to SSH into a remote machine and run an external application through the command line. I have setup the SSH connection via the admin page.
This section of code is used to define the commands and the SSH connection to the external machine.
sshHook = SSHHook(ssh_conn_id='remote_comp')
command_1 ="""
cd /files/232-065/Rans
bash run.sh
"""
Where 'run.sh' runs the shell script:
#!/bin/sh
starccm+ -batch run_export.java Rans_Model.sim
Which simply runs the commercial software starccm+ with some options I have specified.
This section defines the task:
inlet_profile = SSHOperator(
task_id='inlet_profile',
ssh_hook=sshHook,
command=command_1
)
I have confirmed the SSH connection works by giving a simple 'ls' command and checking the output.
The error that I get is:
bash run.sh, error: run.sh: line 2: starccm+: command not found
The command in 'run.sh' works when I am logged into the machine (it does not require a GUI). This makes me think that there is a problem with the SSH session and it is not the same as the one that Apache Airflow logs into, but I am not sure how to solve this problem.
Does anyone have any experience with this?
There is no issue with SSH connection (at least from the error message). However, the issue is with starccm+ installation path.
Please check the installation path of starccm+ .
Check if the installation path is part of $PATH env variable
$ echo $PATH
If not, then install it in the standard locations like /bin or /usr/bin etc (provided they are included in $PATH variable), or export the installed director into PATH variable like this,
$ export PATH=$PATH:/<absolute_path>
It is not ideal but if you struggle with setting the path variable you can run starccm stating the full path like:
/directory/where/star/is/installed/starccm+ -batch run_export.java Rans_Model.sim

One liner ssh different enviroment variables than normal ssh

I am using AWS Beanstalk, in case it may be relevant to the question.
The issue that I have is that when I do from my local terminal:
ssh mozart-api printenv
I missing most of the enviroment variables, instead if I do:
ssh mozart-api
..wait to open..
printenv
I get all enviroment varibles as I was expecting.
At first I thought it could be an ssh configuration in server but can't find anything strange.
if I do:
ssh mozart-api "export hello=123 && echo $hello"
then it outputs 123, which means that variables can be set and queried, however I just cannot get the existing variables from the server.
This is causing an issue because I am preparing a script that will run a command in ssh on this server, but because the variables are not loaded the project fails to open the database.
I tried reimporting them in one liner:
ssh mozart-api "sudo chmod +777 /etc/profile.d/sh.local && (/opt/elasticbeanstalk/bin/get-config environment | jq -r 'keys[] as \$k | \"echo export \(\$k)=\(.[\$k])\"') > /etc/profile.d/sh.local && printenv"
But still can't see the new added variables.
ssh mozart-api executes a login shell, which probably sources one or more files that define your environment variables.
ssh mozart-api printenv executes printenv instead of a login shell, so the only variables you see are the ones you inherit from the parent process, not any of the variables defined in your shell configuration files.

Run Kubectl in apache

I have this bash script:
#!/bin/bash
USERNAME=$1
WORKDIR='dir_'$USERNAME
mkdir deployment/$WORKDIR
cat deployment/deploy.yml > deployment/$WORKDIR/deploy.yml
sed -i 's/alopezfu/'$USERNAME'/g' deployment/$WORKDIR/deploy.yml
kubectl apply -f deployment/$WORKDIR/deploy.yml
rm -rf deployment/$WORKDIR/
And i use exec funcition in PHP for run.
And i get this messege in /var/log/apache/error.log
To view or setup config directly use the 'config' command.
error: no configuration has been provided, try setting KUBERNETES_MASTER environment variable
error: Missing or incomplete configuration info. Please point to an existing, complete config file:
Via the command-line flag --kubeconfig
Via the KUBECONFIG environment variable
In your home directory as ~/.kube/config
I need help 🙏
Since you are running the script as a diferent user, you need to "tell" to kubectl where is the configuration file.
This can be done setting the variable KUBECONFIG in your environment.
Supposing the kubernetes config file is in the dir /var/www/ with the correct permission to be readable, you can configure your php script like this:
<?php
$kubeconfig = "/var/www/config"; // The config file
putenv("KUBECONFIG=$kubeconfig"); // set the environment variable KUBECONFIG
$output = shell_exec("KUBECONFIG=$kubeconfig ; kubectl get pods -A"); // Runs the command
echo "<pre>$output</pre>"; // and return the expected output.
?>
Please be aware that:
Setting certain environment variables may be a potential security breach.
Some actions that should mitigate the impacts:
Make sure your config file is safe and not reachable from the browser;
Consider to create a serviceAccount with limited permissions;
Here you can find some useful commands and kubectl tips.
How to create a service account for kubectl

gsettings changes are not working over ssh

I am trying to set the idle timeout for Ubuntu 14.04 using gsettings from ssh.
The commands I am using are like this
dbus-launch gsettings set org.gnome.desktop.session idle-delay 600
dbus-launch gsettings set org.gnome.desktop.screensaver lock-delay 0
dbus-launch gsettings set org.gnome.desktop.screensaver lock-enabled true
dbus-launch gsettings set org.gnome.desktop.screensaver idle-activation-enabled true
After the commands are executed with various timeout periods the changes are taking place, but those timeout changes are getting lost after a reboot or logout.
Is this possible to make the timeout change persistent on reboot/logout.
Basically, when you are launching a new dbus instance with dbus-launch, you are saving the configurations to the wrong location by kicking off a new dbus. While adding dbus-launch to the beginning of the gsettings invokation will remove any error messages, you will not save changes.
There exists for the target user an existing dbus process, and via ssh your terminal doesn't receive the correct environment variables with which to address it.
The correct way to edit gsettings via ssh is to first identify the DBUS_SESSION_BUS_ADDRESS of the existing dbus process and set it as an environment variable. Thus:
PID=$(pgrep gnome-session)
export DBUS_SESSION_BUS_ADDRESS=$(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$PID/environ)
# And now:
gsettings set org.gnome.desktop.session idle-delay 600
On Ubuntu 18.04 you have to set not only DBUS_SESSION_BUS_ADDRESS, but also XDG_RUNTIME_DIR. You can do so with this command (replace 121 with UID and gdm with user):
su gdm -s /bin/bash -c 'XDG_RUNTIME_DIR=/run/user/121 DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/121/bus gsettings get org.gnome.desktop.session idle-delay'

How do I set an environment variable?

In bash I can see npm environment variables with npm run env. USER=brianmackey is one such environment variable. How can I set an environment variable, say USER=billybob?
I know I can use npm config set <key> <value> [--global]. Is key+value always/in any case an environment variable? Can I set the environment variables in session?
Single Command
If you want to set environment variables for a single node command, you can simply do this:
$ USER=billybob node server.js
Loaded for each session
If you want to permanently set that environment variable for your user, edit your ~/.bash_profile and add the following line:
export USER="billybob"
This will automatically set the given environment variable each time you create a new terminal session.
Existing for the entire current session
Lastly, if you want to set the environment variable only for the current session, just run it as it's own command:
$ USER=billybob
$ node app.js # user is billybob
$ node app.js # user is still billybob
When you exit the session, these temporarily set environment variables will be cleared.