Telneting into a Gogo shell seems like a very fragile solution. Why not write an application to support standard POSIX signal processing? Then you can just kill it with kill -s TERM <pid> .
For example, the following beam activator sets a disconnect hook that completely closes the framework, equivalent to stop 0 :
import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; import org.osgi.framework.launch.Framework; public class ShutdownHookActivator implements BundleActivator { @Override public void start(final BundleContext context) { Thread hook = new Thread() { @Override public void run() { System.out.println("Shutdown hook invoked, stopping OSGi Framework."); try { Framework systemBundle = context.getBundle(0).adapt(Framework.class); systemBundle.stop(); System.out.println("Waiting up to 2s for OSGi shutdown to complete..."); systemBundle.waitForStop(2000); } catch (Exception e) { System.err.println("Failed to cleanly shutdown OSGi Framework: " + e.getMessage()); e.printStackTrace(); } } }; System.out.println("Installing shutdown hook."); Runtime.getRuntime().addShutdownHook(hook); } @Override public void stop(BundleContext context) throws Exception { } }
NB: if you control the startup code that runs the OSGi Framework, you should probably set the shutdown tap, and not from a separate package.
Update
In bash, the variable $! evaluated as the PID of the last executed background command. You can save this in your own variable for later reference, for example:
# Launch app: java -jar ... & MY_PID=$!
source share