Running Mule with systemd

Most modern Linux distributions now uses systemd as the init system. However the official documentation for Mule Standalone Runtime currently (2017-06-19) only describes how to use the old SystemV init script style to run the Mule Standalone Runtime as a Unix Daemon.

Here is a quick guide on how to create a systemd Unit file for a Mule Standalone Runtime service. These instructions was created for and tested on a RedHat Enterprise Linux 7 server. However most should be applicable to other Linux distros running systemd.

  1. Make sure your machine fulfills the standard Mule pre-requisites. Such as has Java 8 installed. This guide assumes they are installed using the official packages from the distribution.
  2. Add a mule user
    root@server:~# adduser -r mule
  3. Unpack the Mule distribution into /opt
root@server:~# cd /opt 
root@server:~# unzip /tmp/mule-ee-distribution-standalone-3.8.4.zip
  1. Create a symlink to the mule directory and fix privileges
root@server:~# ln -s mule-enterprise-standalone-3.8.4 mule
root@server:~# chown -R mule:mule mule-enterprise-standalone-3.8.4
root@server:~# chmod  -R o-w mule-enterprise-standalone-3.8.4
  1. Create the a mule unit file
root@server:~# touch /etc/systemd/system/mule.service
root@server:~# chmod 664 /etc/systemd/system/mule.service
  1. Add the following content to the file using your favorit editor
# Systemd unit file for mule standalone runtime
[Unit]
Description=Mule Runtime Standalone Runtime
After=syslog.target network.target

[Service]
Type=forking
WorkingDirectory=/opt/mule
Environment=JAVA_HOME=/usr
Environment=MULE_HOME=/opt/mule
TasksMax=infinity 
LimitNOFILE=65335

ExecStart=/opt/mule/bin/mule start
ExecStop=/opt/mule/bin/mule stop

User=mule
Group=mule

RestartSec=10
Restart=always

[Install]
WantedBy=multi-user.target
  1. Reload the systemd configuration
root@server:~# systemctl daemon-reload
  1. Start the service to test that it starts up correctly
root@server:~# systemctl start mule.service
  1. Enable the service so that it is started by default at boot
root@server:~# systemctl enable mule.service
  1. Reboot the server to verify that the service comes up as expected