Repository: karaf
Updated Branches:
  refs/heads/master bf84b1749 -> b65f00fec


[KARAF-3367]add additional configuration options when use wrapper:install
(cherry picked from commit 72595e366b0d5783ba857183b92e37846ae9b93a)

Conflicts:
        wrapper/src/main/java/org/apache/karaf/wrapper/commands/Install.java


Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/b65f00fe
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/b65f00fe
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/b65f00fe

Branch: refs/heads/master
Commit: b65f00fec1ce927c3478824f849cdd533f058649
Parents: bf84b17
Author: Freeman Fang <[email protected]>
Authored: Tue Nov 18 15:35:57 2014 +0800
Committer: Freeman Fang <[email protected]>
Committed: Tue Nov 18 15:39:46 2014 +0800

----------------------------------------------------------------------
 .../apache/karaf/wrapper/WrapperService.java    | 13 ++++
 .../apache/karaf/wrapper/commands/Install.java  |  6 ++
 .../wrapper/internal/WrapperServiceImpl.java    | 76 +++++++++++++-------
 .../karaf/wrapper/management/WrapperMBean.java  | 14 ++++
 .../management/internal/WrapperMBeanImpl.java   |  8 +++
 5 files changed, 90 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/b65f00fe/wrapper/src/main/java/org/apache/karaf/wrapper/WrapperService.java
----------------------------------------------------------------------
diff --git a/wrapper/src/main/java/org/apache/karaf/wrapper/WrapperService.java 
b/wrapper/src/main/java/org/apache/karaf/wrapper/WrapperService.java
index fb05a16..78a0877 100644
--- a/wrapper/src/main/java/org/apache/karaf/wrapper/WrapperService.java
+++ b/wrapper/src/main/java/org/apache/karaf/wrapper/WrapperService.java
@@ -38,5 +38,18 @@ public interface WrapperService {
      * @return an array containing the wrapper configuration file (index 0) 
and the service file (index 1)
      */
     public File[] install(String name, String displayName, String description, 
String startType) throws Exception;
+    
+    /**
+     * Install the Karaf container as a system service in the OS.
+     *
+     * @param name The service name that will be used when installing the 
service.
+     * @param displayName The display name of the service.
+     * @param description The description of the service.
+     * @param startType Mode in which the service is installed. AUTO_START or 
DEMAND_START.
+     * @param envs The environment variable and values
+     * @param includes The include statement for JSW wrapper conf
+     * @return an array containing the wrapper configuration file (index 0) 
and the service file (index 1)
+     */
+    public File[] install(String name, String displayName, String description, 
String startType, String[] envs, String[] includes) throws Exception;
 
 }

