goofy: create instalog plugin

Use Goofy's plugin system to start and stop Instalog.  A config
file is generated on-the-fly and stored to RuntimeVariableDataPath
(/var/run in a test image, and /tmp/factory.$USER/run in chroot).

BUG=b:30450419
TEST=Manually on local machine

Change-Id: If7579f094a3f8d19aa966896dd60a93129815a64
Reviewed-on: https://chromium-review.googlesource.com/414689
Commit-Ready: Joel Kitching <kitching@chromium.org>
Tested-by: Joel Kitching <kitching@chromium.org>
Reviewed-by: Shun-Hsing Ou <shunhsingou@chromium.org>
diff --git a/py/instalog/cli.py b/py/instalog/cli.py
index 0bf677a..2c83a84 100755
--- a/py/instalog/cli.py
+++ b/py/instalog/cli.py
@@ -59,9 +59,11 @@
     logger = logging.getLogger()
     logger.setLevel(logging.DEBUG)
 
-    # A StreamHandler to stdout is created implicitly.  Since we want to create
-    # our own, we need to remove the default one.
-    logger.removeHandler(logger.handlers[0])
+    # In certain situations, a StreamHandler to stdout is created implicitly.
+    # Since we want to create our own, we need to remove the default one if it
+    # exists.
+    if logger.handlers:
+      logger.removeHandler(logger.handlers[0])
 
     # Create formatter.
     formatter = logging.Formatter(log_utils.LOG_FORMAT)
@@ -138,7 +140,8 @@
         os.path.join(os.path.dirname(os.path.realpath(__file__)),
                      'instalog.yaml'),
         os.path.join(os.path.expanduser('~'), '.instalog.yaml'),
-        os.path.join(os.sep, 'etc', 'instalog.yaml')]
+        os.path.join(os.sep, 'etc', 'instalog.yaml'),
+        os.path.join(os.sep, 'var', 'run', 'instalog.yaml')]
     for path in paths:
       logging.debug('Checking %s for config file...', path)
       if os.path.exists(path):
@@ -212,7 +215,7 @@
       '--config', '-c',
       help='config file path; by default, searches: \n'
            '$PWD/instalog.yaml py/instalog/instalog.yaml '
-           '~/.instalog.yaml /etc/instalog.yaml')
+           '~/.instalog.yaml /etc/instalog.yaml /var/run/instalog.yaml')
   parser.add_argument(
       '--verbose', '-v', action='count', default=0,
       help='increase verbosity')