You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by an...@apache.org on 2020/01/15 01:23:15 UTC

[sling-whiteboard] branch master updated: Making the Sling Starter Feature Maven Plugin work (start/stop and keep it running)

This is an automated email from the ASF dual-hosted git repository.

andysch pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-whiteboard.git


The following commit(s) were added to refs/heads/master by this push:
     new 0a15c7a  Making the Sling Starter Feature Maven Plugin work (start/stop and keep it running)
0a15c7a is described below

commit 0a15c7af8d71e6d4061abf8131bbfb5333d4744d
Author: Andreas Schaefer <sc...@iMac.local>
AuthorDate: Tue Jan 14 17:22:50 2020 -0800

    Making the Sling Starter Feature Maven Plugin work (start/stop and keep it running)
---
 sling-org-apache-sling-feature-starter/pom.xml     |   9 +
 .../sling/feature/starter/app/ControlAction.java   |  53 ++
 .../sling/feature/starter/app/ControlListener.java | 628 +++++++++++++++++++++
 .../sling/feature/starter/app/ControlTarget.java   |  32 ++
 .../sling/feature/starter/app/SlingStarter.java    | 127 ++++-
 .../slingstart/feature/launcher/Launcher.java      |   2 +
 .../maven/slingstart/feature/launcher/Main.java    |  13 +-
 .../slingstart/feature/run/ControlClient.java      | 365 ++++++++++++
 .../slingstart/feature/run/LauncherCallable.java   |  26 +-
 .../slingstart/feature/run/ProcessDescription.java |  15 +-
 .../maven/slingstart/feature/run/StartMojo.java    |   1 +
 11 files changed, 1243 insertions(+), 28 deletions(-)

diff --git a/sling-org-apache-sling-feature-starter/pom.xml b/sling-org-apache-sling-feature-starter/pom.xml
index 593e430..7968c93 100644
--- a/sling-org-apache-sling-feature-starter/pom.xml
+++ b/sling-org-apache-sling-feature-starter/pom.xml
@@ -143,6 +143,14 @@
             <groupId>org.slf4j</groupId>
             <artifactId>slf4j-simple</artifactId>
         </dependency>
+
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.framework</artifactId>
+            <version>6.0.2</version>
+            <scope>provided</scope>
+        </dependency>
+
         <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.feature.extension.content</artifactId>
@@ -226,6 +234,7 @@
                             <launchpadJar>${project.build.directory}/${project.artifactId}-${project.version}.jar</launchpadJar>
                             <parallelExecution>false</parallelExecution>
 <!--                            <createWebapp>false</createWebapp>-->
+                                <keepLaunchpadRunning>true</keepLaunchpadRunning>
                             <servers>
                                 <server>
                                     <port>${http.port}</port>
