/*
 * 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.karaf.shell.osgi;

import org.apache.karaf.shell.console.OsgiCommandSupport;
import org.apache.felix.gogo.commands.Command;
import org.osgi.framework.Bundle;

/**
 * Command to shut down Karaf
 */
@Command(scope = "osgi", name = "shutdown", description = "Shuts the framework down.")
public class Shutdown extends OsgiCommandSupport {

    protected Object doExecute() throws Exception {
        new Thread() {
            public void run() {
                try {
                    Bundle bundle = getBundleContext().getBundle(0);
                    bundle.stop();
                } catch (Exception e) {
                    log.error("Error when shutting down Apache Karaf", e);
                }
            }
        }.start();
        return null;
    }

}

@@ -1203,16 +1203,622 @@
 ption %7B%0A
+        for (;;) %7B%0A            StringBuffer sb = new StringBuffer();%0A            System.err.println(%22Do you really want to shutdown (yes/no): %22);%0A            System.err.flush();%0A            for (;;) %7B%0A                int c = session.getKeyboard().read();%0A                if (c %3C 0) %7B%0A                    return null;%0A                %7D%0A                System.err.print((char) c);%0A                if (c == '%5Cr' %7C%7C c == '%5Cn') %7B%0A                    break;%0A                %7D%0A                sb.append((char) c);%0A            %7D%0A            String str = sb.toString();%0A            if (str.equals(%22yes%22)) %7B%0A        
         
@@ -1844,16 +1844,24 @@
         
+ 
+       
 public v
@@ -1892,14 +1892,30 @@
     
+    
+    
 try %7B%0A
+        
     
@@ -1999,16 +1999,24 @@
         
+        
 bundle.s
@@ -2038,16 +2038,24 @@
         
+  
+      
 %7D catch 
@@ -2066,24 +2066,32 @@
 eption e) %7B%0A
+        
             
@@ -2153,16 +2153,24 @@
 f%22, e);%0A
+        
         
@@ -2183,34 +2183,50 @@
   %7D%0A            
-%7D%0A
+        %7D%0A        
         %7D.start(
@@ -2224,24 +2224,42 @@
  %7D.start();%0A
+            %7D%0A    
         retu
@@ -2263,21 +2263,31 @@
 eturn null;%0A
+        %7D%0A
     %7D%0A%0A%7D%0A

Add confirmation message to osgi:shutdown command.