monitor: Support for running with power off

Put in the remaining changes necessary so that fan monitor doesn't need
to be killed when power turns off.

This includes things like:
* Support for starting before the Present property is on D-Bus.
* Support for starting before the config file name is available.
* Stopping any running timers when power is turned off.
* Checking the power off rules when power turns on.

Most, but not all, of the changes are common between the JSON and YAML
modes, but this only truly supported when compiled for JSON.

This also removes the init vs monitor modes of operation, if compiled
for JSON.

Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: Ic2c6848f24511c9dc763227e05bbebb4c8c80cd1
diff --git a/monitor/power_off_rule.hpp b/monitor/power_off_rule.hpp
index 72d0052..3172bd5 100644
--- a/monitor/power_off_rule.hpp
+++ b/monitor/power_off_rule.hpp
@@ -76,35 +76,33 @@
      */
     void check(PowerRuleState state, const FanHealth& fanHealth)
     {
-        if (state == _validState)
+        auto satisfied = _cause->satisfied(fanHealth);
+
+        // Only start an action if it matches on the current state,
+        // but be able to stop it no matter what the state is.
+        if (!_active && satisfied && (state == _validState))
         {
-            auto satisfied = _cause->satisfied(fanHealth);
+            // Start the action
+            getLogger().log(
+                fmt::format("Starting shutdown action '{}' due to cause '{}'",
+                            _action->name(), _cause->name()));
 
-            if (!_active && satisfied)
+            _active = true;
+            _action->start();
+        }
+        else if (_active && !satisfied)
+        {
+            // Attempt to cancel the action, but don't force it
+            if (_action->cancel(false))
             {
-                // Start the action
-                getLogger().log(fmt::format(
-                    "Starting shutdown action '{}' due to cause '{}'",
-                    _action->name(), _cause->name()));
-
-                _active = true;
-                _action->start();
+                getLogger().log(fmt::format("Stopped shutdown action '{}'",
+                                            _action->name()));
+                _active = false;
             }
-            else if (_active && !satisfied)
+            else
             {
-                // Attempt to cancel the action, but don't force it
-                if (_action->cancel(false))
-                {
-                    getLogger().log(fmt::format("Stopped shutdown action '{}'",
-                                                _action->name()));
-                    _active = false;
-                }
-                else
-                {
-                    getLogger().log(
-                        fmt::format("Could not stop shutdown action '{}'",
-                                    _action->name()));
-                }
+                getLogger().log(fmt::format(
+                    "Could not stop shutdown action '{}'", _action->name()));
             }
         }
     }