Cleanly shutdown zuul scheduler if startup fails

At the moment, sys.exit is used to terminate the scheduler in case
an exception is thrown during startup phase. However, since not
all remaining threads were either daemonized or stopped, sys.exit
waited indefinitely. This change uses Scheduler.stop before exiting
so that all non-daemonized threads are terminated before exit.

Change-Id: I9e1a753e897276b0b0f5c1b5735d05f1cfa8f9f1
diff --git a/zuul/cmd/scheduler.py b/zuul/cmd/scheduler.py
index 68c9000..a3a53cf 100755
--- a/zuul/cmd/scheduler.py
+++ b/zuul/cmd/scheduler.py
@@ -159,6 +159,7 @@
             self.log.exception("Error starting Zuul:")
             # TODO(jeblair): If we had all threads marked as daemon,
             # we might be able to have a nicer way of exiting here.
+            self.sched.stop()
             sys.exit(1)
 
         signal.signal(signal.SIGHUP, self.reconfigure_handler)
diff --git a/zuul/scheduler.py b/zuul/scheduler.py
index 14ca029..de42aa3 100644
--- a/zuul/scheduler.py
+++ b/zuul/scheduler.py
@@ -230,6 +230,7 @@
         self.statsd = get_statsd(config)
         self.rpc = rpclistener.RPCListener(config, self)
         self.stats_thread = threading.Thread(target=self.runStats)
+        self.stats_thread.daemon = True
         self.stats_stop = threading.Event()
         # TODO(jeblair): fix this
         # Despite triggers being part of the pipeline, there is one trigger set