package nl.jpoint.vertx.mod.cluster.command;

import nl.jpoint.vertx.mod.cluster.Constants;
import nl.jpoint.vertx.mod.cluster.request.ModuleRequest;
import nl.jpoint.vertx.mod.cluster.util.LogConstants;
import nl.jpoint.vertx.mod.cluster.util.ModuleFileNameFilter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.vertx.java.core.Vertx;
import org.vertx.java.core.json.JsonObject;

import java.io.File;
import java.io.IOException;

public class StopModule implements Command<ModuleRequest> {

    private static final Logger LOG = LoggerFactory.getLogger(StopModule.class);
    private final Vertx vertx;
    private final File modRoot;

    public StopModule(Vertx vertx, File modRoot) {
        this.vertx = vertx;
        this.modRoot = modRoot;
    }

    @Override
    public JsonObject execute(ModuleRequest request) {
        Process killProcess;
        final JsonObject result = new JsonObject();

        for (String file : modRoot.list(new ModuleFileNameFilter(request))) {
            LOG.info("[{} - {}]: Stopping module {}", LogConstants.DEPLOY_REQUEST, request.getId(), file);

            try {
                killProcess = Runtime.getRuntime().exec(new String[]{"/etc/init.d/vertx", "stop-module", file});
                killProcess.waitFor();
                result.putBoolean(Constants.STOP_STATUS, true);
            } catch (IOException | InterruptedException e) {
                LOG.error("[{} - {}]: Failed to stop module {}", LogConstants.DEPLOY_REQUEST, request.getId(), request.getModuleId());
                result.putBoolean(Constants.STOP_STATUS, false);
                return result;
            }
        }
        return result;
    }

}

@@ -395,16 +395,47 @@
 bject;%0A%0A
+import java.io.BufferedReader;%0A
 import j
@@ -474,16 +474,50 @@
 ception;
+%0Aimport java.io.InputStreamReader;
 %0A%0Apublic
@@ -983,16 +983,73 @@
 bject();
+%0A        result.putBoolean(Constants.STOP_STATUS, false);
 %0A%0A      
@@ -1315,16 +1315,24 @@
 tring%5B%5D%7B
+%22sudo%22, 
 %22/etc/in
@@ -1402,24 +1402,836 @@
 .waitFor();%0A
+                int exitValue = killProcess.exitValue();%0A                BufferedReader output = new BufferedReader(new InputStreamReader(killProcess.getInputStream()));%0A                String outputLine;%0A                while ((outputLine = output.readLine()) != null) %7B%0A                    LOG.info(%22%5B%7B%7D - %7B%7D%5D: %7B%7D%22, LogConstants.DEPLOY_REQUEST, request.getId(), outputLine);%0A                %7D%0A%0A                if (exitValue != 0) %7B%0A                    BufferedReader errorOut = new BufferedReader(new InputStreamReader(killProcess.getErrorStream()));%0A                    String errorLine;%0A                    while ((errorLine = errorOut.readLine()) != null) %7B%0A                        LOG.error(%22%5B%7B%7D - %7B%7D%5D: %7B%7D%22, LogConstants.DEPLOY_REQUEST, request.getId(), errorLine);%0A                    %7D%0A                %7D%0A
             
@@ -2482,73 +2482,8 @@
 ));%0A
-                result.putBoolean(Constants.STOP_STATUS, false);%0A
     

Add logging to stop process and use sudo