@Override
    protected void run(Environment environment, Namespace namespace, T configuration) throws Exception {
        final Server server = configuration.getServerFactory().build(environment);
        try {
            server.addEventListener(new LifeCycleListener());
            cleanupAsynchronously();
            server.start();
            new Thread(() -> {
                try {
                    server.join();
                } catch (InterruptedException e) {
                    Thread.currentThread().interrupt();
                }
            }, "dw-awaiter").start();
        } catch (Exception e) {
            LOGGER.error("Unable to start server, shutting down", e);
            try {
                server.stop();
            } catch (Exception e1) {
                LOGGER.warn("Failure during stop server", e1);
            }
            try {
                cleanup();
            } catch (Exception e2) {
                LOGGER.warn("Failure during cleanup", e2);
            }
            throw e;
        }
    }
@Test
    void stopsAServerIfThereIsAnErrorStartingIt() {
        this.throwException = true;
        server.addBean(new AbstractLifeCycle() {
            @Override
            protected void doStart() throws Exception {
                throw new IOException("oh crap");
            }
        });

        assertThatIOException()
            .isThrownBy(() -> command.run(environment, namespace, configuration))
            .withMessage("oh crap");

        assertThat(server.isStarted())
                .isFalse();
        this.throwException = false;
    }