Shell api and using yum

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Shell api and using yum

rantav
My applications reside in a yum repository so I'd like to try and use glu's agent to run a "yum install" command.
What would be the best way to do so?

Just playing around, I figured I might just search for a way to execute linux command and hopefully try a "sudo yum install xxx" and hope it'd work.
Alternatively, if that doesn't work then maybe "ssh -t root@localhost 'yum install xxx'" and maybe I need to share a key before that or something and hopefully that would work... if not I'm at a dead end...
If that's just rubbish then what's the recommended way of doing a yum install with the agent?
I like to be able to use yum b/c it's self contained, has versions and can also be run independently of glu.

I started looking at the shell api and I was a bit confused. The wiki (here https://github.com/linkedin/glu/wiki/Agent) says that there are a number of Shell methods such as fetch, ls, mv, exec etc. I wanted to check out what kind of arguments they expect so I ended up looking at Shell.groovy which surprisingly only has one method, fetch (https://github.com/linkedin/glu/blob/master/agent/org.linkedin.glu.agent-api/src/main/groovy/org/linkedin/glu/agent/api/Shell.groovy)
The impl class OTOH has a few more methods such as exec() and others https://github.com/linkedin/glu/blob/master/agent/org.linkedin.glu.agent-impl/src/main/groovy/org/linkedin/glu/agent/impl/capabilities/ShellImpl.groovy

Are the missing methods from the interface Shell.groovy just an oversight?
I've never coded a line of groovy in my life so I apologize if the questions are dumb...

And the real question was - what's the proper way of telling the agent to yum install a thing (my app)?

Thanks
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Shell api and using yum

frenchyan
Administrator
Hi Ran

Yes it is an oversight. You get an instance of ShellImpl in the glu script so it works. I had so many things to do for the open source release that I never copied the methods in the interface. I created an issue to keep track of it: https://github.com/linkedin/glu/issues/issue/5

Regarding your question, I am not familiar with how 'yum' works exactly. To execute any command you want from the glu script you simply do:

String output = shell.exec("ls -la /tmp")
log.info "ouput from command = ${output}"

So I assume in your case you may want to execute something like:

shell.exec("yum install ${params.yumPackageName}")

(if you want to provide the argument as an init parameters).

In terms of security/privileges, under the cover it simply uses java/forking capabilities, so the yum command will execute with the same security/privileges the agent process was started as.

The key 2 points here are:
* you can execute any command you want (shell.exec("any command you want"))
* it will be executed with the same security/privileges the agent process was started as

It is not recommended to start the agent as root, but if your network is secure then that may be a solution for you.

Thanks
Yan
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Shell api and using yum

rantav
Thanks Yan, I was able to pull this out.
1. I run the agent as root (required by yum)
2. In the install phase I execute: shell.exec("yum install -y ImageServer");

Related question, this also works for me:
String output = "yum install -y ImageServer").execute().text.
Is shell.exec just a thin wrapper around this sort of command or does it add more goodness? Which of the two approaches is recommended?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Shell api and using yum

frenchyan
Administrator
I am really glad to hear that you were able to make it work.

The shell.exec command does more (https://github.com/linkedin/glu/blob/master/agent/org.linkedin.glu.agent-impl/src/main/groovy/org/linkedin/glu/agent/impl/capabilities/ShellImpl.groovy) @ line 670 and 726 like checking for error (if the command does not return 0 then it throws an exception) and also issuing bash -c xxx (which in my experience works better than executing the command directly especially with complex command line options)

So I would recommend shell.exec :)

Yan
Loading...