0

I'm trying to run Mule on Ubuntu 14.04 as a service. I created the following init script (/etc/init.d/mule)

#!/bin/bash

JAVA_HOME=/usr/lib/jvm/java-8-oracle
PATH=$PATH:$JAVA_HOME/bin

# Set Mule related environment
MULE_HOME=/opt/mule
PATH=$PATH:$MULE_HOME/bin
RUN_AS_USER=mule

# Export environment variables
export JAVA_HOME MULE_HOME RUN_AS_USER PATH

# Invoke Mule
$MULE_HOME/bin/mule $1

Here I define some environment variables, most notably RUN_AS_USER since I want Mule to run as user mule.

When I call sudo service mule start I see nothing happening but when calling sudo /etc/init.d/mule start, Mule starts running fine.

Looking at the startup script for Mule, on line 419 the script is relaunched if it needs to be run as another user.

RELAUNCH_CMD="$REALPATH $@"
su -m $RUN_AS_USER -c "$RELAUNCH_CMD"

Why is it that when calling the init script directly, Mule starts running fine but when using the service utility, nothing happens? The man page for service says that it removes most environment variables. So I'm guessing that calling su depends on the environment somehow.

0

The problem was that the user mule didn't have a shell. It was set to /bin/false.

The -m flag for su preserves the environment, so when I called sudo /etc/init.d/mule start the SHELL environment variable was set and passed down to su.

But when calling sudo service mule start the environment is cleaned. From service man page:

service runs a System V init script or upstart job in as predictable an environment as possible, removing most environment variables and with the current working directory set to /.

Therefore the environment does not contain a SHELL variable and the user mule does not have a shell as well. So no command is executed it seems.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.