Using RVM from within a service context

Paul D'Ambra

I have a user set up on Ubuntu 14.

If I check when logged in as the user

build@linux-build-agent-1:~$ type rvm | head -1
rvm is a function

However, this machine is going to be a teamcity agent...

When a job is run in the context of the teamcity service we see

[13:19:11][Step 1/1] RVM is not a function, selecting rubies with 'rvm use ...' will not work.
[13:19:11][Step 1/1] 
[13:19:11][Step 1/1] You need to change your terminal emulator preferences to allow login shell.
[13:19:11][Step 1/1] Sometimes it is required to use `/bin/bash --login` as the command.
[13:19:11][Step 1/1] Please visit https://rvm.io/integration/gnome-terminal/ for an example.

I've tried several commands trying to force the service to run in a login shell

su - build -c 'source "$HOME/.rvm/scripts/rvm" && /home/build/buildAgent/bin/agent.sh start'


sudo -u build -i bash -lc '/home/build/buildAgent/bin/agent.sh start'
su - build -c '/home/build/buildAgent/bin/agent.sh start'

within the /etc/init.d/ script with no effect.

If I run source "$HOME/.rvm/scripts/rvm at the head of the script in teamcity then everything is OK but there are multiple users and I can't ask them all to remember to do that.

Is this how I've installed RVM or..?


To clarify:

1) when I'm logged in as the user over SSH rvm is installed correctly and functions as expected. As shown by type rvm | head -1 => 'rvm is a function' 2) when a service logs in as the user rvm is not working correctly.

I want rvm to work when running in the context of the service so that users don't have to explicitly source "$HOME/.rvm/scripts/rvm in their build scripts

Typically this issue is caused by not running as a login shell. So I need to know either how to run a service as a login shell. Or how to fangle rvm so that it can work outside of the login shell context

terdon

When you run su - build -c foo.sh, you are starting a login shell, which then launches foo.sh. The script foo.sh, however, is running in its own subshell (that's how scripts work) and the type of that shell depends on the shebang line of the script. So, su - -c foo.sh is not making foo.sh run in a login shell, it is just running a login shell which then launches foo.sh.

So, edit /home/build/buildAgent/bin/agent.sh and change this:

#!/bin/sh

to this:

#!/bin/sh -l

That will make it run in a login shell and should cause it to read the /etc/profile, and ~/.profile files and bring in your function. Please note that ~/.bash_profile is not relevant here. This is a file that is only read by bash, and not sh which, on Ubuntu, is actually dash.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Passing context from Service to AsyncTask without leaking it

Spring context from within a jar file

Using context beans within a Condition or a ConfigurationCondition

Is it good practice to yield from within a context manager?

AngularJS: Using "this" in an interval function within a service

Seeing if a request succeeds from within a service worker

Read cookies from within a Service Worker?

How to test response from service within controller

Dynamic injection of service (from within the controller)

bad_weak_ptr while using class inheriting from boost::asio::io_context::service

using context and a hook within

How to access Flask app's context from within embedded Dash app when using app factory pattern?

Using context of a fragment within its innerclass in Kotlin

Unable to resolve cache service from within ViewComponent

Reset context from helper service

Can not access ingress service from within cluster

Using Context inside aidl service implementation

Using a service during context initaliatizon

Using string from context outside of context

Using a shared service within a class

Symfony: Load resources into the Translator from within a Service

Calling secure ServiceStack service from within

AngularJS, using a promise within a service

Bad context binding within service

Send SMS from within a service

Subscribing to an observable from within a service vs from within a component

Impersonate and run any method using a logged in user context from SYSTEM level process (Windows Service):

Can access clusterip service from within cluster but not by using kubectl proxy

Data not returning from service to context when using promises