sys-apps/fwupd: Update start/stop stanzas for fwupd.conf

This change alters when the daemon will be stopped. This will ensure
that we can complete a reboot even if the ui was stopped before the
service started.

BUG=b:191912505
TEST=reboot

Change-Id: Ib836daef45f704a7d8772d32903d96bb1be7d544
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/overlays/chromiumos-overlay/+/2989312
Tested-by: Daniel Campello <campello@chromium.org>
Auto-Submit: Daniel Campello <campello@chromium.org>
Commit-Queue: Daniel Campello <campello@chromium.org>
Commit-Queue: Benson Leung <bleung@google.com>
Reviewed-by: Benson Leung <bleung@google.com>
Reviewed-by: Sarthak Kukreti <sarthakkukreti@chromium.org>
diff --git a/sys-apps/fwupd/files/fwupd.conf b/sys-apps/fwupd/files/fwupd.conf
index f9e9a98..b6123ff 100644
--- a/sys-apps/fwupd/files/fwupd.conf
+++ b/sys-apps/fwupd/files/fwupd.conf
@@ -5,8 +5,8 @@
 description    "Fwupd daemon"
 author         "chromium-os-dev@chromium.org"
 
-# The service is started by Chrome via UpstartClient::StartAuthPolicyService().
-stop on stopping ui
+# The service is started via DBus activation.
+stop on stopping system-services
 respawn
 
 env CACHE_DIRECTORY="/var/cache/fwupd"
@@ -14,6 +14,15 @@
 pre-start script
   mkdir -p /var/cache/fwupd /var/lib/fwupd
   chown -R fwupd:fwupd /var/cache/fwupd /var/lib/fwupd
+
+  # Check if system-services is still running before starting.
+  # 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
+    logger -t "${UPSTART_JOB}" "ERROR: system services not running, quit."
+    stop
+    exit 0
+  fi
 end script
 
 script