- # Create the request handler
- operations = Operations(os.getuid(), os.getgid(), args.debug)
-
- if args.debug:
- arvados.config.settings()['ARVADOS_DEBUG'] = 'true'
+ # Daemonize as early as possible, so we don't accidentally close
+ # file descriptors we're using.
+ if not (args.exec_args or args.foreground):
+ os.chdir(args.mountpoint)
+ daemon_ctx = daemon.DaemonContext(working_directory='.')
+ daemon_ctx.open()
+ else:
+ daemon_ctx = None
+
+ # Set up logging.
+ # If we're daemonized without a logfile, there's nowhere to log, so don't.
+ if args.logfile or (daemon_ctx is None):
+ log_conf = {}
+ if args.debug:
+ log_conf['level'] = logging.DEBUG
+ arvados.config.settings()['ARVADOS_DEBUG'] = 'true'
+ if args.logfile:
+ log_conf['filename'] = args.logfile
+ logging.basicConfig(**log_conf)
+ logging.debug("arv-mount debugging enabled")