start
Starting and Stopping Mule
Mule runtime engine version 3.8 reached its End of Life on November 16, 2021. For more information, contact your Customer Success Manager to determine how to migrate to the latest Mule version. |
This document deals with deploying to standalone instances of the Mule runtime. To take full advantage of managing and monitoring features, you can deploy to the same Mule runtime via the Runtime Manager. See Deployment Strategies for a deeper look at the different deployment alternatives offered by the platform.
Mule uses the Java Service Wrapper to control the Java Virtual Machine (JVM) from your native OS. The wrapper provides many options and features, including the ability to run Mule as a Unix daemon or install or remove Mule as a Windows Service. The wrapper can handle system signals and start parameters, and overall provides much better interaction between the JVM and the underlying OS.
For more information about the Java Service Wrapper, consult the online documentation.
Startup and Shutdown Script
The wrapper is called by a script in $MULE_HOME/bin
.
Unix: $MULE_HOME/bin/mule
Windows: $MULE_HOME\bin\mule.bat
Note: When windows restarts, the Mule service stops the same way as using the mule stop
command.
The only situation that this could be different is if Windows kills the process due to a timeout.
The table below lists all the parameters that the script accepts.
Parameter | Description |
---|---|
Starts the Mule server in the terminal background. |
|
|
Stops the Mule server. The stopping process stops inbound endpoints to process in-flight messages. However due to a timeout duration not all messages are ensured to be processed before final shutdown occurs. |
|
Restarts the Mule server. |
|
(Unix only.) Displays the status of the Mule server ( |
|
(Unix only.) Dumps the Mule wrapper’s core to |
|
Start Mule in the terminal foreground (console mode). Same as running |
|
(Windows only.) Install Mule as a Windows service. |
|
(Windows only.) Remove Mule from your Windows services. |
Starting and Stopping Mule Via the Command Line
Starting In the Background
-
Use the
cd
command to navigate to the$MULE_HOME/bin
directory. -
Run the startup script according to the options below.
-
Unix:
./mule start
-
Windows:
mule.bat start
-
Alternatively, instead of using the cd
command, type the full path of the script, for example /opt/mule/mule-ee-3.8.0/bin/mule start
.
To stop Mule, run the script with the stop
parameter.
Starting In the Foreground
-
Use the
cd
command to navigate to the$MULE_HOME/bin
directory. -
Run the startup script according to the options below.
-
Unix:
./mule
-
Windows:
mule
-
Alternatively, instead of using the cd
command, type the full path of the script, for example /opt/mule/mule-ee-3.8.0/bin/mule
.
When running in foreground mode, the startup script displays information on the terminal’s standard output. You can’t issue further commands on the terminal as long as Mule is running.
To stop Mule, press CTRL-C
in the terminal in which the script is running.
Passing Arguments to Mule At Startup
Configuration Files
By default, the Java Service Wrapper loads configuration options from the file mule-config.xml
. This file is empty by default; it’s included in the $MULE_HOME/apps/default
directory.
The -config
parameter allows you to pass configuration files as arguments to the startup script.
./mule start -config <file1>[,<file2>,<file3>...]
To specify more than one configuration file, include the files in a comma-separated list.
Passing Parameters to the JVM via the Startup Command
Include your parameters as script parameters (if running in background, after the start
parameter), as shown below. Separate parameters with a space if there is more than one.
./mule start -D-Mmule.mmc.bind.port=7783-7883
Passing Parameters to the JVM via the Wrapper Config File
Include your parameters in the configuration file $MULE_HOME/conf/wrapper.conf
. The distribution includes this file with comments (see fragment below). You can edit this file or add to it as needed. For more information about the wrapper.conf
file, consult the Java Service Wrapper online documentation for the file.
...
# Name of the service
wrapper.ntservice.name=%MULE_APP%
# Display name of the service
wrapper.ntservice.displayname=%MULE_APP_LONG%
# Description of the service
wrapper.ntservice.description=%MULE_APP_LONG%
# Service dependencies. Add dependencies as needed starting from 1
wrapper.ntservice.dependency.1=
# Mode in which the service is installed. AUTO_START or DEMAND_START
wrapper.ntservice.starttype=AUTO_START
# Allow the service to interact with the desktop.
wrapper.ntservice.interactive=false
# Do not edit lines below!
wrapper.license.type=DEV
wrapper.license.id=201010160006
wrapper.license.licensee=mulesoft.com
wrapper.license.dev_application=Mule Enterprise Edition
wrapper.license.features=64bit
...
Setting JVM Parameters inside Anypoint Studio
You can set JVM parameters for Mule applications run from Anypoint Studio. Run > Run Configurations > Arguments tab, entering the arguments in the "VM arguments" pane.
-Dorg.mule.xml.validate=false -Djava.mail.debug=true
Set Mule Standalone Server Memory
Enter the $MULE_HOME/conf/wrapper.conf
configuration file and search for the maxheap
parameter:
# Maximum Java Heap Size (in MB)
wrapper.java.maxmemory=1024
. The memory allowed must be specified in MB. To set the memory to 2GB, replace 1024
with 2048
.
Set Mule Encoding
For example, to set Mule’s encoding, you could add wrapper.java.additional.1=-Dmule.encoding=ISO-8859-1
to the Wrapper configuration file, or you could add -D-Mmule.encoding=ISO-8859-1
to the Mule script at the command line. Note that if you add wrapper.java.additional.n entries to the configuration file, you must change each instance of n to a consecutive number, or Java does not parse the properties correctly.
Passing Additional Arguments to the Wrapper
To control the behavior of the Wrapper from the command line use the -W switch when launching Mule.
For example, to set the logfile that the Wrapper’s uses, you could add wrapper.logfile=/my/log/file.log
to the Wrapper configuration file, or you could add -Wwrapper.logfile=/my/log/file.log
to the Mule script at the command line.
Running Mule As a Unix Daemon
To run Mule as a Unix daemon, you need to write a simple wrapper script for the Mule startup script. Place your wrapper script in your system’s appropriate directory (such as /etc/init.d
) and use your system’s init script architecture tools to ensure that your wrapper script is invoked in the runlevels you wish.
Here is a sample init.d
script for Red Hat Enterprise Linux:
#!/bin/bash
# RHEL Mule Init Script
#
# chkconfig: 2345 65 64
# description: Mule ESB service
. /etc/init.d/functions
#
if [ -f /etc/sysconfig/mule ]; then
. /etc/sysconfig/mule
fi
# Set JDK related environment
JAVA_HOME=/usr/java/default
PATH=$PATH:$JAVA_HOME/bin
# Set Mule related environment
MULE_HOME=/opt/mule
MULE_LIB=$MULE_HOME/lib
PATH=$PATH:$MULE_HOME/bin
RUN_AS_USER=mule
MULE_ENV=production
# Export environment variables
export JAVA_HOME MULE_HOME MULE_LIB PATH MULE_ENV RUN_AS_USER
case "$1" in
start)
echo "Start service mule"
$MULE_HOME/bin/mule start -M-Dspring.profiles.active=$MULE_ENV -M-DMULE_ENV=$MULE_ENV
;;
stop)
echo "Stop service mule"
$MULE_HOME/bin/mule stop
;;
restart)
echo "Restart service mule"
$MULE_HOME/bin/mule restart -M-Dspring.profiles.active=$MULE_ENV -M-DMULE_ENV=$MULE_ENV
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
;;
esac
Your wrapper script needs to set the required environment for Mule; a sample script is provided below below.
#!/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>
On some systems, you can set up startup scripts for use with the service
utility (System V). Consult your operating system’s documentation for details.
For CentOS 7 and RHEL 7
After the steps described in Running Mule As a Unix Daemon, you might realize that every time you execute service mule start
, a new process replaces the one that was currently running. To avoid that behavior, you can follow these instructions:
-
Create the file
/etc/systemd/system/<name of the wrapper script>.service
with the content:
[Service]
Type=forking
ExecStart=/etc/init.d/<name of the wrapper script> start
User=mule
-
Run the command to reload the service configuration:
systemctl daemon-reload
Running Mule As a Windows Service
In Mule 3.8.0, the Tanuki wrapper was upgraded to a newer version, implying a change to the certificate by which the wrapper is signed. See Mule 3.8.0 release notes concerning Tanuki Wrapper upgrade for details on resolving compatibility issues.
To install Mule as a Windows service, go to the $MULE_HOME/bin/
directory, then issue the following commands.
mule install
To remove Mule from your Windows services, go to the $MULE_HOME/bin/
directory, then run:
mule remove
Once Mule is installed as a service, you can control it with the following command:
mule start|restart|stop
To start Mule with additional configuration, issue:
mule start -config <your-config-file.xml>
Once Mule is installed as a service, you can also use the Windows net
utility to start or stop it:
net start|stop mule
Common Parameters
The table below lists some parameters common to Mule, which are not documented in the wrapper.conf
configuration file.
Parameter | Description |
---|---|
|
( Boolean ) Start Mule with or without the Management Console agent, which is enabled by default. |
-D-Mmule.mmc.bind.port |
Specify a port or port range for the Mule agent listener that the Management Console binds to. To specify a port range, use |
The $MULE_HOME/conf/wrapper.conf
configuration file includes many more parameters, some of which are by default commented out, but documented in the comments.
Shutting Down Mule
You can shut down Mule using the mule stop
command that is run from the MULE_HOME/bin
directory. When Mule stops,
inbound endpoints are shut down, and in-flight Mule messages continue to process until the shutdown.timeout
configured in wrapper.conf
setting elapses and final shutdown occurs.
You can set a timeout value to enable the current flow to complete. However, there is no built in method or utility to check what messages are in flight. You can connect a profiler and see the active threads (or just a thread dump), this should provide you an overview of what’s happening at the JVM level.
To ensure all inflight messages are processed you can shutdown mule in two steps:
-
Stop the flow(s) manually (this will prevent new messages from coming)
-
Stop Mule
Timeout From wrapper.conf
You can set the timeout value (in milliseconds) in wrapper.conf
using the wrapper.shutdown.timeout
statement where the value is in
seconds, for example:
wrapper.shutdown.timeout="30000"
More information is available in the Tanuki wrapper.shutdown.timeout page.
Shutdown Timeout From a Flow
Alternatively, you can set shutdownTimeout
to a milliseconds value for a flow. However, this is not
a global value.
Example for testing purposes:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:test="http://www.mulesoft.org/schema/mule/test"
xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/test http://www.mulesoft.org/schema/mule/test/current/mule-test.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd">
<configuration shutdownTimeout="10000"/>
<flow name="TestService">
<test:component/>
</flow>
</mule>
See Also
-
NEXT STEP: Start with Mule Application Architecture.