diff --git a/sling-org-apache-sling-feature-starter/src/main/java/org/apache/sling/feature/starter/app/ControlAction.java b/sling-org-apache-sling-feature-starter/src/main/java/org/apache/sling/feature/starter/app/ControlAction.java
new file mode 100644
index 0000000..7213d86
--- /dev/null
+++ b/sling-org-apache-sling-feature-starter/src/main/java/org/apache/sling/feature/starter/app/ControlAction.java
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.feature.starter.app;
+
+/**
+ * The <code>ControlAction</code> defines values to used as the action for the
+ * Feature Launcher control with the {@link Main#doControlAction()} method.
+ */
+public enum ControlAction {
+
+    /**
+     * Indicates the Feature Launcher application should be started and a listener should
+     * be installed to accept control commands.
+     */
+    START,
+
+    /**
+     * Indicates to connect to a running Feature Launcher application having installed a
+     * listener and send that application the command to shutdown.
+     */
+    STOP,
+
+    /**
+     * Indicates to connect to a running Feature Launcher application having installed a
+     * listener and ask that application about its state.
+     */
+    STATUS,
+
+    FOREGROUND,
+
+    /**
+     * Indicates to connect to a running Feature Launcher application having installed a
+     * listener and ask for a thread dump.
+     */
+    THREADS;
+
+}
diff --git a/sling-org-apache-sling-feature-starter/src/main/java/org/apache/sling/feature/starter/app/ControlListener.java b/sling-org-apache-sling-feature-starter/src/main/java/org/apache/sling/feature/starter/app/ControlListener.java
new file mode 100644
index 0000000..a996984
--- /dev/null
+++ b/sling-org-apache-sling-feature-starter/src/main/java/org/apache/sling/feature/starter/app/ControlListener.java
@@ -0,0 +1,628 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.feature.starter.app;
+
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.LineNumberReader;
+import java.io.OutputStreamWriter;
+import java.lang.management.LockInfo;
+import java.lang.management.ManagementFactory;
+import java.lang.management.MonitorInfo;
+import java.lang.management.ThreadInfo;
+import java.lang.management.ThreadMXBean;
+import java.math.BigInteger;
+import java.net.ConnectException;
+import java.net.InetSocketAddress;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.security.SecureRandom;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * The <code>ControlListener</code> class is a helper class for the {@link ControlTarget}
+ * class to support in Sling standalone application process communication. This
+ * class implements the client and server sides of a TCP/IP based communication
+ * channel to control a running Sling application.
+ * <p>
+ * The server side listens for commands on a configurable host and port &endash;
+ * <code>localhost:63000</code> by default &endash; supporting the following
+ * commands:
+ * <table>
+ * <tr>
+ * <th>Command</th>
+ * <th>Description</th>
+ * </tr>
+ * <tr>
+ * <td><code>status</code></td>
+ * <td>Request status information. Currently only <i>OK</i> is sent back. If no
+ * connection can be created to the server the client assumes Sling is not
+ * running.</td>
+ * </tr>
+ * <tr>
+ * <td><code>stop</code></td>
+ * <td>Requests Sling to shutdown.</td>
+ * </tr>
+ * </table>
+ */
+public class ControlListener implements Runnable {
+
+    // command sent by the client to cause Sling to shutdown
+    static final String COMMAND_STOP = "stop";
+
+    // command sent by the client to check for the status of the server
+    static final String COMMAND_STATUS = "status";
+
+    // command sent by the client to request a thread dump
+    static final String COMMAND_THREADS = "threads";
+
+    // the response sent by the server if the command executed successfully
+    private static final String RESPONSE_OK = "OK";
+
+    // the status response sent by the server when shutting down
+    private static final String RESPONSE_STOPPING = "STOPPING";
+
+    // The default interface to listen on
+    private static final String DEFAULT_LISTEN_INTERFACE = "127.0.0.1";
+
+    // The default port to listen on and to connect to - we select it randomly
+    private static final int DEFAULT_LISTEN_PORT = 0;
+
+    // The reference to the Main class to shutdown on request
+    private final ControlTarget controlTarget;
+
+    private final String listenSpec;
+
+    private String secretKey;
+    private InetSocketAddress socketAddress;
+
+    private volatile Thread shutdownThread = null;
+
+    /**
+     * Creates an instance of this control support class.
+     * <p>
+     * The host (name or address) and port number of the socket is defined by
+     * the <code>listenSpec</code> parameter. This parameter is defined as
+     * <code>[ host ":" ] port</code>. If the parameter is empty or
+     * <code>null</code> it defaults to <i>localhost:0</i>. If the host name
+     * is missing it defaults to <i>localhost</i>.
+     *
+     * @param controlTarget The Main class reference. This is only required if this
+     *            instance is used for the server side to listen for remote stop
+     *            commands. Otherwise this argument may be <code>null</code>.
+     * @param listenSpec The specification for the host and port for the socket
+     *            connection. See above for the format of this parameter.
+     */
+    public ControlListener(final ControlTarget controlTarget, final String listenSpec) {
+        this.controlTarget = controlTarget;
+        this.listenSpec = listenSpec; // socketAddress = this.getSocketAddress(listenSpec, selectNewPort);
+    }
+
+    /**
+     * Implements the server side of the control connection starting a thread
+     * listening on the host and port configured on setup of this instance.
+     */
+    public boolean listen() {
+        final File configFile = getConfigFile();
+        if (configFile.canRead() && statusServer() == 0) {
+            // server already running, fail
+            controlTarget.error("Sling already active in " + this.controlTarget.getHome(), null);
+            return false;
+        }
+        configFile.delete();
+
+        final Thread listener = new Thread(this);
+        listener.setDaemon(true);
+        listener.setName("Apache Sling Control Listener (inactive)");
+        listener.start();
+        return true;
+    }
+
+    /**
+     * Implements the client side of the control connection sending the command
+     * to shutdown Sling.
+     */
+    public int shutdownServer() {
+        return sendCommand(COMMAND_STOP);
+    }
+
+    /**
+     * Implements the client side of the control connection sending the command
+     * to check whether Sling is active.
+     */
+    public int statusServer() {
+        return sendCommand(COMMAND_STATUS);
+    }
+
+    /**
+     * Implements the client side of the control connection sending the command
+     * to retrieve a thread dump.
+     */
+    public int dumpThreads() {
+        return sendCommand(COMMAND_THREADS);
+    }
+
+    // ---------- Runnable interface
+
+    /**
+     * Implements the server thread receiving commands from clients and acting
+     * upon them.
+     */
+    @Override
+    public void run() {
+        this.configure(false);
+
+        final ServerSocket server;
+        try {
+            server = new ServerSocket();
+            server.bind(this.socketAddress);
+            writePortToConfigFile(getConfigFile(),
+                new InetSocketAddress(server.getInetAddress(), server.getLocalPort()), this.secretKey);
+            Thread.currentThread().setName(
+                "Apache Sling Control Listener@" + server.getInetAddress() + ":" + server.getLocalPort());
+            controlTarget.info("Apache Sling Control Listener started", null);
+        } catch (final IOException ioe) {
+            controlTarget.error("Failed to start Apache Sling Control Listener", ioe);
+            return;
+        }
+
+        long delay = 0;
+
+        try {
+            while (true) {
+
+                final Socket s;
+                try {
+                    s = server.accept();
+                } catch (IOException ioe) {
+                    // accept terminated, most probably due to Socket.close()
+                    // just end the loop and exit
+                    break;
+                }
+
+                // delay processing after unsuccessful attempts
+                if (delay > 0) {
+                    controlTarget.info(s.getRemoteSocketAddress() + ": Delay: " + (delay / 1000), null);
+                    try {
+                        Thread.sleep(delay);
+                    } catch (InterruptedException e) {
+                    }
+                }
+
+                try {
+                    final String commandLine = readLine(s);
+                    if (commandLine == null) {
+                        final String msg = "ERR: missing command";
+                        writeLine(s, msg);
+                        continue;
+                    }
+
+                    final int blank = commandLine.indexOf(' ');
+                    if (blank < 0) {
+                        final String msg = "ERR: missing key";
+                        writeLine(s, msg);
+                        continue;
+                    }
+
+                    if (!secretKey.equals(commandLine.substring(0, blank))) {
+                        final String msg = "ERR: wrong key";
+                        writeLine(s, msg);
+                        delay = (delay > 0) ? delay * 2 : 1000L;
+                        continue;
+                    }
+
+                    final String command = commandLine.substring(blank + 1);
+                    controlTarget.info(s.getRemoteSocketAddress() + ">" + command, null);
+
+                    if (COMMAND_STOP.equals(command)) {
+                        if (this.shutdownThread != null) {
+                            writeLine(s, RESPONSE_STOPPING);
+                        } else {
+                            this.shutdownThread = new Thread("Apache Sling Control Listener: Shutdown") {
+                                @Override
+                                public void run() {
+                                    controlTarget.doStop();
+                                    try {
+                                        server.close();
+                                    } catch (final IOException ignore) {
+                                    }
+                                }
+                            };
+                            this.shutdownThread.start();
+                            writeLine(s, RESPONSE_OK);
+                        }
+
+                    } else if (COMMAND_STATUS.equals(command)) {
+                        writeLine(s, (this.shutdownThread == null) ? RESPONSE_OK : RESPONSE_STOPPING);
+
+                    } else if (COMMAND_THREADS.equals(command)) {
+                        dumpThreads(s);
+
+                    } else {
+                        final String msg = "ERR:" + command;
+                        writeLine(s, msg);
+
+                    }
+                } finally {
+                    try {
+                        s.close();
+                    } catch (IOException ignore) {
+                    }
+                }
+            }
+        } catch (final IOException ioe) {
+            controlTarget.error("Failure reading from client", ioe);
+        } finally {
+            try {
+                server.close();
+            } catch (final IOException ignore) {
+            }
+        }
+
+        getConfigFile().delete();
+
+        // everything has stopped and when this thread terminates,
+        // the VM should stop. If there are still some non-daemon threads
+        // active, this will not happen, so we force this here ...
+        controlTarget.info("Apache Sling terminated, exiting Java VM", null);
+        this.controlTarget.doTerminateVM(0);
+    }
+
+    // ---------- socket support
+
+    private void dumpThreads(final Socket socket) throws IOException {
+
+        final ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
+        final ThreadInfo[] threadInfos = threadBean.dumpAllThreads(true, true);
+
+        for (ThreadInfo thread : threadInfos) {
+            printThread(socket, thread);
+
+            // add locked synchronizers
+            final LockInfo[] locks = thread.getLockedSynchronizers();
+            writeLine(socket, "-");
+            writeLine(socket, "-   Locked ownable synchronizers:");
+            if (locks.length > 0) {
+                for (LockInfo li : locks) {
+                    writeLine(socket, String.format("-        - locked %s",
+                        formatLockInfo(
+                            li.getClassName(),
+                            li.getIdentityHashCode()
+                        )
+                    ));
+                }
+            } else {
+                writeLine(socket, "-        - None");
+            }
+
+            // empty separator line
+            writeLine(socket, "-");
+        }
+
+        final long[] deadLocked;
+        if (threadBean.isSynchronizerUsageSupported()) {
+            deadLocked = threadBean.findDeadlockedThreads();
+        } else {
+            deadLocked = threadBean.findMonitorDeadlockedThreads();
+        }
+        if (deadLocked != null) {
+            final ThreadInfo[] dl = threadBean.getThreadInfo(deadLocked, true, true);
+            final Set<ThreadInfo> dlSet = new HashSet<ThreadInfo>(Arrays.asList(dl));
+            int deadlockCount = 0;
+            for (ThreadInfo current : dl) {
+                if (dlSet.remove(current)) {
+
+                    // find and record a single deadlock
+                    ArrayList<ThreadInfo> loop = new ArrayList<ThreadInfo>();
+                    do {
+                        loop.add(current);
+                        for (ThreadInfo cand : dl) {
+                            if (cand.getThreadId() == current.getLockOwnerId()) {
+                                current = (dlSet.remove(cand)) ? cand : null;
+                                break;
+                            }
+                        }
+                    } while (current != null);
+
+                    deadlockCount++;
+
+                    // print the deadlock
+                    writeLine(socket, "-Found one Java-level deadlock:");
+                    writeLine(socket, "-=============================");
+                    for (ThreadInfo thread : loop) {
+                        writeLine(socket, String.format("-\"%s\" #%d",
+                            thread.getThreadName(),
+                            thread.getThreadId()
+                        ));
+                        writeLine(socket, String.format("-  waiting on %s",
+                            formatLockInfo(
+                                thread.getLockInfo().getClassName(),
+                                thread.getLockInfo().getIdentityHashCode()
+                            )
+                        ));
+                        writeLine(socket, String.format("-  which is held by \"%s\" #%d",
+                            thread.getLockOwnerName(),
+                            thread.getLockOwnerId()
+                        ));
+                    }
+                    writeLine(socket, "-");
+
+                    writeLine(socket, "-Java stack information for the threads listed above:");
+                    writeLine(socket, "-===================================================");
+
+                    for (ThreadInfo thread : loop) {
+                        printThread(socket, thread);
+                    }
+                    writeLine(socket, "-");
+                }
+            }
+
+//            "Thread-8":
+//                waiting to lock monitor 7f89fb80da08 (object 7f37a0968, a java.lang.Object),
+//                which is held by "Thread-7"
+//              "Thread-7":
+//                waiting to lock monitor 7f89fb80b0b0 (object 7f37a0958, a java.lang.Object),
+//                which is held by "Thread-8"
+
+            writeLine(socket, String.format("-Found %d deadlocks.",
+                deadlockCount
+            ));
+        }
+
+        writeLine(socket, RESPONSE_OK);
+    }
+
+    private String formatLockInfo(final String className, final int objectId) {
+        return String.format("<%08x> (a %s)", objectId, className);
+    }
+
+    private void printThread(final Socket socket, final ThreadInfo thread) throws IOException {
+        writeLine(socket, String.format("-\"%s\" #%d",
+            thread.getThreadName(),
+            thread.getThreadId()
+        ));
+
+        writeLine(socket, String.format("-    java.lang.Thread.State: %s",
+            thread.getThreadState()
+        ));
+
+        final MonitorInfo[] monitors = thread.getLockedMonitors();
+        final StackTraceElement[] trace = thread.getStackTrace();
+        for (int i=0; i < trace.length; i++) {
+            StackTraceElement ste = trace[i];
+            if (ste.isNativeMethod()) {
+                writeLine(socket, String.format("-        at %s.%s(Native Method)",
+                    ste.getClassName(),
+                    ste.getMethodName()
+                ));
+            } else {
+                writeLine(socket, String.format("-        at %s.%s(%s:%d)",
+                    ste.getClassName(),
+                    ste.getMethodName(),
+                    ste.getFileName(),
+                    ste.getLineNumber()
+                ));
+            }
+
+            if (i == 0 && thread.getLockInfo() != null) {
+                writeLine(socket, String.format("-        - waiting on %s%s",
+                    formatLockInfo(
+                        thread.getLockInfo().getClassName(),
+                        thread.getLockInfo().getIdentityHashCode()
+                    ),
+                    (thread.getLockOwnerId() >= 0)
+                        ? String.format(" owned by \"%s\" #%d",
+                            thread.getLockOwnerName(),
+                            thread.getLockOwnerId()
+                        ):""
+                ));
+            }
+
+            for (MonitorInfo mi : monitors) {
+                if (i == mi.getLockedStackDepth()) {
+                    writeLine(socket, String.format("-        - locked %s",
+                        formatLockInfo(
+                            mi.getClassName(),
+                            mi.getIdentityHashCode()
+                        )
+                    ));
+                }
+            }
+        }
+    }
+
+    /**
+     * Sends the given command to the server indicated by the configured
+     * socket address and logs the reply.
+     *
+     * @param command The command to send
+     *
+     * @return A code indicating success of sending the command.
+     */
+    private int sendCommand(final String command) {
+        if (configure(true)) {
+            if (this.secretKey == null) {
+                controlTarget.info("Missing secret key to protect sending '" + command + "' to " + this.socketAddress, null);
+                return 4; // LSB code for unknown status
+            }
+
+            Socket socket = null;
+            try {
+                socket = new Socket();
+                socket.connect(this.socketAddress);
+                writeLine0(socket, this.secretKey + " " + command);
+                final String result = readLine(socket);
+                controlTarget.info("Sent '" + command + "' to " + this.socketAddress + ": " + result, null);
+                return 0; // LSB code for everything's fine
+            } catch (final ConnectException ce) {
+                controlTarget.info("No Apache Sling running at " + this.socketAddress, null);
+                return 3; // LSB code for programm not running
+            } catch (final IOException ioe) {
+                controlTarget.error("Failed sending '" + command + "' to " + this.socketAddress, ioe);
+                return 1; // LSB code for programm dead
+            } finally {
+                if (socket != null) {
+                    try {
+                        socket.close();
+                    } catch (IOException ignore) {
+                    }
+                }
+            }
+        }
+        controlTarget.info("No socket address to send '" + command + "' to", null);
+        return 4; // LSB code for unknown status
+    }
+
+    private String readLine(final Socket socket) throws IOException {
+        final BufferedReader br = new BufferedReader(new InputStreamReader(
+            socket.getInputStream(), "UTF-8"));
+
+        StringBuilder b = new StringBuilder();
+        boolean more = true;
+        while (more) {
+            String s = br.readLine();
+            if (s != null && s.startsWith("-")) {
+                s = s.substring(1);
+            } else {
+                more = false;
+            }
+            if (b.length() > 0) {
+                b.append("\r\n");
+            }
+            b.append(s);
+        }
+
+        return b.toString();
+    }
+
+    private void writeLine(final Socket socket, final String line) throws IOException {
+        controlTarget.info(socket.getRemoteSocketAddress() + "<" + line, null);
+        this.writeLine0(socket, line);
+    }
+
+    private void writeLine0(final Socket socket, final String line) throws IOException {
+        final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(), "UTF-8"));
+        bw.write(line);
+        bw.write("\r\n");
+        bw.flush();
+    }
+
+    /**
+     * Read the port from the config file
+     * @return The port or null
+     */
+    private boolean configure(final boolean fromConfigFile) {
+        boolean result = false;
+        if (fromConfigFile) {
+            final File configFile = this.getConfigFile();
+            if (configFile.canRead()) {
+                try ( final LineNumberReader lnr = new LineNumberReader(new FileReader(configFile))) {
+                    this.socketAddress = getSocketAddress(lnr.readLine());
+                    this.secretKey = lnr.readLine();
+                    result = true;
+                } catch (final IOException ignore) {
+                    // ignore
+                }
+            }
+        } else {
+            this.socketAddress = getSocketAddress(this.listenSpec);
+            this.secretKey = generateKey();
+            result = true;
+        }
+
+        return result;
+    }
+
+    private static String generateKey() {
+         return new BigInteger(165, new SecureRandom()).toString(32);
+    }
+
+    /**
+     * Return the control port file
+     */
+    private File getConfigFile() {
+        final File configDir = new File(this.controlTarget.getHome(), "conf");
+        return new File(configDir, "controlport");
+    }
+
+    private InetSocketAddress getSocketAddress(String listenSpec) {
+        try {
+
+            final String address;
+            final int port;
+            if (listenSpec == null) {
+                address = DEFAULT_LISTEN_INTERFACE;
+                port = DEFAULT_LISTEN_PORT;
+            } else {
+                final int colon = listenSpec.indexOf(':');
+                if (colon < 0) {
+                    address = DEFAULT_LISTEN_INTERFACE;
+                    port = Integer.parseInt(listenSpec);
+                } else {
+                    address = listenSpec.substring(0, colon);
+                    port = Integer.parseInt(listenSpec.substring(colon + 1));
+                }
+            }
+
+            final InetSocketAddress addr = new InetSocketAddress(address, port);
+            if (!addr.isUnresolved()) {
+                return addr;
+            }
+
+            controlTarget.error("Unknown host in '" + listenSpec, null);
+        } catch (final NumberFormatException nfe) {
+            controlTarget.error("Cannot parse port number from '" + listenSpec + "'",
+                null);
+        }
+
+        return null;
+    }
+
+    private void writePortToConfigFile(final File configFile, final InetSocketAddress socketAddress,
+            final String secretKey) {
+        configFile.getParentFile().mkdirs();
+        FileWriter fw = null;
+        try {
+            fw = new FileWriter(configFile);
+            fw.write(socketAddress.getAddress().getHostAddress());
+            fw.write(':');
+            fw.write(String.valueOf(socketAddress.getPort()));
+            fw.write('\n');
+            fw.write(secretKey);
+            fw.write('\n');
+        } catch (final IOException ignore) {
+            // ignore
+        } finally {
+            if (fw != null) {
+                try {
+                    fw.close();
+                } catch (final IOException ignore) {
+                }
+            }
+        }
+    }
+}
diff --git a/sling-org-apache-sling-feature-starter/src/main/java/org/apache/sling/feature/starter/app/ControlTarget.java b/sling-org-apache-sling-feature-starter/src/main/java/org/apache/sling/feature/starter/app/ControlTarget.java
new file mode 100644
index 0000000..7611889
--- /dev/null
+++ b/sling-org-apache-sling-feature-starter/src/main/java/org/apache/sling/feature/starter/app/ControlTarget.java
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.feature.starter.app;
+
+public interface ControlTarget {
+
+    public String getHome();
+
+    public void doStop();
+
+    public void doTerminateVM(int status);
+
+    void info(String message, Throwable t);
+
+    void error(String message, Throwable t);
+}
diff --git a/sling-org-apache-sling-feature-starter/src/main/java/org/apache/sling/feature/starter/app/SlingStarter.java b/sling-org-apache-sling-feature-starter/src/main/java/org/apache/sling/feature/starter/app/SlingStarter.java
index 5518e1d..6959c05 100644
--- a/sling-org-apache-sling-feature-starter/src/main/java/org/apache/sling/feature/starter/app/SlingStarter.java
+++ b/sling-org-apache-sling-feature-starter/src/main/java/org/apache/sling/feature/starter/app/SlingStarter.java
@@ -17,14 +17,10 @@
 package org.apache.sling.feature.starter.app;
 
 import java.io.File;
