I have installed rbenv on an Ubuntu sever. I can cd into my application directory and run $ bundle without issue, however I need to run $ sudo bundle exec ... and this gets me an error:
bundle: command not found
Why is this and how can I fix it?
Not entirely sure, but maybe this would work for you:
sudo -i -u $USER bundle exec...
or
sudo -i -u username_with_correct_env bundle exec...
Dan Carley's rbenv-sudo looks like it will do what you want:
rbenv-sudo is a plugin for rbenv that allows you to run rbenv-provided Rubies and Gems from within a sudo session.
A more detailed explanation of how it works is provided in this article: Sudo Rbenv Me a Sandwich
Why you get the error has been addressed already. But I was able to get around it by saying:
sudo /full/path/to/bundle exec ...
In my case, I'm using rbenv, so I had to:
sudo /home/renier/.rbenv/shims/bundle exec ...
That worked. To get sudo to not ask for a password, you would need to configure your /etc/sudoers file for this. See https://serverfault.com/a/160587.
To do this without using rbenv or rvm, do this:
sudo -E bundle exec ...
-E The -E (preserve environment) option will override the env_reset option in sudoers(5). It is only available when
either the matching command has the SETENV tag or the setenv option is set in sudoers(5). sudo will return an error
if the -E option is specified and the user does not have permission to preserve the environment.
Related
So I try to do a backup of git. I have found this script (here:https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/raketasks/backup_restore.md)
But if I use this command it says that the command is not found. What am I doing wrong?
root#gitlab-test git/gitlab# sudo gitlab-rake gitlab:backup:create SKIP=db,uploads
sudo: gitlab-rake: command not found
Also I tried the command
sudo -u git -H bundle exec rake gitlab:backup:create RAILS_ENV=production
But with that the command stopped at upload.rb with a Errno::ENOENT: No such file or directory.
It depends where gitlab is installed.
For example:
PATH=$PATH:/opt/gitlab/bin
export PATH
Check if gitlab-rake is there in /opt/gitlab/bin.
There should be symlinks in /usr/bin.
If not, maybe you have installed GitLab from source (sudo -u git -H bundle exec rake)
I have an init.d script to start up god on my server after a reboot.
I've run sudo chmod +x /etc/init.d/god and sudo update-rc.d -f god defaults and when I run /etc/init.d/god start as the deploy user I have no issues and god starts.
However, when I reboot the server god doesn't start.
When I try and start god manually as root I get this error:
Your Ruby version is 1.9.3, but your Gemfile specified 2.3.0
I believe the issue is something to do with root not having rvm or ruby 2.3.0. Is there a way to run the init.d script as deploy?
I'm on Ubuntu 14.04, ruby 2.3.0 and god 0.13.7
You can run any command (or execute a script) as any user with the sudo command; just use the -u flag to specify the user. Example:
sudo -u deploy /etc/init.d/god
See more here: http://www.sudo.ws/man/1.8.15/sudo.man.html
I open an interactive shell into a docker container like so
sudo docker exec -t -i {container_name} bash
So far so good but trying to run nano results in:
Error opening terminal: unknown.
I think this can be related with Docker Issue #9299.
There are some workarounds commented in that issue:
Run the container allocating a pseudo-TTY (option -t).
Export environment variable $TERM=xterm in the container's process run in exec (i.e.: export TERM=xterm)
Run comand : export TERM=xterm
You can add
ENV TERM xterm
to your Dockerfile if you will use the editor regularly. We have that setting in our base container, since we're constantly debugging things with vi/emacs.
docker exec -it id_container bash
apt-get update
apt-get install nano
export TERM=xterm
as $TERM was already set to xterm but still not working for me, here is a way that worked: docker exec -it [CONTAINER_ID] /bin/bash -c "export TERM=xterm; exec bash"
Run this command in your container apk add nano
I did a workaround, in my .bashrc i have added:
alias nano='export TERM=xterm && nano'
In this case the error no longer appear
For me export TERM=xterm causes some display issues described here:
https://superuser.com/questions/1172222/issues-editing-files-with-nano-in-bash-windows-10
In that case export TERM=linux may works better.
I don't know if we are talking about the same thing but you need to make apt update | apt install nano so you can install it in the container.
We have a linux system that we do not have full control of. Basically we cannot modify sudoers file there (it is on a remote, read only file system).
Our "solution" for hudson user to have sudo privileges was to add this user to sudo group in /etc/group file. With this approach I can execute sudo as hudson user once I ssh to the machine. However, when I try to execute sudo from a Hudson job on this system, I get the following error:
+ id
uid=60000(hudson) gid=60000(hudson) groups=60000(hudson),31(sudo)
+ cat passfile
+ sudo -S -v
Sorry, user hudson may not run sudo on sc11136681.
+ cat passfile
+ sudo -S ls /root
hudson is not allowed to run sudo on sc11136681. This incident will be reported.
The above is trying to execute:
cat passfile | sudo -S -v
cat passfile | sudo -S ls /root
Why does it work when I ssh to the machine directly but does not when Hudson uses ssh? Is there a way to make sudo work in Hudson job without adding hudson user to the sudoers file?
Edit: here is output when executing sudo commands after I ssh to the system as hudson user:
[hudson#sc11136681 ~]$ cat passfile | sudo -S -v
[sudo] password for hudson: [hudson#sc11136681 ~]$
[hudson#sc11136681 ~]$
[hudson#sc11136681 ~]$ cat passfile | sudo -S ls /root
anaconda-ks.cfg install.log.syslog jaytest
install.log iscsi_pool_protocol_fields_file subnets
The solution to this problem that worked for us was to install local sudo on the system. Command used:
sudo yum reinstall sudo
Once installed, had to make sure the right sudo was used:
export PATH=/usr/bin:$PATH
The above can be added to slave configuration so it works for all jobs on that slave.
Here is what I am running:
rbenv sudo foreman export upstart /etc/init -a myapp -p 8080 -u myuser
What gets generated in ...web-1.conf
start on starting myapp-web
stop on stopping myapp-web
respawn
exec su - myuser -c 'cd /home/myuser/apps/myapp; export PORT=8080; bundle exec unicorn -p $PORT -c ./config/unicorn.rb >> /var/log/myapp/web-1.log 2>&1'
When I run tail -f /var/log/myapp/web-1.log, I see the following:
-su: bundle: command not found
It appears $PATH is being reset. If I manually cd into that directory, while running under myuser, I can execute the command just fine. Thoughts?
I am using foreman, rbenv, rbenv-sudo, unicorn, rails 4.0.0, and ruby 2.0.0-p247.
Thanks!
Okay, so I had my rbenv being configured in ~/.bashrc.
su - myuser -c is a login shell, but not an interactive shell.
I moved rbenv config to ~/.profile and everything seems to be working now.
Thanks!