Guard complaints about running outside of Bundler, but only on 2nd terminal window onwards - ruby-on-rails-3

I am following Michael Hartl's tutorial and ran this 2 blocks of code
$ rvm get head && rvm reload
$ chmod +x $rvm_path/hooks/after_cd_bundler
$ cd ~/rails_projects/sample_app
$ bundle install --without production --binstubs=./bundler_stubs
now when I run Guard on my first terminal window everything is fine, but when I open another terminal window and run the exact same command, it complaints that I am running Guard outside of Bundler. Why is that so?
Still can't post images but here is the screenshot of the 2 separate terminal windows
terminal 1
terminal 2
Thanks!
Ryan

tests
rvm current - is the proper ruby selected
echo $PATH - first position should be path to .../bundler_stubs
solutions
for both errors it might work again with cd . - but this might be problematic
you need to make sure that RVM was loaded properly, and that proper ruby was loaded in session:
make sure you use gnome-terminal with login session enabled: https://rvm.beginrescueend.com/integration/gnome-terminal/
run rvm get head --auto - keep a gist of it in case
restart your computer - it's required in some cases
make sure you do not overwrite PATH after RVM was loaded in your RC scripts

Related

Problems getting Singularity Compose to work

I wrote a small test project for Singularity Compose, consisting of a small server application, with the following YAML file:
version: "1.0"
instances:
server:
build:
context: ./server
recipe: server.recipe
ports:
- 9999:9999
When I call singularity-compose build, it successfully builds server.sif. Calling singularity-compose up also seemingly works without error, and calling singularity-compose ps results in something that looks just fine:
+ singularity-compose ps
INSTANCES NAME PID IMAGE
1 server 4176911 server.sif
However, the server application does not work, calling my test client results in it saying that there is no answer from the server.
But if I run server.sif directly without compose, everything works just fine.
Also, I tripple checked, my test application listens to port 9999, thus should be reachable from the outside.
What did I do wrong?
Edit:
I also checked whether there actually is any process listening at port 9999 by calling sudo lsof -i -P -n | grep LISTEN, this is not the case. Only when I manually start server.sif without compose it shows me the process listening.
Edit:
I went into the Singularity Compose shell and tried to start the Server application directly in there, just as a test, and it resulted in Permission denied. Not sure if that means anything.
Edit:
I now gave the application execution rights within the shell and called in there, this works. Am now trying to add execution rights in the recipe. If that works, it would be kind of strange, as the executable was build right there, and thus should already have execution rights.
Edit:
I added chmod +x in my recipe both after building Server and before executing it. Doesn't work either.
Also checked whether any bridges exist using brctl show, this is not the case.
Edit: My recipe, adjusted by the input of tsnowlan in his answer below:
Bootstrap: docker
From: ubuntu:20.04
%files
connection.cpp
connection.h
main.cpp
server.cpp
server.h
server.pro
%post
# get some basics
apt update
apt-get install -y wget
apt-get install -y software-properties-common
# get C++ compiler
apt-get install -y g++
apt-get install -y build-essential
apt-get install -y build-essential cmake
# get Qt
apt-get install -y qt5-default
# compile
qmake
make
ls
%runscript
/Server
%startscript
/Server
Again, note that the application works just fine both when compiled and startet normally and when started within a Singularity image (but without Singularity Compose).
The ls at the end of the %post block is used to verify that the Server application was build successfully.
Please share the server.recipe, as it is difficult to identify should be/is happening without it.
Without having that, my guess is that you have a %runscript in your definition file, but no %startscript. When the image is executed directly or via singularity run image.sif, the contents of %runscript determine what happens. To emulate the docker-compose style, the singularity images are started as persistent instances. In this case, the %startscript block determines what runs. If it is empty, it will just start up and sit there doing nothing. This would explain why when run by hand it works but not when using compose.

"docker run -dti" with a dumb terminal

updated: added the missing docker attach.
Hi am trying to run a docker container, with -dti. but I cannot access with a terminal set to dumb. is there a way to change this (it is currently set to xterm, even though my ssh client is dumb)
example:
create the container
docker run -dti --name test -v /my-folder alpine /bin/ash
docker attach test
apk --update add nodejs
cd /my-folder
npm install -g gulp
the last command always contains ascii escape chars to move the cursor.
I have tried "export TERM=dumb" inside the running container, but it does not work.
is there a way to "run" this using the dumb terminal?
I am running this from a script on another computer, via (dumb) ssh.
using the -t which sets this https://docs.docker.com/engine/reference/run/#env-environment-variables, however removing effects the command prompt (the prompt is not shown)
possible solution 1 remove the -t and keep the -i. To see if the command has completed echo out a known token (ENDENDEND). ie
docker run -di --name test -v /my-folder alpine /bin/ash
docker attach test
apk --update add nodejs;echo ENDENDEND
cd /my-folder;echo ENDENDEND
npm install -g gulp;echo ENDENDEND
not pretty, but it works (there is no ascii in the results)
Possible solution 2 use the journal, docker can log out to the linux journal, this can be gathered as commands are executed in the container. (I have yet to fully test this one out. however the log seems to be a nicer output of what happened)
update:
Yep -t is the problem.
However if you want to see the entire process when running a command, maybe this way is better:
docker run -di --name test -v/my-folder alpine /bin/ash
docker exec -it test /bin/ash
finally you need to kill the container after all jobs finished.
docker run -d means "Run container in background and print container ID"
not start the container as a daemon
I was hitting this issue on OSx running docker, i had to do 2 things to stop the terminal/ascii/ansi escape sequences.
remove the "t" option on the docker run command (from docker run -it ... to docker run -i...)
ensure to force bash or sh shells used on osx when running the command from a script file, not the default zsh
Also
the escape sequences were not always visible on the terminal
even so, they still usually caused content corruption, even with SED brought to bear
they always were shown in my editor

