in gshell/gshell-wrapper/src/main/java/org/apache/servicemix/kernel/gshell/wrapper/InstallCommand.java [50:207]
protected Object doExecute() throws Exception {
try {
String name = getName();
File base = new File(System.getProperty("servicemix.base"));
File bin = new File(base, "bin");
File etc = new File(base, "etc");
File lib = new File(base, "lib");
HashMap<String, String> props = new HashMap<String, String>();
props.put("${servicemix.home}", System.getProperty("servicemix.home"));
props.put("${servicemix.base}", base.getPath());
props.put("${name}", name);
props.put("${displayName}", getDisplayName());
props.put("${description}", getDescription());
props.put("${startType}", getStartType());
String os = System.getProperty("os.name", "Unknown");
File serviceFile=null;
if( os.startsWith("Win") ) {
mkdir(bin);
copyResourceTo(new File(bin, name+"-wrapper.exe"), "windows/servicemix-wrapper.exe", false);
serviceFile = new File(bin,name+"-service.bat");
copyFilteredResourceTo(serviceFile, "windows/servicemix-service.bat", props);
mkdir(lib);
copyResourceTo(new File(bin, "wrapper.dll"), "windows/wrapper.dll", false);
} else if( os.startsWith("Mac OS X") ) {
mkdir(bin);
File file = new File(bin, name+"-wrapper");
copyResourceTo(file, "macosx/servicemix-wrapper", false);
chmod(file, "a+x");
serviceFile = new File(bin,name+"-service");
copyFilteredResourceTo(serviceFile, "unix/servicemix-service", props);
chmod(serviceFile, "a+x");
mkdir(lib);
copyResourceTo(new File(lib, "libwrapper.jnilib"), "macosx/libwrapper.jnilib", false);
// TODO: figure out how to hook in the service that it starts up
// when the machine boots up.
} else if( os.startsWith("Linux") ) {
mkdir(bin);
File file = new File(bin, name+"-wrapper");
copyResourceTo(file, "linux/servicemix-wrapper", false);
chmod(file, "a+x");
serviceFile = new File(bin,name+"-service");
copyFilteredResourceTo(serviceFile, "unix/servicemix-service", props);
chmod(serviceFile, "a+x");
mkdir(lib);
copyResourceTo(new File(lib, "libwrapper.so"), "linux/libwrapper.so", false);
// TODO: figure out how to hook in the service that it starts up
// when the machine boots up.
} else {
io.out.println("Your operating system '"+os+"' is not currently supported.");
return 1;
}
// Install the wrapper jar to the lib directory..
mkdir(lib);
copyResourceTo(new File(lib, "servicemix-wrapper.jar"), "all/servicemix-wrapper.jar", false);
mkdir(etc);
File wrapperConf = new File(etc,name+"-wrapper.conf");
copyFilteredResourceTo(wrapperConf, "all/servicemix-wrapper.conf", props);
io.out.println("");
io.out.println("Setup complete. You may want to tweak the JVM properties in the wrapper configuration file: "+wrapperConf.getPath());
io.out.println("before installing and starting the service.");
io.out.println("");
if( os.startsWith("Win") ) {
io.out.println("");
io.out.println("To install the service, run: ");
io.out.println(" C:> "+serviceFile.getPath()+" install");
io.out.println("");
io.out.println("Once installed, to start the service run: ");
io.out.println(" C:> net start \""+name+"\"");
io.out.println("");
io.out.println("Once running, to stop the service run: ");
io.out.println(" C:> net stop \""+name+"\"");
io.out.println("");
io.out.println("Once stopped, to remove the installed the service run: ");
io.out.println(" C:> "+serviceFile.getPath()+" remove");
io.out.println("");
} else if( os.startsWith("Mac OS X") ) {
io.out.println("");
io.out.println("At this time it is not known how to get this service to start when the machine is rebooted.");
io.out.println("If you know how to install the following service script so that it gets started");
io.out.println("when OS X starts, please email dev@servicemix.apache.org and let us know how so");
io.out.println("we can update this message.");
io.out.println(" ");
io.out.println(" To start the service:");
io.out.println(" $ "+serviceFile.getPath()+" start");
io.out.println("");
io.out.println(" To stop the service:");
io.out.println(" $ "+serviceFile.getPath()+" stop");
io.out.println("");
} else if( os.startsWith("Linux") ) {
io.out.println("The way the service is installed depends upon your flavor of Linux.");
// TODO: figure out if we can detect the Linux flavor
io.out.println("");
io.out.println("@|cyan On Redhat/Fedora/CentOS Systems:|");
io.out.println(" To install the service:");
io.out.println(" $ ln -s "+serviceFile.getPath()+" /etc/init.d/");
io.out.println(" $ chkconfig "+serviceFile.getName()+" --add");
io.out.println("");
io.out.println(" To start the service when the machine is rebooted:");
io.out.println(" $ chkconfig "+serviceFile.getName()+" on");
io.out.println("");
io.out.println(" To disable starting the service when the machine is rebooted:");
io.out.println(" $ chkconfig "+serviceFile.getName()+" off");
io.out.println("");
io.out.println(" To start the service:");
io.out.println(" $ service "+serviceFile.getName()+" start");
io.out.println("");
io.out.println(" To stop the service:");
io.out.println(" $ service "+serviceFile.getName()+" stop");
io.out.println("");
io.out.println(" To uninstall the service :");
io.out.println(" $ chkconfig "+serviceFile.getName()+" --del");
io.out.println(" $ rm /etc/init.d/"+serviceFile.getName());
io.out.println("");
io.out.println("@|cyan On Ubuntu/Debian Systems:|");
io.out.println(" To install the service:");
io.out.println(" $ ln -s "+serviceFile.getPath()+" /etc/init.d/");
io.out.println("");
io.out.println(" To start the service when the machine is rebooted:");
io.out.println(" $ update-rc.d "+serviceFile.getName()+" defaults");
io.out.println("");
io.out.println(" To disable starting the service when the machine is rebooted:");
io.out.println(" $ update-rc.d -f "+serviceFile.getName()+" remove");
io.out.println("");
io.out.println(" To start the service:");
io.out.println(" $ /etc/init.d/"+serviceFile.getName()+" start");
io.out.println("");
io.out.println(" To stop the service:");
io.out.println(" $ /etc/init.d/"+serviceFile.getName()+" stop");
io.out.println("");
io.out.println(" To uninstall the service :");
io.out.println(" $ rm /etc/init.d/"+serviceFile.getName());
}
} catch (Exception e) {
e.printStackTrace();
throw e;
}
return 0;
}