]> kaliko git repositories - mpd-sima.git/blobdiff - launch
Add daemon
[mpd-sima.git] / launch
diff --git a/launch b/launch
index f03ca5b120fcc753dc6035914bef19f8aa0ccd22..13528b7559e769e1fa4929b6f1c7e7a339dcf082 100755 (executable)
--- a/launch
+++ b/launch
@@ -71,8 +71,9 @@ def main():
     sopt = StartOpt(info)
     # set logger
     verbosity = sopt.options.get('verbosity', 'warning')
+    logfile = sopt.options.get('logfile', None)
     cli_loglevel = getattr(logging, verbosity.upper())
-    set_logger(level=verbosity)
+    set_logger(level=verbosity, logfile=logfile)
     logger = logging.getLogger('sima')
     logger.setLevel(cli_loglevel)
     # loads configuration
@@ -102,21 +103,30 @@ def main():
 
     #  Loading contrib plugins
     load_contrib_plugins(sima)
+
+    # Run as a daemon
+    if config.getboolean('daemon', 'daemon'):
+        sima.start()
+
     try:
-        sima.run()
+        sima.foreground()
     except KeyboardInterrupt:
         logger.info('Caught KeyboardInterrupt, stopping')
-        sima.shutdown()
+        #sima.shutdown()
 
 
-# Script starts here
-if __name__ == '__main__':
+def run():
+    """Catching broad exception
+    """
     # pylint: disable=broad-except
     try:
         main()
     except Exception:
         exception_log()
 
+# Script starts here
+if __name__ == '__main__':
+    run()
 
 # VIM MODLINE
 # vim: ai ts=4 sw=4 sts=4 expandtab