Deploy rails application after git push

I want to deploy my application on remote test server using capistrano gem.
Both git and rails should run on same server.
I have 2 users 'git' for git repositories and 'rails' with installed rvm. After git push i want to execute hook post-receive which runs su rails and then cap deploy.
When i tried push i got message:
remote: su: must be run from a terminal
How can i work around this message. Can i enable tty some way over git ssh connection?
I can give up from capistrano for this case but still i want rvm and rails to be used only by user rails (so su probably have to be used in each case).
edit
Now i walk around problem. Probably this is very bad solution but works ;). From bellow script's i removed original paths and echo's.
post-receive hook before walkaround
#!/bin/bash
while read oldrev newrev ref
do
su rails #here script fails
cd /path/to/rails/app/current/ && cap deploy
done
post-recive now
#!/bin/bash
while read oldrev newrev ref
do
ssh rails#localhost '/path/to/scripts/deploy.sh'
done
deploy.sh script
#!/bin/bash
CAP_DIR="/path/to/capistrano/dir"
RUBY="1.9.3-p194"
GEMSET="gemset_name"
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"
rvm use $RUBY
rvm gemset use $GEMSET
cd $CAP_DIR
cap deploy

Passenger module fails to install

On Mac OSX 10.8.4, I'm running:
sudo passenger-install-apache2-module
which suggested:
Your RVM wrapper scripts are too old, or some wrapper scripts are missing. Please update/regenerate them first by running:
rvmsudo rvm get stable && rvm reload && rvmsudo rvm repair all
If that doesn't seem to work, please run:
rvmsudo rvm wrapper [] --no-prefix --all
I did the first bit, re-ran the passenger-install-apache2-module but got the same problem. Then I did the second part. This gave:
awk: nonterminated character class ^[]=
source line number 1
context is
>>> /^[]=/ <<<
sed: 1: "s#^[]=##
": unbalanced brackets ([])
Unknown ruby interpreter string component: '[]'.
Could not load ruby [].
Any suggestions on where I go from here?
just run passenger-install-apache2-module do not prefix it with sudo.
the command will tell you what to do if it has no write access into required locations.
using sudo losses all environment variables - which basically breaks what rvm set up.
if you would really need root privileges you should use rvmsudo which does preserve all required environment variables.

Updating files after RVM install

I have installed RVM enroute to updating and running different ruby and rails. After install I received message to update shell's loading files.
1) Place the folowing line at the end of your shell's loading files
(.bashrc or .bash_profile for bash and .zshrc for zsh),
after all PATH/variable settings:
[[ -s "/Users/eric/.rvm/scripts/rvm" ]] && source "/Users/eric/.rvm/scripts/rvm" # This loads RVM into a shell session.
You only need to add this line the first time you install rvm.
I typed [[ -s "/Users/eric/.rvm/scripts/rvm" ]] && source "/Users/eric/.rvm/scripts/rvm"
and hit enter. Does this update my files? Or do I have to open some type of file and cut and paste code?
Since I did not see any notice as stated below from part 2 of the post install, I closed the shell and opened a new one. but the RVM command does not seem to work. Part 2 of the instructions post install was:
2) Ensure that there is no 'return' from inside the ~/.bashrc file,
otherwise rvm may be prevented from working properly.
This means that if you see something like:
'[ -z "$PS1" ] && return'
then you change this line to:
if [[ -n "$PS1" ]] ; then
# ... original content that was below the '&& return' line ...
fi # <= be sure to close the if at the end of the .bashrc.
# This is a good place to source rvm v v v
[[ -s "/Users/eric/.rvm/scripts/rvm" ]] && source "/Users/eric/.rvm/scripts/rvm" # This loads RVM into a shell session.
EOF - This marks the end of the .bashrc file
Be absolutely *sure* to REMOVE the '&& return'.
If you wish to DRY up your config you can 'source ~/.bashrc' at the bottom of your .bash_profile.
Placing all non-interactive (non login) items in the .bashrc,
including the 'source' line above and any environment settings.
Thanks for the help as I am very new and trying to learn RoR but so far have not been able to get past the setup in many of the tutorials I've attempted. It seems many [
1 2 are out of date with new software or I get error messages before I can even attempt to learn the code. If someone knows of a good beginner tutorial that would be great. Thanks again!
The snippet that the installer gives you need to go in a file called the bashrc. The file lives in your home directory: /Users/eric/.bashrc
You need to edit this file and add the line from rvm and then you should be good to go.
As for getting rolling with rails I'd recommend The Pragmatic Programmers book on rails. You can find their books at pragprog.com
If you're on Ubuntu, my tutorial on setting rvm will get you roll all the way up to rails installation:
http://blog.dcxn.com/2011/06/20/setting-up-rvm-on-ubuntu-11-04/