Java Service Wrapper
Mule uses the Java Service Wrapper (http://wrapper.tanukisoftware.org) to control the JVM from your native OS. The wrapper provides many advanced options and features which you can read about on the Wrapper website. In brief, the Java Service Wrapper can install (or remove) Mule as a Windows NT Service. It also provides means to run Mule a UNIX Daemon. The Wrapper can handle system signals and provides better interaction between the JVM and the underlying OS.
Starting Mule from a Script
To start mule, it is easiest to use the 'mule' and 'mule.bat' scripts in the distribution bin directory. These scripts invoke the Java Service Wrapper.
If you want to simply run Mule, without bothering with running it as a service or daemon, just type
mule -config <your-config-file.xml>
If you don't specify the "-config" option, Mule will look for a file called mule-config.xml. (There is no such file in the stock distribution). For more examples of the syntax above, refer to the scripts in the examples directory of your distribution.
Running Mule as a Windows NT Service
If you want to install Mule as a Windows NT Service, type
mule install -config <your-config-file.xml>
Likewise, to remove Mule from your services, type:
Once you have Mule installed, you can then invoke the service exactly as you did before, but with an additional parameter:
mule start|restart|stop -config <your-config-file.xml>
You can do the same operations using Windows 'net' utility:
The start|restart|stop arguments tell the Mule service to start, restart or stop, respectively.
Running Mule as a UNIX Daemon
To run Mule as UNIX Daemon you'll need to use 'mule' script. As that script accepts start|stop|restart|status command the only thing that needs to be done is creating simple wrapper script to set Mule environment and pass required parameters. Sample script might look like this:
#!/bin/bash
# Set JDK related environment
JAVA_HOME=<path to JDK>
PATH=$PATH:$JAVA_HOME/bin
# Set Mule related environment
MULE_HOME=<path to Mule>
MULE_LIB=<path to application specific libraries>
PATH=$PATH:$MULE_HOME/bin
# Export environment variables
export JAVA_HOME MULE_HOME MULE_LIB PATH
# Invoke Mule
$MULE_HOME/bin/mule $1 -config <path to mule-conf.xml>
Yo'll need to set path to your JDK, Mule installation and mule config file(s). Once you have saved this script as /etc/init.d/mule you should set apropriate ownership and mode on that script:
chown root:root /etc/init.d/mule
chmod 755 /etc/init.d/mule
Now you can use that script to manage Mule Daemon:
/etc/init.d/mule start|stop|restart|status
On some operating systems, which are using SysV-style startup system you can use 'service' utility:
service start|stop|restart|status mule
Starting Mule Directly
To start a mule server from a script or from your IDE without using the Java Service Wrapper, you can use the org.mule.MuleServer class. This accepts a couple of parameters.
org.mule.MuleServer -config mule-config.xml or
org.mule.MuleServer -builder <fully qualified classname> -config appContext.xml
- -config param specifies one or more config files to use. If this argument is omitted the default 'mule-config.xml' will be used.
- -builder param is a fully qualified classname of the config builder to use. If this is not set the default org.mule.config.builders.MuleXmlConfigurationBuilder is used.
The eaisest way to set the classpath is to include all jars in the ./lib/mule and ./lib/opt directories of the distribution. You can have a look at the dependency report for the server and each of the modules to see exactly which jars are required for a particular module.
You can also start a mule server from your code by using one of -
MuleServer server = new MuleServer("mule-config1.xml,mule-config2.xml");
server.start(true);
Often it will not be necessary to start the server like this. If you want to embed Mule in an application or a webapp see -
Configuring Mule for performance, memory and thread profiling:
- [MULEUSER:Profiling Mule with YourKit]