static bool background = true;
 static void init_reload(void);
 static CONFIG *config;
+static bool test_config = false;
 
 /* Globals Exported */
 DIRRES *director;                     /* Director resource */
    int ch;
    JCR *jcr;
    bool no_signals = false;
-   bool test_config = false;
    char *uid = NULL;
    char *gid = NULL;
 
    stop_watchdog();
    generate_daemon_event(NULL, "Exit");
    unload_plugins();
-   write_state_file(director->working_directory, "bacula-dir", get_first_port_host_order(director->DIRaddrs));
-   delete_pid_file(director->pid_directory, "bacula-dir", get_first_port_host_order(director->DIRaddrs));
+   if (!test_config) {
+      write_state_file(director->working_directory, "bacula-dir", get_first_port_host_order(director->DIRaddrs));
+      delete_pid_file(director->pid_directory, "bacula-dir", get_first_port_host_order(director->DIRaddrs));
+   }
    term_scheduler();
    term_job_server();
    if (runjob) {
 
 #endif
 
 char *configfile = NULL;
+static bool test_config = false;
 static bool foreground = false;
 static workq_t dir_workq;             /* queue of work from Director */
 static pthread_t server_tid;
 int main (int argc, char *argv[])
 {
    int ch;
-   bool test_config = false;
    bool keep_readall_caps = false;
    char *uid = NULL;
    char *gid = NULL;
    bnet_stop_thread_server(server_tid);
    generate_daemon_event(NULL, "Exit");
    unload_plugins();
-   write_state_file(me->working_directory, "bacula-fd", get_first_port_host_order(me->FDaddrs));
-   delete_pid_file(me->pid_directory, "bacula-fd", get_first_port_host_order(me->FDaddrs));
+
+   if (!test_config) {
+      write_state_file(me->working_directory,
+                       "bacula-fd", get_first_port_host_order(me->FDaddrs));
+      delete_pid_file(me->pid_directory,
+                      "bacula-fd", get_first_port_host_order(me->FDaddrs));
+   }
 
    if (configfile != NULL) {
       free(configfile);
 
 pthread_mutex_t device_release_mutex = PTHREAD_MUTEX_INITIALIZER;
 pthread_cond_t wait_device_release = PTHREAD_COND_INITIALIZER;
 void *start_heap;
+static bool test_config = false;
 
 
 static uint32_t VolSessionId = 0;
 {
    int ch;
    bool no_signals = false;
-   bool test_config = false;
    pthread_t thid;
    char *uid = NULL;
    char *gid = NULL;
       bmicrosleep(0, 500000);         /* give them 1/2 sec to clean up */
    }
 
-   write_state_file(me->working_directory, "bacula-sd", get_first_port_host_order(me->sdaddrs));
-   delete_pid_file(me->pid_directory, "bacula-sd", get_first_port_host_order(me->sdaddrs));
+   if (!test_config) {
+      write_state_file(me->working_directory,
+                       "bacula-sd", get_first_port_host_order(me->sdaddrs));
+      delete_pid_file(me->pid_directory,
+                      "bacula-sd", get_first_port_host_order(me->sdaddrs));
+   }
 
    Dmsg1(200, "In terminate_stored() sig=%d\n", sig);