-import java.io.PrintStream;
 import java.net.MalformedURLException;
 import java.net.URISyntaxException;
 import java.net.URL;
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
 import java.util.ArrayList;
-import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -34,14 +30,15 @@ import org.apache.sling.feature.launcher.impl.Main;
 import picocli.CommandLine;
 import picocli.CommandLine.Command;
 import picocli.CommandLine.Option;
+import picocli.CommandLine.Parameters;
 
 
 @Command(
-    name = "sfl",
+    name = "java -jar <Sling Feature Starter JAR File>",
     description = "Apache Sling Feature Starter",
     footer = "Copyright(c) 2019 The Apache Software Foundation."
 )
-public class SlingStarter implements Runnable {
+public class SlingStarter implements Runnable, ControlTarget {
 
     @Option(names = { "-s", "--mainFeature" }, description = "main feature file (file path or URL) replacing the provided Sling Feature File", required = false)
     private String mainFeatureFile;
@@ -87,6 +84,9 @@ public class SlingStarter implements Runnable {
     @Option(names = { "-h", "--help" }, usageHelp = true, description = "Display the usage message.")
     private boolean helpRequested;
 
+    @Parameters(paramLabel = "COMMAND", description = "Optional Command for Server Instance Interaction, can be one of: 'start', 'stop', 'status' or 'threads'", arity = "0..1")
+    private String command;
+
     // The name of the environment variable to consult to find out
     // about sling.home
     private static final String ENV_SLING_HOME = "SLING_HOME";
@@ -141,6 +141,7 @@ public class SlingStarter implements Runnable {
      */
     private static final String PROP_SHUTDOWN_HOOK = "sling.shutdown.hook";
 
+    private boolean started = false;
 
     @Override
     public void run() {
@@ -161,9 +162,10 @@ public class SlingStarter implements Runnable {
                     }
                 }
             }
-            if(StringUtils.isNotEmpty(controlAddress)) {
-                addArgument(argumentList, PROP_CONTROL_SOCKET, controlAddress);
-            }
+            //TODO: Remove because this is handled here so we do not need to pass it to the Feature Launcher
+//            if(StringUtils.isNotEmpty(controlAddress)) {
+//                addArgument(argumentList, PROP_CONTROL_SOCKET, controlAddress);
+//            }
             if(StringUtils.isNotEmpty(logLevel)) {
                 addArgument(argumentList, PROP_LOG_LEVEL, logLevel);
             }
@@ -183,7 +185,20 @@ public class SlingStarter implements Runnable {
                 argumentList.add("-v");
             }
             System.out.println("Before Launching Feature Launcher, arguments: " + argumentList);
-            Main.main(argumentList.toArray(new String[]{}));
+            // Now we have to handle any Start Option
+            ControlAction controlAction = getControlAction(command);
+            int answer = doControlAction(controlAction, controlAddress);
+            if (answer >= 0) {
+                doTerminateVM(answer);
+                return;
+            }
+
+            // finally start Sling
+            if (!doStart(argumentList)) {
+                error("Failed to start Sling; terminating", null);
+                doTerminateVM(1);
+                return;
+            }
         } catch(Throwable t) {
             System.out.println("Caught an Exception: " + t.getLocalizedMessage());
             t.printStackTrace();
@@ -222,4 +237,96 @@ public class SlingStarter implements Runnable {
         CommandLine.run(new SlingStarter(), args);
     }
 
+    private int doControlAction(ControlAction controlAction, String controlAddress) {
+//        if(controlAction != ControlAction.FOREGROUND) {
+            final ControlListener sl = new ControlListener(
+                this,
+                controlAddress
+            );
+            switch (controlAction) {
+                case FOREGROUND:
+                    if (!sl.listen()) {
+                        return -1;
+                    }
+                    break;
+                case START:
+                    if (!sl.listen()) {
+                        // assume service already running
+                        return 0;
+                    }
+                    break;
+                case STOP:
+                    return sl.shutdownServer();
+                case STATUS:
+                    return sl.statusServer();
+                case THREADS:
+                    return sl.dumpThreads();
+            }
+//        }
+        return -1;
+    }
+
+    private boolean doStart(List<String> argumentList) {
+        // prevent duplicate start
+        if ( this.started) {
+            info("Apache Sling has already been started", new Exception("Where did this come from"));
+            return true;
+        }
+
+        info("Starting Apache Sling in " + slingHome, null);
+        this.started = true;
+        System.out.println("Start Command: '" + command + "'");
+        try {
+            Main.main(argumentList.toArray(new String[]{}));
+        } catch(Error | RuntimeException e) {
+            error("Launching Sling Feature failed", e);
+            return false;
+        }
+        return true;
+    }
+
+    private ControlAction getControlAction(String command) {
+        ControlAction answer = ControlAction.FOREGROUND;
+        try {
+            answer = ControlAction.valueOf(command.toUpperCase());
+        } catch (IllegalArgumentException e) {
+            throw new RuntimeException("Given Control Action is not valid: '" + command.toUpperCase() + "'");
+        } catch (NullPointerException e) {
+            // Ignore as we set the default to FOREGROUND anyhow
+        }
+        return answer;
+    }
+
+    @Override
+    public String getHome() {
+        return slingHome;
+    }
+
+    @Override
+    public void doStop() {
+        info("Stop Application", null);
+        System.exit(0);
+    }
+
+    @Override
+    public void doTerminateVM(int status) {
+        info("Terminate VM, status: " + status, null);
+        System.exit(status);
+    }
+
+    @Override
+    public void info(String message, Throwable t) {
+        System.out.println(message);
+        if(t != null) {
+            t.printStackTrace();
+        }
+    }
+
+    @Override
+    public void error(String message, Throwable t) {
+        System.err.println(message);
+        if(t != null) {
+            t.printStackTrace(System.err);
+        }
+    }
 }
diff --git a/sling-slingstart-feature-maven-plugin/src/main/java/org/apache/sling/maven/slingstart/feature/launcher/Launcher.java b/sling-slingstart-feature-maven-plugin/src/main/java/org/apache/sling/maven/slingstart/feature/launcher/Launcher.java
index 668756c..0e3538f 100644
--- a/sling-slingstart-feature-maven-plugin/src/main/java/org/apache/sling/maven/slingstart/feature/launcher/Launcher.java
+++ b/sling-slingstart-feature-maven-plugin/src/main/java/org/apache/sling/maven/slingstart/feature/launcher/Launcher.java
@@ -30,11 +30,13 @@ public class Launcher implements LauncherMBean {
     private final int listenerPort;
 
     public Launcher(final int listenerPort) {
+        System.out.println("Launcher MBean created on port: " + listenerPort);
         this.listenerPort = listenerPort;
     }
 
     @Override
     public void startupFinished() {
+        System.out.println("Launcher MBean startup finished called, port: " + listenerPort);
         final List<String> hosts = new ArrayList<String>();
         hosts.add("localhost");
         hosts.add("127.0.0.1");
diff --git a/sling-slingstart-feature-maven-plugin/src/main/java/org/apache/sling/maven/slingstart/feature/launcher/Main.java b/sling-slingstart-feature-maven-plugin/src/main/java/org/apache/sling/maven/slingstart/feature/launcher/Main.java
index 9db0523..f7e4a80 100644
--- a/sling-slingstart-feature-maven-plugin/src/main/java/org/apache/sling/maven/slingstart/feature/launcher/Main.java
+++ b/sling-slingstart-feature-maven-plugin/src/main/java/org/apache/sling/maven/slingstart/feature/launcher/Main.java
@@ -27,6 +27,9 @@ import java.net.URL;
 import java.net.URLClassLoader;
 import java.util.Arrays;
 
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
 /**
  * Main class for launching Apache Sling.
  *
@@ -88,10 +91,10 @@ public class Main {
         final ClassLoader cl = new URLClassLoader(new URL[] {this.appJar.toURI().toURL()});
         Thread.currentThread().setContextClassLoader(cl);
 
-        // create and register mbean
-        final MBeanServer jmxServer = ManagementFactory.getPlatformMBeanServer();
-        jmxServer.registerMBean(new Launcher(this.listenerPort),
-                new ObjectName("org.apache.sling.feature.launchpad:type=Launcher"));
+//        // create and register mbean
+//        final MBeanServer jmxServer = ManagementFactory.getPlatformMBeanServer();
+//        jmxServer.registerMBean(new Launcher(this.listenerPort),
+//                new ObjectName("org.apache.sling.feature.launchpad:type=Launcher"));
 
         final Class<?> mainClass = cl.loadClass(MAIN_CLASS_DEF);
         final Method mainMethod = mainClass.getDeclaredMethod("main", String[].class);
@@ -102,8 +105,6 @@ public class Main {
         try {
             final Main m = new Main(args);
             m.run();
-        } catch(RuntimeException e) {
-            throw e;
         } catch ( final Exception e) {
             e.printStackTrace();
             System.exit(1);
diff --git a/sling-slingstart-feature-maven-plugin/src/main/java/org/apache/sling/maven/slingstart/feature/run/ControlClient.java b/sling-slingstart-feature-maven-plugin/src/main/java/org/apache/sling/maven/slingstart/feature/run/ControlClient.java
new file mode 100644
index 0000000..e627f38
--- /dev/null
+++ b/sling-slingstart-feature-maven-plugin/src/main/java/org/apache/sling/maven/slingstart/feature/run/ControlClient.java
@@ -0,0 +1,365 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.maven.slingstart.feature.run;
+
+import org.apache.maven.plugin.logging.Log;
+import org.apache.sling.feature.starter.app.ControlTarget;
+import org.slf4j.Logger;
+
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.LineNumberReader;
+import java.io.OutputStreamWriter;
+import java.lang.management.LockInfo;
+import java.lang.management.ManagementFactory;
+import java.lang.management.MonitorInfo;
+import java.lang.management.ThreadInfo;
+import java.lang.management.ThreadMXBean;
+import java.math.BigInteger;
+import java.net.ConnectException;
+import java.net.InetSocketAddress;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.security.SecureRandom;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * The <code>ControlListener</code> class is a helper class for the {@link ControlTarget}
+ * class to support in Sling standalone application process communication. This
+ * class implements the client and server sides of a TCP/IP based communication
+ * channel to control a running Sling application.
+ * <p>
+ * The server side listens for commands on a configurable host and port &endash;
+ * <code>localhost:63000</code> by default &endash; supporting the following
+ * commands:
+ * <table>
+ * <tr>
+ * <th>Command</th>
+ * <th>Description</th>
+ * </tr>
+ * <tr>
+ * <td><code>status</code></td>
+ * <td>Request status information. Currently only <i>OK</i> is sent back. If no
+ * connection can be created to the server the client assumes Sling is not
+ * running.</td>
+ * </tr>
+ * <tr>
+ * <td><code>stop</code></td>
+ * <td>Requests Sling to shutdown.</td>
+ * </tr>
+ * </table>
+ */
+public class ControlClient {
+
+    // command sent by the client to cause Sling to shutdown
+    static final String COMMAND_STOP = "stop";
+
+    // command sent by the client to check for the status of the server
+    static final String COMMAND_STATUS = "status";
+
+    // command sent by the client to request a thread dump
+    static final String COMMAND_THREADS = "threads";
+
+    // the response sent by the server if the command executed successfully
+    private static final String RESPONSE_OK = "OK";
+
+    // the status response sent by the server when shutting down
+    private static final String RESPONSE_STOPPING = "STOPPING";
+
+    // The default interface to listen on
+    private static final String DEFAULT_LISTEN_INTERFACE = "127.0.0.1";
+
+    // The default port to listen on and to connect to - we select it randomly
+    private static final int DEFAULT_LISTEN_PORT = 0;
+
+    private final String listenSpec;
+
+    private String secretKey;
+    private InetSocketAddress socketAddress;
+    private File directory;
+    private Log logger;
+
+    /**
+     * Creates an instance of this control support class.
+     * <p>
+     * The host (name or address) and port number of the socket is defined by
+     * the <code>listenSpec</code> parameter. This parameter is defined as
+     * <code>[ host ":" ] port</code>. If the parameter is empty or
+     * <code>null</code> it defaults to <i>localhost:0</i>. If the host name
+     * is missing it defaults to <i>localhost</i>.
+     *
+     * @param listenSpec The specification for the host and port for the socket
+     *            connection. See above for the format of this parameter.
+     */
+    public ControlClient(final String listenSpec, final File directory, Log logger) {
+        this.listenSpec = listenSpec; // socketAddress = this.getSocketAddress(listenSpec, selectNewPort);
+        this.directory = directory;
+        this.logger = logger;
+    }
+
+    public int getPort() {
+        return socketAddress != null ? socketAddress.getPort() : -1;
+    }
+
+    public boolean isStarted() {
+        Response response = sendCommand(COMMAND_STATUS);
+        return response.getCode() == 0 && "OK".equals(response.getResult());
+    }
+
+    /**
+     * Implements the client side of the control connection sending the command
+     * to shutdown Sling.
+     */
+    public int shutdownServer() { return sendCommand(COMMAND_STOP).getCode(); }
+
+    /**
+     * Implements the client side of the control connection sending the command
+     * to check whether Sling is active.
+     */
+    public int statusServer() {
+        return sendCommand(COMMAND_STATUS).getCode();
+    }
+
+    /**
+     * Implements the client side of the control connection sending the command
+     * to retrieve a thread dump.
+     */
+    public int dumpThreads() {
+        return sendCommand(COMMAND_THREADS).getCode();
+    }
+
+    /**
+     * Sends the given command to the server indicated by the configured
+     * socket address and logs the reply.
+     *
+     * @param command The command to send
+     *
+     * @return A code indicating success of sending the command.
+     */
+    private Response sendCommand(final String command) {
+        if (configure()) {
+            if (this.secretKey == null) {
+                logger.info("Missing secret key to protect sending '" + command + "' to " + this.socketAddress);
+                return new Response(4);
+            }
+
+            Socket socket = null;
+            try {
+                socket = new Socket();
+                socket.connect(this.socketAddress);
+                writeLine0(socket, this.secretKey + " " + command);
+                final String result = readLine(socket);
+                logger.info("Sent '" + command + "' to " + this.socketAddress + ": " + result);
+                return new Response(0, result);
+            } catch (final ConnectException ce) {
+                logger.info("No Apache Sling running at " + this.socketAddress);
+                return new Response(3, ce);
+            } catch (final IOException ioe) {
+                logger.error("Failed sending '" + command + "' to " + this.socketAddress, ioe);
+                return new Response(1, ioe);
+            } finally {
+                if (socket != null) {
+                    try {
+                        socket.close();
+                    } catch (IOException ignore) {
+                    }
+                }
+            }
+        }
+        logger.info("No socket address to send '" + command + "' to");
+        return new Response(4);
+    }
+
+    private String readLine(final Socket socket) throws IOException {
+        final BufferedReader br = new BufferedReader(new InputStreamReader(
+            socket.getInputStream(), "UTF-8"));
+
+        StringBuilder b = new StringBuilder();
+        boolean more = true;
+        while (more) {
+            String s = br.readLine();
+            if (s != null && s.startsWith("-")) {
+                s = s.substring(1);
+            } else {
+                more = false;
+            }
+            if (b.length() > 0) {
+                b.append("\r\n");
+            }
+            b.append(s);
+        }
+
+        return b.toString();
+    }
+
+//    private void writeLine(final Socket socket, final String line) throws IOException {
+//        logger.info(socket.getRemoteSocketAddress() + "<" + line);
+//        this.writeLine0(socket, line);
+//    }
+
+    private void writeLine0(final Socket socket, final String line) throws IOException {
+        final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(), "UTF-8"));
+        bw.write(line);
+        bw.write("\r\n");
+        bw.flush();
+    }
+
+    /**
+     * Read the port from the config file
+     * @return The port or null
+     */
+    private boolean configure() {
+        boolean result = false;
+        final File configFile = this.getConfigFile();
+        if (configFile.canRead()) {
+            try ( final LineNumberReader lnr = new LineNumberReader(new FileReader(configFile))) {
+                this.socketAddress = getSocketAddress(lnr.readLine());
+                this.secretKey = lnr.readLine();
+                result = true;
+            } catch (final IOException ignore) {
+                // ignore
+            }
+        }
+
+        return result;
+    }
+
+    private File getConfigFile() {
+        final File configDir = new File(directory, "conf");
+        return new File(configDir, "controlport");
+    }
+
+    /**
+     * Read the port from the config file
+     * @return The port or null
+     */
+    private boolean configure(final boolean fromConfigFile) {
+        this.socketAddress = getSocketAddress(this.listenSpec);
+        this.secretKey = generateKey();
+
+        return true;
+    }
+
+    private static String generateKey() {
+         return new BigInteger(165, new SecureRandom()).toString(32);
+    }
+
+    /**
+     * Return the control port file
+     */
+//    private File getConfigFile() {
+//        final File configDir = new File(this.controlTarget.getHome(), "conf");
+//        return new File(configDir, "controlport");
+//    }
+
+    private InetSocketAddress getSocketAddress(String listenSpec) {
+        try {
+
+            final String address;
+            final int port;
+            if (listenSpec == null) {
+                address = DEFAULT_LISTEN_INTERFACE;
+                port = DEFAULT_LISTEN_PORT;
+            } else {
+                final int colon = listenSpec.indexOf(':');
+                if (colon < 0) {
+                    address = DEFAULT_LISTEN_INTERFACE;
+                    port = Integer.parseInt(listenSpec);
+                } else {
+                    address = listenSpec.substring(0, colon);
+                    port = Integer.parseInt(listenSpec.substring(colon + 1));
+                }
+            }
+
+            final InetSocketAddress addr = new InetSocketAddress(address, port);
+            if (!addr.isUnresolved()) {
+                return addr;
+            }
+
+            logger.error("Unknown host in '" + listenSpec);
+        } catch (final NumberFormatException nfe) {
+            logger.error("Cannot parse port number from '" + listenSpec + "'");
+        }
+
+        return null;
+    }
+
+    private static class Response {
+        private int code;
+        private String result;
+        private Exception exception;
+
+        public Response(int code) {
+            this.code = code;
+        }
+
+        public Response(int code, String result) {
+            this.code = code;
+            this.result = result;
+        }
+
+        public Response(int code, Exception exception) {
+            this.code = code;
+            this.exception = exception;
+        }
+
+        public int getCode() {
+            return code;
+        }
+
+        public String getResult() {
+            return result;
+        }
+
+        public Exception getException() {
+            return exception;
+        }
+    }
+//    private void writePortToConfigFile(final File configFile, final InetSocketAddress socketAddress,
+//            final String secretKey) {
+//        configFile.getParentFile().mkdirs();
+//        FileWriter fw = null;
+//        try {
+//            fw = new FileWriter(configFile);
+//            fw.write(socketAddress.getAddress().getHostAddress());
+//            fw.write(':');
+//            fw.write(String.valueOf(socketAddress.getPort()));
+//            fw.write('\n');
+//            fw.write(secretKey);
+//            fw.write('\n');
+//        } catch (final IOException ignore) {
+//            // ignore
+//        } finally {
+//            if (fw != null) {
+//                try {
+//                    fw.close();
+//                } catch (final IOException ignore) {
+//                }
+//            }
+//        }
+//    }
+}
diff --git a/sling-slingstart-feature-maven-plugin/src/main/java/org/apache/sling/maven/slingstart/feature/run/LauncherCallable.java b/sling-slingstart-feature-maven-plugin/src/main/java/org/apache/sling/maven/slingstart/feature/run/LauncherCallable.java
index d05c4e4..89228e5 100644
--- a/sling-slingstart-feature-maven-plugin/src/main/java/org/apache/sling/maven/slingstart/feature/run/LauncherCallable.java
+++ b/sling-slingstart-feature-maven-plugin/src/main/java/org/apache/sling/maven/slingstart/feature/run/LauncherCallable.java
@@ -61,7 +61,7 @@ public class LauncherCallable implements Callable<ProcessDescription> {
      */
     @Override
     public ProcessDescription call() throws Exception {
-
+        logger.info("call() started");
         // fail if launchpad with this id is already started
         if (!ProcessDescriptionProvider.getInstance().isRunConfigurationAvailable(configuration.getId())) {
             throw new Exception("Launchpad with id " + configuration.getId() + " is not available");
@@ -84,13 +84,16 @@ public class LauncherCallable implements Callable<ProcessDescription> {
         // Add configuration to the config provider
         ProcessDescriptionProvider.getInstance().addRunConfiguration(cfg, launchpadKey);
 
+        logger.info("Before Check if started");
         boolean started = false;
         try {
             final long endTime = System.currentTimeMillis() + this.environment.getReadyTimeOutSec() * 1000;
             boolean finished = false;
             while ( !started && !finished && System.currentTimeMillis() < endTime ) {
                 Thread.sleep(5000);
-                started = cfg.getControlListener().isStarted();
+                logger.info("Ask Control Listener: " + cfg.getControlClient());
+                started = cfg.getControlClient().isStarted();
+                logger.info("Is Started: " + started);
                 try {
                     // if we get an exit value, the process has stopped
                     cfg.getProcess().exitValue();
@@ -100,6 +103,7 @@ public class LauncherCallable implements Callable<ProcessDescription> {
                 }
                 
             }
+            logger.info("Check Done, started: " + started + ", finihsed: " + finished);
 
             if ( finished ) {
                 throw new Exception("Launchpad did exit unexpectedly.");
@@ -121,7 +125,7 @@ public class LauncherCallable implements Callable<ProcessDescription> {
                     "' at port " + configuration.getPort()+ " [run modes: " + configuration.getRunmode()+ "]");
         } finally {
             // stop control port
-            cfg.getControlListener().stop();
+            cfg.getControlClient().shutdownServer();
 
             // call launchpad stop routine if not properly started
             if (!started) {
@@ -172,7 +176,12 @@ public class LauncherCallable implements Callable<ProcessDescription> {
     }
 
     private ProcessDescription start(final File jar) throws Exception {
-        final ProcessDescription cfg = new ProcessDescription(this.configuration.getId(), this.configuration.getFolder());
+        final ProcessDescription cfg = new ProcessDescription(
+            this.configuration.getId(),
+            this.configuration.getFolder(),
+            this.configuration.getServer() + ":" + this.configuration.getControlPort(),
+            logger
+        );
 
         final ProcessBuilder builder = new ProcessBuilder();
         final List<String> args = new ArrayList<String>();
@@ -189,7 +198,7 @@ public class LauncherCallable implements Callable<ProcessDescription> {
         args.add(Main.class.getName());
         // first three arguments: jar, listener port, verbose
         args.add(jar.getPath());
-        args.add(String.valueOf(cfg.getControlListener().getPort()));
+        args.add(String.valueOf(cfg.getControlClient().getPort()));
         args.add("true");
 
         // from here on launchpad properties
@@ -213,6 +222,7 @@ public class LauncherCallable implements Callable<ProcessDescription> {
         if ( this.configuration.getRunmode() != null && this.configuration.getRunmode().length() > 0 ) {
             args.add("-Dsling.run.modes=" + this.configuration.getRunmode());
         }
+        logger.info("Is Shutdown On Exit: " + this.environment.isShutdownOnExit());
         if ( !this.environment.isShutdownOnExit() ) {
             args.add("start");
         }
@@ -221,6 +231,7 @@ public class LauncherCallable implements Callable<ProcessDescription> {
         builder.directory(this.configuration.getFolder());
         builder.redirectErrorStream(true);
         logger.info("Starting Launchpad " + this.configuration.getId() +  "...");
+        logger.info("Starting Launchpad, arguments: " + args);
         String stdOutFile = this.configuration.getStdOutFile();
         if (StringUtils.isNotBlank(stdOutFile)) {
             File absoluteStdOutFile = new File(builder.directory(), stdOutFile);
@@ -361,8 +372,9 @@ public class LauncherCallable implements Callable<ProcessDescription> {
     }
 
     private static File getControlPortFile(final File directory) {
-        final File launchpadDir = new File(directory, LaunchpadEnvironment.WORK_DIR_NAME);
-        final File confDir = new File(launchpadDir, "conf");
+//        final File launchpadDir = new File(directory, LaunchpadEnvironment.WORK_DIR_NAME);
+//        final File confDir = new File(launchpadDir, "conf");
+        final File confDir = new File(directory, "conf");
         final File controlPortFile = new File(confDir, "controlport");
         return controlPortFile;
     }
diff --git a/sling-slingstart-feature-maven-plugin/src/main/java/org/apache/sling/maven/slingstart/feature/run/ProcessDescription.java b/sling-slingstart-feature-maven-plugin/src/main/java/org/apache/sling/maven/slingstart/feature/run/ProcessDescription.java
index ca8c563..ccda0be 100644
--- a/sling-slingstart-feature-maven-plugin/src/main/java/org/apache/sling/maven/slingstart/feature/run/ProcessDescription.java
+++ b/sling-slingstart-feature-maven-plugin/src/main/java/org/apache/sling/maven/slingstart/feature/run/ProcessDescription.java
@@ -17,6 +17,7 @@
 package org.apache.sling.maven.slingstart.feature.run;
 
 import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.logging.Log;
 
 import java.io.File;
 
@@ -27,13 +28,17 @@ public class ProcessDescription {
 
     private final String id;
     private final File directory;
-    private final ControlListener listener;
+    private final ControlClient controlClient;
     private volatile Process process;
 
-    public ProcessDescription(final String id, final File directory) throws MojoExecutionException {
+    public ProcessDescription(final String id, final File directory, String listenerSpec, Log logger) throws MojoExecutionException {
         this.id = id;
         this.directory = directory;
-        this.listener = new ControlListener(PortHelper.getNextAvailablePort());
+        this.controlClient = new ControlClient(
+            listenerSpec,
+            directory,
+            logger
+        );
     }
 
     public String getId() {
@@ -44,8 +49,8 @@ public class ProcessDescription {
         return directory;
     }
 
-    public ControlListener getControlListener() {
-        return this.listener;
+    public ControlClient getControlClient() {
+        return this.controlClient;
     }
 
     public Process getProcess() {
diff --git a/sling-slingstart-feature-maven-plugin/src/main/java/org/apache/sling/maven/slingstart/feature/run/StartMojo.java b/sling-slingstart-feature-maven-plugin/src/main/java/org/apache/sling/maven/slingstart/feature/run/StartMojo.java
index 1915303..f79bdd7 100644
--- a/sling-slingstart-feature-maven-plugin/src/main/java/org/apache/sling/maven/slingstart/feature/run/StartMojo.java
+++ b/sling-slingstart-feature-maven-plugin/src/main/java/org/apache/sling/maven/slingstart/feature/run/StartMojo.java
@@ -169,6 +169,7 @@ public class StartMojo extends AbstractStartStopMojo {
         final Collection<ServerConfiguration> configurations = getLaunchpadConfigurations();
 
         // create the common environment
+        getLog().info("Keep Launchpad Running: " + this.keepLaunchpadRunning);
         final LaunchpadEnvironment env = new LaunchpadEnvironment(this.findLaunchpadJar(),
                 this.cleanWorkingDirectory,
                 !this.keepLaunchpadRunning,