Linux can not find gitlab-rake? - ruby-on-rails

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)

Related

How to run docker-compose as root user Docker Cloud

When I run as docker compose as ec2-user
[ec2-user#ip-15-0-52-106 $ docker-compose --version
docker-compose version 1.11.2, build dfed245
but as root user
[root#ip-15-0-52-106 ~]# docker-compose --version
-bash: docker-compose: command not found
I get command not found.
Any idea how to run it as a root user
Default location of docker-compose is /usr/local/bin/docker-compose but root does not contain path /usr/local/bin.
You can check is by following command:
[root#ip-172-31-40-117 ~]# echo $PATH
/sbin:/bin:/usr/sbin:/usr/bin:/opt/aws/bin
[ec2-user#ip-172-31-40-117 ~]$ echo $PATH
/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:
/opt/aws/bin:/home/ec2-user/.local/bin:/home/ec2-user/bin
You can add path for root, but it may not be a good way.(https://unix.stackexchange.com/questions/115129/why-does-root-not-have-usr-local-in-path)
[ec2-user#ip-172-31-40-117 ~]$ sudo su
[root#ip-172-31-40-117 ec2-user]# cd
[root#ip-172-31-40-117 ~]# vi .bash_profile
edit like this
export PATH=/usr/local/bin:$PATH
[root#ip-172-31-40-117 ~]# source .bash_profile
Or you can install docker-compose other path.

How I can directly login to rails console through ssh?

Time to time I repeat the following commands:
ssh username#servername
cd /projects/rails_project
bundle exec rails c production
I want to create a shell script, and make alias for this file for run production console in one line. If i wrote simple script whith this 3 command it is dosen't work.
How I can do it?
If you don't use ssh -t, the Rails console will not prompt you for input. What you actually want is:
ssh -t username#servername "cd/projects/rails_project && bundle exec rails c production"
Using -t " [...] can be used to execute arbitrary screen-based programs on a remote machine [...]" (according to the ssh man page.)
Just send it as an argument:
ssh username#servername 'cd /projects/rails_project && bundle exec rails c production'
From man ssh:
SYNOPSIS
ssh [options] [user#]hostname [command]
...
If command is specified, it is executed on the remote host instead of a
login shell.
...
When the user's identity has been accepted by the server, the server
either executes the given command in a non-interactive session or, if no
command has been specified, logs into the machine and gives the user a
normal shell as an interactive session. All communication with the remote
command or shell will be automatically encrypted.
To be more precise, if you use bash and have error of bundle command not found then you have set it before running bundle exec, like:
ssh -t <user>#<server> "cd /home/appfolder && /bin/bash --login bundle exec rails c -e production"

Starting god as deploy user

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

Foreman export upstart resetting $PATH

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!

Using $ sudo bundle exec ... raises 'bundle: command not found' error

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.

Resources