CHROMIUM: tlsdated: Delegate dbus service activations to Upstart

Delegate dbus activation to Upstart to prevent tlsdated from
running during shutdown.

Additionally, after system-services has stopped, dbus can still
activate an instance of tlsdated via d-bus service activations.
Add a pre-start script to prevent the service from starting up
during shutdown.

BUG=chromium:1025914
TEST=none

Change-Id: Ic4a0570fab794b42c09578d6d1609135440b9524
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/tlsdate/+/2048135
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Reviewed-by: Jorge Lucangeli Obes <jorgelo@chromium.org>
Tested-by: Sarthak Kukreti <sarthakkukreti@chromium.org>
Commit-Queue: Sarthak Kukreti <sarthakkukreti@chromium.org>
diff --git a/dbus/org.torproject.tlsdate.service b/dbus/org.torproject.tlsdate.service
index 36ee56d..6d49cbf 100644
--- a/dbus/org.torproject.tlsdate.service
+++ b/dbus/org.torproject.tlsdate.service
@@ -1,3 +1,3 @@
 [D-BUS Service]
 Name=org.torproject.tlsdate
-Exec=/usr/bin/tlsdated
+Exec=/sbin/start tlsdated
diff --git a/init/tlsdated.conf b/init/tlsdated.conf
index e7a3ec8..2e0459a 100644
--- a/init/tlsdated.conf
+++ b/init/tlsdated.conf
@@ -25,6 +25,14 @@
   # TODO: We really should move the target of /etc/resolv.conf to a common
   # place that is independent of any daemon (such as "shill").
   mkdir -p /run/shill || true
+
+  # Check if system-services is still running before starting tlsdated.
+  # This is to prevent new dbus-activated instances from getting started once
+  # the system is beginning to shut down.
+  if ! initctl status system-services | grep -q running; then
+    stop
+    exit 0
+  fi
 end script
 
 # The various paths we bind mount: