1

I am trying to execute shell script with camel and tried the following code, everything is looking fine its starting the route but I have following 2 issues

  1. Shell script file is not picking and executing the commands in it.
  2. Not even getting log messages that I kept all over in my code.

following is the route that I am using

@component
public class ShellRoute extends RouteBuilder
{
@override
public void configure()
{
final Logger logger = LoggerFactory.getLogger(ShellRoute.class);
logger.info("shellRoute");

boolean startupRoute=true;

from("direct:start")
.log(LoggingLevel.INFO, "Enter into Route:")
.routeID("ShellRoute")
.autoStartup(startupRoute)
.onException(Exception.class);
.logExhausted(false)
.logStackTrace(false)
.end()
.log(LoggingLevel.INFO, "Starting Script:")
.to("exec:./run_setup.sh?args=dev")
.log(LoggingLevel.INFO, "End of Script:");
}
}

Following is the Log:

2017-09-29 08:32:53 INFO Version:30 - HV000001: Hibernate Validator 5.2.4.Final

2017-09-29 08:32:53 INFO SupportMain:48 - Starting SupportMain on VDDP13C-52C8C99.mis.lmig.com with PID 13002 (/data/userdata/workspaces/ClaimDownload/support/target/classes started by mani in /data/userdata/workspaces/ClaimDownload/support)

2017-09-29 08:32:53 INFO SupportMain:669 - The following profiles are active: local

2017-09-29 08:32:53 INFO AnnotationConfigApplicationContext:581 - Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@776aec5c: startup date [Fri Sep 29 08:32:53 EDT 2017]; root of context hierarchy 2017-09-29 08:32:55 INFO PostProcessorRegistrationDelegate$BeanPostProcessorChecker:328 - Bean 'org.apache.camel.spring.boot.CamelAutoConfiguration' of type [class org.apache.camel.spring.boot.CamelAutoConfiguration$$EnhancerBySpringCGLIB$$9509da1] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)

2017-09-29 08:32:56 INFO DefaultTypeConverter:56 - Loaded 209 type converters

2017-09-29 08:32:57 INFO AnnotationMBeanExporter:431 - Registering beans for JMX exposure on startup

2017-09-29 08:32:57 INFO ShellRoute:33 - ShellRoute

2017-09-29 08:32:57 INFO RoutesCollector:148 - Loading additional Camel XML routes from: classpath:camel/*.xml

2017-09-29 08:32:57 INFO RoutesCollector:162 - Loading additional Camel XML rests from: classpath:camel-rest/*.xml

2017-09-29 08:32:57 INFO SpringCamelContext:2800 - Apache Camel 2.17.2 (CamelContext: camel-1) is starting

2017-09-29 08:32:57 INFO ManagedManagementStrategy:191 - JMX is enabled

2017-09-29 08:32:57 INFO DefaultRuntimeEndpointRegistry:203 - Runtime endpoint registry is in extended mode gathering usage statistics of all incoming and outgoing endpoints (cache limit: 1000)

2017-09-29 08:32:57 INFO SpringCamelContext:3039 - AllowUseOriginalMessage is enabled. If access to the original message is not needed, then its recommended to turn this option off as it may improve performance.

2017-09-29 08:32:57 INFO SpringCamelContext:3049 - StreamCaching is not in use. If using streams then its recommended to enable stream caching. See more details at http://camel.apache.org/stream-caching.html

2017-09-29 08:32:57 INFO SpringCamelContext:3570 - Route: ShellRoute started and consuming from: Endpoint[direct://start]

2017-09-29 08:32:57 INFO SpringCamelContext:2840 - Total 1 routes, of which 1 are started.

2017-09-29 08:32:57 INFO SpringCamelContext:2841 - Apache Camel 2.17.2 (CamelContext: camel-1) started in 0.667 seconds

2017-09-29 08:32:57 INFO SupportMain:57 - Started SupportMain in 4.963 seconds (JVM running for 6.767)

2017-09-29 08:32:57 INFO AnnotationConfigApplicationContext:982 - Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@776aec5c: startup date [Fri Sep 29 08:32:53 EDT 2017]; root of context hierarchy

2017-09-29 08:32:57 INFO AnnotationMBeanExporter:449 - Unregistering JMX-exposed beans on shutdown

2017-09-29 08:32:57 INFO SpringCamelContext:3066 - Apache Camel 2.17.2 (CamelContext: camel-1) is shutting down

Syfer
  • 4,262
  • 3
  • 20
  • 37
mani ratnam
  • 11
  • 1
  • 2

2 Answers2

0

To execute shell script command in Apache camel, As per the exec component documentation http://camel.apache.org/exec.html

The following example executes Apache Ant (Windows only) with the build file CamelExecBuildFile.xml, provided that ant.bat is in the system path, and that CamelExecBuildFile.xml is in the current directory.

from("direct:exec").to("exec:ant.bat?args=-f CamelExecBuildFile.xml")

So similarly from("direct:exec").to("exec:{path}/Cygwin/bin/bash?args=run_setup.sh")

  • Hi ManishGupta It's not working, problem here in this route is, route is starting as I gave .autoStartup(startupRoute) But whatever in the route it may be "exec" or "simple file transfer" its not happening Do I need to register this route somewhere to execute commands in the route Please let me know, i am new to camel. – mani ratnam Sep 30 '17 at 07:04
  • A good idea is to study the beginner examples of Apache Camel if you are new to Camel: https://github.com/apache/camel/tree/master/examples#examples – Claus Ibsen Oct 03 '17 at 17:31
0

The direct endpoint provides synchronous invocation of a route. So you have to invoke the route for the script to execute. Have a look at this answer for invoking routes. Apache Camel : "direct:start" endpoint - what does it mean ?

If you want it to execute just one time at the startup you can replace

from("direct:exec") 

with something like

from("timer://runOnce?repeatCount=1&delay=5000") 

Related answer in Apache Camel - Triggering a task on startup to run only once

ltsallas
  • 1,918
  • 1
  • 12
  • 25