diff --git a/build.gradle b/build.gradle
index 2855cc5487d8eb490fecea9ddab45eadce432d46..5748c5f2df9725ce3a391a96fe1b01497b3963d5 100644
--- a/build.gradle
+++ b/build.gradle
@@ -31,7 +31,6 @@ task clean(type: Delete) {
     delete rootProject.buildDir
 }
 
-
 configure([project(':mailbox-core'), project(':mailbox-lib')]) {
     apply plugin: 'maven-publish'
 
diff --git a/mailbox-core/src/main/java/org/briarproject/mailbox/core/lifecycle/LifecycleManager.kt b/mailbox-core/src/main/java/org/briarproject/mailbox/core/lifecycle/LifecycleManager.kt
index a15d3b78ce61fe1a4a748f5c30ee95a27a5247e9..850e4bd05c7d3ec34c49fabc7514c655deeb3bdf 100644
--- a/mailbox-core/src/main/java/org/briarproject/mailbox/core/lifecycle/LifecycleManager.kt
+++ b/mailbox-core/src/main/java/org/briarproject/mailbox/core/lifecycle/LifecycleManager.kt
@@ -74,7 +74,10 @@ interface LifecycleManager {
      * registered [Services][Service].
      */
     @Wakeful
-    fun startServices(wipeHook: WipeHook = WipeHook { }): StartResult
+    fun startServices(
+        exitAfterStopping: Boolean = true,
+        wipeHook: WipeHook = WipeHook { },
+    ): StartResult
 
     /**
      * Stops any registered [Services][Service], shuts down any
diff --git a/mailbox-core/src/main/java/org/briarproject/mailbox/core/lifecycle/LifecycleManagerImpl.kt b/mailbox-core/src/main/java/org/briarproject/mailbox/core/lifecycle/LifecycleManagerImpl.kt
index c598732ba9a82b8ccf239479574864bfd2529e89..82ecbf59da50b381ceae2e9ceeacc54490553294 100644
--- a/mailbox-core/src/main/java/org/briarproject/mailbox/core/lifecycle/LifecycleManagerImpl.kt
+++ b/mailbox-core/src/main/java/org/briarproject/mailbox/core/lifecycle/LifecycleManagerImpl.kt
@@ -82,6 +82,7 @@ internal class LifecycleManagerImpl @Inject constructor(
     private val state = MutableStateFlow(NOT_STARTED)
 
     private var wipeHook: WipeHook? = null
+    private var exitAfterStopping: Boolean = true
 
     init {
         services = CopyOnWriteArrayList()
@@ -105,7 +106,7 @@ internal class LifecycleManagerImpl @Inject constructor(
     }
 
     @GuardedBy("startStopWipeSemaphore")
-    override fun startServices(wipeHook: WipeHook): StartResult {
+    override fun startServices(exitAfterStopping: Boolean, wipeHook: WipeHook): StartResult {
         LOG.info("startServices()")
         try {
             LOG.info("acquiring start stop semaphore")
@@ -121,6 +122,7 @@ internal class LifecycleManagerImpl @Inject constructor(
             return LIFECYCLE_REUSE
         }
         this.wipeHook = wipeHook
+        this.exitAfterStopping = exitAfterStopping
         return try {
             LOG.info("Opening database")
             var start = now()
@@ -215,7 +217,7 @@ internal class LifecycleManagerImpl @Inject constructor(
             // This is for the CLI where we might call stopServices() twice due to the shutdown
             // hook. In order to avoid a deadlock with calling exitProcess() from two threads, make
             // sure here that it gets called only once.
-            if (stopped) {
+            if (stopped && exitAfterStopping) {
                 LOG.info("Exiting")
                 exitProcess(0)
             }
diff --git a/mailbox-lib/src/main/java/org/briarproject/mailbox/lib/Mailbox.kt b/mailbox-lib/src/main/java/org/briarproject/mailbox/lib/Mailbox.kt
index 8bc80195e24384442f48c95cd91a762a1cd268d5..954a9a9dd98bd466dd37e53ea43c7a5731fbc141 100644
--- a/mailbox-lib/src/main/java/org/briarproject/mailbox/lib/Mailbox.kt
+++ b/mailbox-lib/src/main/java/org/briarproject/mailbox/lib/Mailbox.kt
@@ -76,9 +76,9 @@ class Mailbox {
         LOG.info { "Mailbox wiped successfully \\o/" }
     }
 
-    fun startLifecycle() {
+    fun startLifecycle(exitAfterStopping: Boolean) {
         LOG.info { "Starting lifecycle" }
-        lifecycleManager.startServices()
+        lifecycleManager.startServices(exitAfterStopping = exitAfterStopping)
         LOG.info { "Waiting for startup" }
         lifecycleManager.waitForStartup()
         LOG.info { "Startup finished" }
diff --git a/mailbox-lib/src/test/java/org/briarproject/mailbox/lib/MailboxLibTest.kt b/mailbox-lib/src/test/java/org/briarproject/mailbox/lib/MailboxLibTest.kt
index 610feb25b2adbbba28da93a78730c735e1857294..ad5cc9da1e6d6d6c691b67a0aa3ee90758946428 100644
--- a/mailbox-lib/src/test/java/org/briarproject/mailbox/lib/MailboxLibTest.kt
+++ b/mailbox-lib/src/test/java/org/briarproject/mailbox/lib/MailboxLibTest.kt
@@ -27,7 +27,7 @@ class MailboxLibTest {
     fun testStartStopMailbox() {
         val mailbox = Mailbox()
         mailbox.init()
-        mailbox.startLifecycle()
+        mailbox.startLifecycle(false)
         mailbox.waitForTorPublished()
         mailbox.stopLifecycle()
     }