RHEL Environment Variable Path To Mongo Shell - bash

I have installed mongodb in one of our environments & this has been done using MongoDb Operations Manager. Though i have my PATH variable set correctly i'm unable to connect mongo shell with my user account but able to connect as a sudo. could someone help me if i'm missing anything here.
Details:
[user01#west.company.com#rhel01 /]$ echo $PATH
> /var/lib/mongodb-mms-automation/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/nfs/home/user01/.local/bin:/nfs/home/user01/bin
[user01#west.company.com#rhel01 /]$ mongo
> -bash: mongo: command not found
[user01#west.company.com#rhel01 /]$ sudo -i
[sudo] password for user01#west.company.com:
[root#rhel01 ~]# echo $PATH
> /var/lib/mongodb-mms-automation/bin:/usr/local/sbin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
[root#rhel01 ~]# mongo
> MongoDB shell
> version: 3.2.10 connecting to: test
> MongoDB Enterprise MYMONGOREPLSET01:PRIMARY>
Which Mongo Output:
[user01#west.company.com#rhel01 /]$ which mongo
/usr/bin/which: no mongo in (/var/lib/mongodb-mms-automation/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/nfs/home/user01/.local/bin:/nfs/home/user01/bin)
[root#rhel01 ~]# which mongo
/var/lib/mongodb-mms-automation/bin/mongo
Observation:
i just noticed the bin location is set like this ...
[root#rhel01 mongodb-mms-automation]# pwd
/var/lib/mongodb-mms-automation
[root#rhel01 mongodb-mms-automation]# ls -la
total 32
drwxr-xr-x 3 mongod mongod 4096 Mar 30 13:58 .
drwxr-xr-x. 57 root root 4096 Apr 1 03:23 ..
lrwxrwxrwx 1 mongod mongod 67 Nov 4 13:45 bin -> /var/lib/mongodb-mms-automation/mongodb-linux-x86_64-3.2.10-ent/bin
-rw------- 1 mongod mongod 1024 Mar 27 15:07 keyfile
-rw------- 1 mongod mongod 10686 Mar 30 13:58 mms-cluster-config-backup.json
drwxr-x--- 4 mongod mongod 4096 Nov 4 13:45 mongodb-linux-x86_64-3.2.10-ent

Try this
sudo chmod -R 777 /var/lib/mongodb-mms-automation/mongodb-linux-x86_64-3.2.10-ent/bin/

add this to path /var/lib/mongodb-mms-automation/mongodb-linux-x86_64-3.2.10-ent/bin

Related

Can't run Yarn on fish shell on MAC Ventura with nvm

in my MAC with Ventura os I can't run yarn on fish shell:
fish: Unknown command: yarn
I tried to run the following command according to the documentation:
set -U fish_user_paths (yarn global bin) $fish_user_paths
After running it, yarn works fine on fish shell.
However after reboot it stops working again.
I tried also to edit the config.fish file with:
if status is-interactive
# Commands to run in interactive sessions can go here
end
set -U fish_user_paths (yarn global bin) $fish_user_paths
But after reboot nothing changes...
In the variables I see:
fish_user_paths /Users/myusername/.yarn/bin
'/Users/myusername/.yarn/bin' '/usr/local/bin' '/System/Cryptexes/App/usr/bin' '/usr/bin' '/bin' '/usr/sbin' '/sbin'
However in the /Users/myusername/.yarn/bin path I see:
~/.y/bin> ls -la
total 0
drwxr-xr-x 3 myusername group 96 Feb 7 15:29 ./
drwxr-xr-x 3 myusername group 96 Feb 7 15:29 ../
lrwxr-xr-x 1 myusername group 59 Feb 7 15:29 create-next-app# -> ../../.config/yarn/global/node_modules/.bin/create-next-app
Can anyone please help?

Dockerfile failed to change user access

I want to run jenkins on docker and change the user access so could read the SSH key and access git.
Here is sample of the dockerfile
FROM jenkins/jenkins:lts
USER root
COPY --chown=jenkins:jenkins id_rsa $JENKINS_HOME/.ssh/id_rsa
COPY --chown=jenkins:jenkins id_rsa.pub $JENKINS_HOME/.ssh/id_rsa.pub
RUN /bin/bash -c 'ls -la $JENKINS_HOME/.ssh; chmod 600 -R $JENKINS_HOME/.ssh; ls -la $JENKINS_HOME/.ssh'
The output upon build is a success, access has been changed!
Step 3/3 : RUN /bin/bash -c 'ls -la $JENKINS_HOME/.ssh; chmod 600 -R $JENKINS_HOME/.ssh; ls -la $JENKINS_HOME/.ssh'
---> Running in 137d1a4f9f6d
total 16
drwxr-xr-x 2 jenkins jenkins 4096 Jan 8 04:11 .
drwxr-xr-x 3 jenkins jenkins 4096 Jan 8 04:11 ..
-rwxr-xr-x 1 jenkins jenkins 1843 Jan 2 02:33 id_rsa
-rwxr-xr-x 1 jenkins jenkins 413 Jan 2 02:33 id_rsa.pub
total 16
drw------- 2 jenkins jenkins 4096 Jan 8 04:11 .
drwxr-xr-x 3 jenkins jenkins 4096 Jan 8 04:11 ..
-rw------- 1 jenkins jenkins 1843 Jan 2 02:33 id_rsa
-rw------- 1 jenkins jenkins 413 Jan 2 02:33 id_rsa.pub
Removing intermediate container 137d1a4f9f6d
---> 7d6334d2b044
However when I go inside the /bin/bash the access is set to default, the chmod was not working
jenkins#f49048ec8c88:/$ ls -al /var/jenkins_home/.ssh/
total 16
drwxr-xr-x 2 jenkins jenkins 4096 Jan 8 04:25 .
drwxr-xr-x 16 jenkins jenkins 4096 Jan 8 04:26 ..
-rwxr-xr-x 1 jenkins jenkins 1843 Jan 2 02:33 id_rsa
-rwxr-xr-x 1 jenkins jenkins 413 Jan 2 02:33 id_rsa.pub
any idea why the behavior is this way?
This happened because $JENKINS_HOME is defined as VOLUME in jenkins:lts base image. You can workaround this in any of the 3 ways
You can fix the permissions on host machine before building and it should work.
You can use multi stage build, change the permission and copy files from first stage
FROM jenkins/jenkins:lts as base
USER root
COPY --chown=jenkins:jenkins id_rsa /tmp/ssh_keys/
COPY --chown=jenkins:jenkins id_rsa.pub /tmp/ssh_keys/
RUN chmod 600 -R /tmp/ssh_keys
FROM jenkins/jenkins:lts
USER root
COPY --chown=jenkins:jenkins --from=base /tmp/ssh_keys $JENKINS_HOME/.ssh
You can copy and change permissions of the files in a temporary directory as part of build. As part of your startup script(entrypoint), you can copy them from the temporary directory to actual directory.
Because the command /bin/bash is just for that session. If you want it to be permanent, put it inside .profile.

How can I ensure an application is correctly found on the path with Ubuntu SSH

Context
I have a shell script which is called from Jenkins remotely via SSH. If I SSH to the user account manually and then run the script it works. However, when Jenkins does this (same user account but executes command as an argument to the SSH command) it fails to find an application on the path.
Environment
lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 16.04.5 LTS
Release: 16.04
Codename: xenial
uname-a Linux 4.4.0-1066-aws #76-Ubuntu SMP Thu Aug 16 16:21:21 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
Contents of Home Directory
ls -la
total 76
drwxr-xr-x 7 app app 4096 Sep 3 07:49 .
drwxr-xr-x 4 root root 4096 Aug 19 14:31 ..
-rw------- 1 app app 12235 Sep 3 07:52 .bash_history
drwx------ 3 app app 4096 Aug 28 17:06 .cache
drwx------ 2 app app 4096 Aug 22 16:07 .docker
-rw-rw-r-- 1 app app 6064 Sep 1 15:19 docker-compose.yml
drwx------ 4 app app 4096 Aug 22 14:37 .local
drwxrwxr-x 2 app app 4096 Aug 28 17:15 .nano
-rw-rw-r-- 1 app app 97 Aug 22 16:00 .profile
-rwxrw-r-- 1 app app 177 Aug 28 07:45 run-all-apps.sh
-rwxrw-r-- 1 app app 476 Aug 28 07:45 run-apps.sh
-rw-rw-r-- 1 app app 66 Aug 28 17:15 .selected_editor
drwx------ 2 app app 4096 Sep 3 07:49 .ssh
-rw------- 1 app app 10496 Sep 3 07:49 .viminfo
Contents of .profile:
cat .profile
# set PATH so it includes user's private bin directories
PATH="$HOME/bin:$HOME/.local/bin:$PATH"
Contents Of Failing Script
cat ./run-apps.sh
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
# Authenticate for ECR
eval $(aws ecr get-login --region eu-west-1 --no-include-email)
How The Script Is Run
In a Jenkinsfile we have this:
sshagent(credentials: ['server-ssh']) {
sh "ssh -o StrictHostKeyChecking=no -p 22 -l app ${ENVIRONMENT_HOST_NAME} './run-apps.sh'"
}
Observed Result Of Running The Script
./run-apps.sh: line 12: aws: command not found
Other Information
If I SSH to the server using the same user that Jenkins uses I can run the AWS CLI:
whoami
app
and
which aws
/home/app/.local/bin/aws
finally:
aws --version
aws-cli/1.15.83 Python/2.7.12 Linux/4.4.0-1066-aws botocore/1.10.82
Is this perhaps something to do with the use of eval and the environment not being propagated or something, e.g. the .profile isn't run and therefore the application isn't on the path.

How is this $PATH being set to ruby for new user?

I've been toying with chef, and may have installed ruby along the way. Now I would like to upgrade to ruby 2.0. Anyhow I'm curious what could have caused ruby to be added to the path of all new users? Note: there's no mention of ruby in the new user's .bashrc, .profile, or in the global /etc/environment:
ubuntu#ip-10-10-10-10:~$ sudo useradd -m testuser
ubuntu#ip-10-10-10-10:~$ sudo su - testuser
testuser#ip-10-10-10-10:~$ ls -la
total 20
drwxr-xr-x 2 testuser testuser 4096 Mar 23 02:54 .
drwxr-xr-x 5 root root 4096 Mar 23 02:54 ..
-rw-r--r-- 1 testuser testuser 220 Apr 9 2014 .bash_logout
-rw-r--r-- 1 testuser testuser 3637 Apr 9 2014 .bashrc
-rw-r--r-- 1 testuser testuser 675 Apr 9 2014 .profile
testuser#ip-10-10-10-10:~$ echo $PATH
/home/testuser/.gem/ruby/1.9.3/bin:/opt/rubies/1.9.3-p429/lib/ruby/gems/1.9.1/bin:/opt/rubies/1.9.3-p429/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
testuser#ip-10-10-10-10:~$ ruby --version
ruby 1.9.3p429 (2013-05-15 revision 40747) [x86_64-linux]
testuser#ip-10-10-10-10:~$ which ruby
/opt/rubies/1.9.3-p429/bin/ruby
testuser#ip-10-10-10-10:~$
I'm at a loss as to where to look to find and remove the references to ruby 1.9.3 being added apparently automatically.
I faced similar issue. Please try with this option dpkg --get-selections.
As you might be knowing everything is considered as gems. Hence try with this also if above does not work...
$ gem -h
or
$rvm list known
and then you can install only the required version using
rvm install ruby 2.0.0-p247
REFERNCE:- http://www.ruby-lang.org/en/downloads/
Turns out somewhere along the way, somehow, chruby got installed. The quick fix to resolve the user PATH not being overwritten was to disable the .sh chruby put in /etc/profile.d:
ubuntu#ip-10-10-10-10:/etc/profile.d$ ls -l
total 16
-rw-r--r-- 1 root root 663 Aug 19 2015 bash_completion.sh
-rw-r--r-- 1 root root 147 Mar 21 00:58 chruby.sh
-rw-r--r-- 1 root root 1559 Jul 29 2014 Z97-byobu.sh
-rwxr-xr-x 1 root root 2691 Nov 23 18:41 Z99-cloud-locale-test.sh
ubuntu#ip-10-10-10-10:/etc/profile.d$ sudo mv chruby.sh chruby.sh.disabled
ubuntu#ip-10-10-10-10:/etc/profile.d$ ls
bash_completion.sh chruby.sh.disabled Z97-byobu.sh Z99-cloud-locale-test.sh
ubuntu#ip-10-10-10-10:/etc/profile.d$ sudo su - testuser
testuser#ip-10-10-10-10:~$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
Better would be to uninstall chruby, but it's not obvious to me how to do that given I don't know / don't remember how it was installed.

Can't start MongoDB on OSX

I'm trying to run MongoDB on OSX and encountering a common problem, Error with exit code 1.
Here's my very simple mongod.conf:
systemLog:
destination: file
logAppend: true
path: ~/Documents/test/mongodb/mongodb.log
storage:
directoryPerDB: true
dbPath: ~/Documents/test/mongodb/mongodb_data
journal:
enabled: true
processManagement:
fork: true # fork and run in background
net:
port: 27017
I 777'd all the folders so there's no way it can be a permissions issue (right? :P)
mac$ ls -lah ~/Documents/test/mongodb/
total 8
drwxr-xr-x 5 mac staff 170B Dec 4 15:34 .
drwxr-xr-x 11 mac staff 374B Dec 4 15:19 ..
-rwxrwxrwx 1 mac staff 301B Dec 4 15:21 mongod.conf
-rwxrwxrwx 1 mac staff 0B Dec 4 15:21 mongodb.log
drwxrwxrwx 2 mac staff 68B Dec 4 15:18 mongodb_data
But it still gets this error code!
mac$ sudo mongod -f ~/Documents/test/mongodb/mongod.conf
about to fork child process, waiting until server is ready for connections.
forked process: 70062
ERROR: child process failed, exited with error number 1
Things I've tried from other questions:
Apparently I shouldn't have to run this as sudo (?), I've tried both sudo and no sudo, same result
Could be a permissions issue (Starting mongod fails unless run as root) - well the mongodb_data directory and the conf and log are all 777 so can that really be the case? I've tried chown on all of them too but no effect.
Remove the pid location in your mongod.conf (done, doesn't have any effect) Starting mongod fork, ERROR: child process failed, exited with error number 1
Also:
mongodb.log has nothing in it after multiple start attempts
mongodb_data/ has nothing in it either (no .lock file or whatever, just empty)
Any ideas?
This is probably error with log file. It's strange that yours is 0 bytes.
Anyway you do not need to make 777 permissions, you do not need to run mongod with sudo on OSX system.
Try to do the following:
mkdir ~/sometest
cd ~/sometest
cp ~/Documents/test/mongodb/mongod.conf .
Replace systemLog path to mongodb.log, replace dbpath to data
mkdir data
Start mongod (mongod -f mongod.conf)

Resources