http://git-wip-us.apache.org/repos/asf/karaf/blob/b65f00fe/wrapper/src/main/java/org/apache/karaf/wrapper/commands/Install.java
----------------------------------------------------------------------
diff --git 
a/wrapper/src/main/java/org/apache/karaf/wrapper/commands/Install.java 
b/wrapper/src/main/java/org/apache/karaf/wrapper/commands/Install.java
index 346f6f1..39771d6 100644
--- a/wrapper/src/main/java/org/apache/karaf/wrapper/commands/Install.java
+++ b/wrapper/src/main/java/org/apache/karaf/wrapper/commands/Install.java
@@ -46,6 +46,12 @@ public class Install implements Action {
 
        @Option(name = "-s", aliases = { "--start-type" }, description = "Mode 
in which the service is installed. AUTO_START or DEMAND_START (Default: 
AUTO_START)", required = false, multiValued = false)
        private String startType = "AUTO_START";
+       
+       @Option(name = "-e", aliases = {"--env"}, description = "Specify 
environment variable and values. To specify multiple environment variable and 
values, specify this flag multiple times.", required = false, multiValued = 
true)
+       private String[] envs;
+           
+       @Option(name = "-i", aliases = {"--include"}, description = "Specify 
include statement for JSW wrapper conf. To specify multiple include statement, 
specify this flag multiple times.", required = false, multiValued = true)
+       private String[] includes;
 
     @Reference
        private WrapperService wrapperService;

http://git-wip-us.apache.org/repos/asf/karaf/blob/b65f00fe/wrapper/src/main/java/org/apache/karaf/wrapper/internal/WrapperServiceImpl.java
----------------------------------------------------------------------
diff --git 
a/wrapper/src/main/java/org/apache/karaf/wrapper/internal/WrapperServiceImpl.java
 
b/wrapper/src/main/java/org/apache/karaf/wrapper/internal/WrapperServiceImpl.java
index ad4aa4a..ddeb770 100644
--- 
a/wrapper/src/main/java/org/apache/karaf/wrapper/internal/WrapperServiceImpl.java
+++ 
b/wrapper/src/main/java/org/apache/karaf/wrapper/internal/WrapperServiceImpl.java
@@ -39,7 +39,12 @@ public class WrapperServiceImpl implements WrapperService {
         install("karaf", "karaf", "", "AUTO_START");
     }
 
-    public File[] install(String name, String displayName, String description, 
String startType) throws Exception {
+    public File[] install(String name, 
+                          String displayName, 
+                          String description, 
+                          String startType,
+                          String[] envs,
+                          String[] includes) throws Exception {
 
         File base = new File(System.getProperty("karaf.base"));
         File etc = new File(System.getProperty("karaf.etc"));
@@ -74,8 +79,8 @@ public class WrapperServiceImpl implements WrapperService {
                 serviceFile = new File(bin, name + "-service.bat");
                 wrapperConf = new File(etc, name + "-wrapper.conf");
 
-                copyFilteredResourceTo(wrapperConf, 
"windows64/karaf-wrapper.conf", props);
-                copyFilteredResourceTo(serviceFile, 
"windows64/karaf-service.bat", props);
+                copyFilteredResourceTo(wrapperConf, 
"windows64/karaf-wrapper.conf", props, envs, includes);
+                copyFilteredResourceTo(serviceFile, 
"windows64/karaf-service.bat", props, envs, includes);
 
                 mkdir(lib);
                 copyResourceTo(new File(lib, "wrapper.dll"), 
"windows64/wrapper.dll", false);
@@ -87,8 +92,8 @@ public class WrapperServiceImpl implements WrapperService {
                 serviceFile = new File(bin, name + "-service.bat");
                 wrapperConf = new File(etc, name + "-wrapper.conf");
 
-                copyFilteredResourceTo(wrapperConf, 
"windows/karaf-wrapper.conf", props);
-                copyFilteredResourceTo(serviceFile, 
"windows/karaf-service.bat", props);
+                copyFilteredResourceTo(wrapperConf, 
"windows/karaf-wrapper.conf", props, envs, includes);
+                copyFilteredResourceTo(serviceFile, 
"windows/karaf-service.bat", props, envs, includes);
 
                 mkdir(lib);
                 copyResourceTo(new File(lib, "wrapper.dll"), 
"windows/wrapper.dll", false);
@@ -101,14 +106,14 @@ public class WrapperServiceImpl implements WrapperService 
{
             chmod(file, "a+x");
 
             serviceFile = new File(bin, name + "-service");
-            copyFilteredResourceTo(serviceFile, "unix/karaf-service", props);
+            copyFilteredResourceTo(serviceFile, "unix/karaf-service", props, 
envs, includes);
             chmod(serviceFile, "a+x");
 
             wrapperConf = new File(etc, name + "-wrapper.conf");
-            copyFilteredResourceTo(wrapperConf, "unix/karaf-wrapper.conf", 
props);
+            copyFilteredResourceTo(wrapperConf, "unix/karaf-wrapper.conf", 
props, envs, includes);
 
             File plistConf = new File(bin, "org.apache.karaf."+ name + 
".plist");
-            copyFilteredResourceTo(plistConf, 
"macosx/org.apache.karaf.KARAF.plist", props);
+            copyFilteredResourceTo(plistConf, 
"macosx/org.apache.karaf.KARAF.plist", props, envs, includes);
             
             mkdir(lib);
 
@@ -123,11 +128,11 @@ public class WrapperServiceImpl implements WrapperService 
{
                 chmod(file, "a+x");
 
                 serviceFile = new File(bin, name + "-service");
-                copyFilteredResourceTo(serviceFile, "unix/karaf-service", 
props);
+                copyFilteredResourceTo(serviceFile, "unix/karaf-service", 
props, envs, includes);
                 chmod(serviceFile, "a+x");
 
                 wrapperConf = new File(etc, name + "-wrapper.conf");
-                copyFilteredResourceTo(wrapperConf, "unix/karaf-wrapper.conf", 
props);
+                copyFilteredResourceTo(wrapperConf, "unix/karaf-wrapper.conf", 
props, envs, includes);
 
                 mkdir(lib);
                 copyResourceTo(new File(lib, "libwrapper.so"), 
"linux64/libwrapper.so", false);
@@ -139,11 +144,11 @@ public class WrapperServiceImpl implements WrapperService 
{
                 chmod(file, "a+x");
 
                 serviceFile = new File(bin, name + "-service");
-                copyFilteredResourceTo(serviceFile, "unix/karaf-service", 
props);
+                copyFilteredResourceTo(serviceFile, "unix/karaf-service", 
props, envs, includes);
                 chmod(serviceFile, "a+x");
 
                 wrapperConf = new File(etc, name + "-wrapper.conf");
-                copyFilteredResourceTo(wrapperConf, "unix/karaf-wrapper.conf", 
props);
+                copyFilteredResourceTo(wrapperConf, "unix/karaf-wrapper.conf", 
props, envs, includes);
 
                 mkdir(lib);
                 copyResourceTo(new File(lib, "libwrapper.so"), 
"linux/libwrapper.so", false);
@@ -158,11 +163,11 @@ public class WrapperServiceImpl implements WrapperService 
{
                 chmod(file, "a+x");
 
                 serviceFile = new File(bin, name + "-service");
-                copyFilteredResourceTo(serviceFile, "unix/karaf-service", 
props);
+                copyFilteredResourceTo(serviceFile, "unix/karaf-service", 
props, envs, includes);
                 chmod(serviceFile, "a+x");
 
                 wrapperConf = new File(etc, name + "-wrapper.conf");
-                copyFilteredResourceTo(wrapperConf, "unix/karaf-wrapper.conf", 
props);
+                copyFilteredResourceTo(wrapperConf, "unix/karaf-wrapper.conf", 
props, envs, includes);
 
                 mkdir(lib);
                 copyResourceTo(new File(lib, "libwrapper.a"), 
"aix/ppc64/libwrapper.a", false);
@@ -174,11 +179,11 @@ public class WrapperServiceImpl implements WrapperService 
{
                 chmod(file, "a+x");
 
                 serviceFile = new File(bin, name + "-service");
-                copyFilteredResourceTo(serviceFile, "unix/karaf-service", 
props);
+                copyFilteredResourceTo(serviceFile, "unix/karaf-service", 
props, envs, includes);
                 chmod(serviceFile, "a+x");
 
                 wrapperConf = new File(etc, name + "-wrapper.conf");
-                copyFilteredResourceTo(wrapperConf, "unix/karaf-wrapper.conf", 
props);
+                copyFilteredResourceTo(wrapperConf, "unix/karaf-wrapper.conf", 
props, envs, includes);
 
                 mkdir(lib);
                 copyResourceTo(new File(lib, "libwrapper.a"), 
"aix/ppc32/libwrapper.a", false);
@@ -193,11 +198,11 @@ public class WrapperServiceImpl implements WrapperService 
{
                 chmod(file, "a+x");
 
                 serviceFile = new File(bin, name + "-service");
-                copyFilteredResourceTo(serviceFile, "unix/karaf-service", 
props);
+                copyFilteredResourceTo(serviceFile, "unix/karaf-service", 
props, envs, includes);
                 chmod(serviceFile, "a+x");
 
                 wrapperConf = new File(etc, name + "-wrapper.conf");
-                copyFilteredResourceTo(wrapperConf, "unix/karaf-wrapper.conf", 
props);
+                copyFilteredResourceTo(wrapperConf, "unix/karaf-wrapper.conf", 
props, envs, includes);
 
                 mkdir(lib);
                 copyResourceTo(new File(lib, "libwrapper.so"), 
"solaris/sparc64/libwrapper.so", false);
@@ -209,11 +214,11 @@ public class WrapperServiceImpl implements WrapperService 
{
                 chmod(file, "a+x");
 
                 serviceFile = new File(bin, name + "-service");
-                copyFilteredResourceTo(serviceFile, "unix/karaf-service", 
props);
+                copyFilteredResourceTo(serviceFile, "unix/karaf-service", 
props, envs, includes);
                 chmod(serviceFile, "a+x");
 
                 wrapperConf = new File(etc, name + "-wrapper.conf");
-                copyFilteredResourceTo(wrapperConf, "unix/karaf-wrapper.conf", 
props);
+                copyFilteredResourceTo(wrapperConf, "unix/karaf-wrapper.conf", 
props, envs, includes);
 
                 mkdir(lib);
                 copyResourceTo(new File(lib, "libwrapper.so"), 
"solaris/x86/libwrapper.so", false);
@@ -225,11 +230,11 @@ public class WrapperServiceImpl implements WrapperService 
{
                 chmod(file, "a+x");
 
                 serviceFile = new File(bin, name + "-service");
-                copyFilteredResourceTo(serviceFile, "unix/karaf-service", 
props);
+                copyFilteredResourceTo(serviceFile, "unix/karaf-service", 
props, envs, includes);
                 chmod(serviceFile, "a+x");
 
                 wrapperConf = new File(etc, name + "-wrapper.conf");
-                copyFilteredResourceTo(wrapperConf, "unix/karaf-wrapper.conf", 
props);
+                copyFilteredResourceTo(wrapperConf, "unix/karaf-wrapper.conf", 
props, envs, includes);
 
                 mkdir(lib);
                 copyResourceTo(new File(lib, "libwrapper.so"), 
"solaris/x86_64/libwrapper.so", false);
@@ -241,11 +246,11 @@ public class WrapperServiceImpl implements WrapperService 
{
                 chmod(file, "a+x");
 
                 serviceFile = new File(bin, name + "-service");
-                copyFilteredResourceTo(serviceFile, "unix/karaf-service", 
props);
+                copyFilteredResourceTo(serviceFile, "unix/karaf-service", 
props, envs, includes);
                 chmod(serviceFile, "a+x");
 
                 wrapperConf = new File(etc, name + "-wrapper.conf");
-                copyFilteredResourceTo(wrapperConf, "unix/karaf-wrapper.conf", 
props);
+                copyFilteredResourceTo(wrapperConf, "unix/karaf-wrapper.conf", 
props, envs, includes);
 
                 mkdir(lib);
                 copyResourceTo(new File(lib, "libwrapper.so"), 
"solaris/sparc32/libwrapper.so", false);
@@ -258,11 +263,11 @@ public class WrapperServiceImpl implements WrapperService 
{
             chmod(file, "a+x");
 
             serviceFile = new File(bin, name + "-service");
-            copyFilteredResourceTo(serviceFile, "unix/karaf-service", props);
+            copyFilteredResourceTo(serviceFile, "unix/karaf-service", props, 
envs, includes);
             chmod(serviceFile, "a+x");
 
             wrapperConf = new File(etc, name + "-wrapper.conf");
-            copyFilteredResourceTo(wrapperConf, "unix/karaf-wrapper.conf", 
props);
+            copyFilteredResourceTo(wrapperConf, "unix/karaf-wrapper.conf", 
props, envs, includes);
 
             mkdir(lib);
             copyResourceTo(new File(lib, "libwrapper.sl"), 
"hpux/parisc64/libwrapper.sl", false);
@@ -339,7 +344,7 @@ public class WrapperServiceImpl implements WrapperService {
         }
     }
 
-    private void copyFilteredResourceTo(File outFile, String resource, 
HashMap<String, String> props) throws Exception {
+    private void copyFilteredResourceTo(File outFile, String resource, 
HashMap<String, String> props, String[] envs, String[] includes) throws 
Exception {
         if (!outFile.exists()) {
             LOGGER.info("Creating file: {}", outFile.getPath());
             System.out.println(Ansi.ansi().a("Creating file: ")
@@ -358,6 +363,18 @@ public class WrapperServiceImpl implements WrapperService {
                         line = filter(line, props);
                         out.println(line);
                     }
+                    if (outFile.getName().endsWith(".conf")) {
+                        if (envs != null && envs.length > 0) {
+                            for (String env : envs) {
+                                out.println(env);
+                            }
+                        }
+                        if (includes != null && includes.length > 0) {
+                            for (String include : includes) {
+                                out.println("#include " + include);
+                            }
+                        }
+                    }
                 } finally {
                     safeClose(out);
                 }
@@ -447,4 +464,9 @@ public class WrapperServiceImpl implements WrapperService {
         }
     }
 
+    @Override
+    public File[] install(String name, String displayName, String description, 
String startType) throws Exception {
+        return install(name, displayName, description, startType, null, null);
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/karaf/blob/b65f00fe/wrapper/src/main/java/org/apache/karaf/wrapper/management/WrapperMBean.java
----------------------------------------------------------------------
diff --git 
a/wrapper/src/main/java/org/apache/karaf/wrapper/management/WrapperMBean.java 
b/wrapper/src/main/java/org/apache/karaf/wrapper/management/WrapperMBean.java
index 937bfe2..8733b59 100644
--- 
a/wrapper/src/main/java/org/apache/karaf/wrapper/management/WrapperMBean.java
+++ 
b/wrapper/src/main/java/org/apache/karaf/wrapper/management/WrapperMBean.java
@@ -42,5 +42,19 @@ public interface WrapperMBean {
      * @throws MBeanException in case of installation failure.
      */
     File[] install(String name, String displayName, String description, String 
startType) throws MBeanException;
+    
+    /**
+     * Install the service wrapper.
+     *
+     * @param name the service name.
+     * @param displayName the service display name.
+     * @param description the service description.
+     * @param startType the start type.
+     * @param envs The environment variable and values
+     * @param includes The include statement for JSW wrapper conf
+     * @return the wrapper configuration (index 0) and service files (index 1).
+     * @throws MBeanException in case of installation failure.
+     */
+    File[] install(String name, String displayName, String description, String 
startType, String[] envs, String[] includes) throws MBeanException;
 
 }

http://git-wip-us.apache.org/repos/asf/karaf/blob/b65f00fe/wrapper/src/main/java/org/apache/karaf/wrapper/management/internal/WrapperMBeanImpl.java
----------------------------------------------------------------------
diff --git 
a/wrapper/src/main/java/org/apache/karaf/wrapper/management/internal/WrapperMBeanImpl.java
 
b/wrapper/src/main/java/org/apache/karaf/wrapper/management/internal/WrapperMBeanImpl.java
index 1523015..9be5b8e 100644
--- 
a/wrapper/src/main/java/org/apache/karaf/wrapper/management/internal/WrapperMBeanImpl.java
+++ 
b/wrapper/src/main/java/org/apache/karaf/wrapper/management/internal/WrapperMBeanImpl.java
@@ -58,5 +58,13 @@ public class WrapperMBeanImpl extends StandardMBean 
implements WrapperMBean {
             throw new MBeanException(null, e.getMessage());
         }
     }
+    
+    public File[] install(String name, String displayName, String description, 
String startType, String[] envs, String[] includes) throws MBeanException {
+        try {
+            return wrapperService.install(name, displayName, description, 
startType, envs, includes);
+        } catch (Exception e) {
+            throw new MBeanException(null, e.getMessage());
+        }
+    }
 
 }

Reply via email to