Camel-exec issue (script works but returns 1 inside a route)

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Camel-exec issue (script works but returns 1 inside a route)

Gerald Kallas - mailbox.org
Hi all,

I've the following script (inside the container)

-rwxr-xr-x 1 casisp casisp 103 May 22 22:58 user-add

/opt/apache-karaf/bin/client "jaas:realm-manage --index 1; jaas:user-add user1 password1; jaas:update"

When I'm calling it from the command line directly it works.

Inside a route (see below) it returns an exit code 1. Any thoughts about this?

<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0
           https://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">

        <camelContext xmlns="http://camel.apache.org/schema/blueprint">

                <route>
                        <from uri="timer:exec?repeatCount=1" />
                        <setHeader name="CamelExecCommandExecutable">
                                <constant>/opt/apache-karaf/bin/user-add</constant>
                        </setHeader>
                        <to uri="exec://dummy-target" />
                        <log message="headers: ${in.headers}" />
                </route>

        </camelContext>

</blueprint>

2020-05-23T05:28:44,039 | INFO  | Blueprint Event Dispatcher: 1 | AbstractCamelContext             | 94 - org.apache.camel.camel-base - 3.3.0 | Route: route37 started and consuming from: timer://exec
2020-05-23T05:28:44,067 | INFO  | Blueprint Event Dispatcher: 1 | AbstractCamelContext             | 94 - org.apache.camel.camel-base - 3.3.0 | Total 1 routes, of which 1 are started
2020-05-23T05:28:44,068 | INFO  | Blueprint Event Dispatcher: 1 | AbstractCamelContext             | 94 - org.apache.camel.camel-base - 3.3.0 | Apache Camel 3.3.0 (CamelContext: camel-35) started in 0.223 seconds
2020-05-23T05:28:44,088 | INFO  | fileinstall-/opt/apache-karaf-4.2.8/deploy | fileinstall                      | 10 - org.apache.felix.fileinstall - 3.6.4 | Started bundle: blueprint:file:/opt/apache-karaf-4.2.8/deploy/exec.xml
2020-05-23T05:28:50,553 | INFO  | sshd-SshServer[242a1ef6]-nio2-thread-1 | ServerUserAuthService            | 38 - org.apache.sshd.core - 1.7.0 | Session admin@/127.0.0.1:50158 authenticated
2020-05-23T05:28:51,697 | ERROR | Camel (camel-35) thread #67 - timer://exec | ExecProducer                     | 109 - org.apache.camel.camel-exec - 3.3.0 | The command ExecCommand [args=[], executable=/opt/apache-karaf/bin/user-add, timeout=9223372036854775807, outFile=null, workingDir=null, commandLogLevel=DEBUG, useStderrOnEmptyStdout=false] returned exit value 1
2020-05-23T05:28:51,697 | INFO  | Camel (camel-35) thread #67 - timer://exec | route37                          | 102 - org.apache.camel.camel-core-engine - 3.3.0 | headers: {CamelExecExitValue=1, CamelExecStderr=java.io.ByteArrayInputStream@6d4d91bc, firedTime=Sat May 23 05:28:45 UTC 2020}
 

Best
- Gerald
Reply | Threaded
Open this post in threaded view
|

Re: Camel-exec issue (script works but returns 1 inside a route)

Alex Soto
Hi Gerald,

There is no "/opt/apache-karaf/bin/user-add” in the default Karaf distribution, AFAIK.

I think you may want to use the “/opt/apache-karaf/bin/client” script instead, or SSH, or perhaps your best choice is to directly reference the implementation Service as a bean.  I don’t know which service deals with the JAAS subsystem, but I suspect there is one, in which case, you can reference the service, as in:

        <reference id=“myService” interface=“org.apache.karaf.SomeServiceInterface”/>


Then call “myService” as a bean:

        <bean ref=“myService" method=“someMethod”/>


And avoid interacting with the shell.  I hope this helps.

Best regards,
Alex soto




> On May 23, 2020, at 1:29 AM, Gerald Kallas <[hidden email]> wrote:
>
> /opt/apache-karaf/bin/user-add

Reply | Threaded
Open this post in threaded view
|

Re: Camel-exec issue (script works but returns 1 inside a route)

Alex Soto
Also, take a look at  org.apache.karaf.itests.KarafTestSupport.executeCommand from

<groupId>org.apache.karaf.itests</groupId>
<artifactId>common</artifactId>



Best regards,
Alex soto




> On May 28, 2020, at 9:50 AM, Alex Soto <[hidden email]> wrote:
>
> Hi Gerald,
>
> There is no "/opt/apache-karaf/bin/user-add” in the default Karaf distribution, AFAIK.
>
> I think you may want to use the “/opt/apache-karaf/bin/client” script instead, or SSH, or perhaps your best choice is to directly reference the implementation Service as a bean.  I don’t know which service deals with the JAAS subsystem, but I suspect there is one, in which case, you can reference the service, as in:
>
> <reference id=“myService” interface=“org.apache.karaf.SomeServiceInterface”/>
>
>
> Then call “myService” as a bean:
>
> <bean ref=“myService" method=“someMethod”/>
>
>
> And avoid interacting with the shell.  I hope this helps.
>
> Best regards,
> Alex soto
>
>
>
>
>> On May 23, 2020, at 1:29 AM, Gerald Kallas <[hidden email] <mailto:[hidden email]>> wrote:
>>
>> /opt/apache-karaf/bin/user-add
>