From a13ec193c8b01d7519844af5f33a97678b58c16b Mon Sep 17 00:00:00 2001 From: Tobias Henkel Date: Thu, 7 Feb 2019 22:17:48 +0100 Subject: [PATCH] Add foreground option The current options stated as 'do not run as a daemon' is actually 'run in debug mode in foreground'. When running in container we actually want an option for running normally in foreground. Thus add a new option -f for foreground operations and change the docker imaged to use this accordingly. Change-Id: I16173a73dbfb79dc2c2b05c2002ac41e20a48225 --- Dockerfile | 10 +++++----- doc/source/examples/docker-compose.yaml | 6 ++---- zuul/cmd/__init__.py | 17 ++++++++++++++--- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/Dockerfile b/Dockerfile index 93a99d0cd7..e1f3051843 100644 --- a/Dockerfile +++ b/Dockerfile @@ -60,16 +60,16 @@ COPY --from=builder /usr/local/lib/zuul/ /usr/local/lib/zuul COPY --from=builder /tmp/openshift-install/kubectl /usr/local/bin/kubectl COPY --from=builder /tmp/openshift-install/oc /usr/local/bin/oc -CMD ["/usr/local/bin/zuul-executor"] +CMD ["/usr/local/bin/zuul-executor", "-f"] FROM zuul as zuul-fingergw -CMD ["/usr/local/bin/zuul-fingergw"] +CMD ["/usr/local/bin/zuul-fingergw", "-f"] FROM zuul as zuul-merger -CMD ["/usr/local/bin/zuul-merger"] +CMD ["/usr/local/bin/zuul-merger", "-f"] FROM zuul as zuul-scheduler -CMD ["/usr/local/bin/zuul-scheduler"] +CMD ["/usr/local/bin/zuul-scheduler", "-f"] FROM zuul as zuul-web -CMD ["/usr/local/bin/zuul-web"] +CMD ["/usr/local/bin/zuul-web", "-f"] diff --git a/doc/source/examples/docker-compose.yaml b/doc/source/examples/docker-compose.yaml index 16ba24cade..839e9cf9e5 100644 --- a/doc/source/examples/docker-compose.yaml +++ b/doc/source/examples/docker-compose.yaml @@ -51,7 +51,7 @@ services: - https_proxy - no_proxy=${no_proxy},gerrit - ZUUL_MYSQL_PASSWORD=secret - command: "sh -c '/var/playbooks/wait-to-start.sh && zuul-scheduler -d'" + command: "sh -c '/var/playbooks/wait-to-start.sh && zuul-scheduler -f'" # FIXME: The scheduler has no ansible anymore so use the executor image. # This needs to be changes such that ansible is not required for startup. image: zuul/zuul-scheduler @@ -60,7 +60,7 @@ services: - "./playbooks/:/var/playbooks/:z" - "sshkey:/var/ssh:z" web: - command: "sh -c '/var/playbooks/wait-to-start-gearman.sh && zuul-web -d'" + command: "sh -c '/var/playbooks/wait-to-start-gearman.sh && zuul-web -f'" depends_on: - scheduler - mysql @@ -79,7 +79,6 @@ services: - https_proxy - no_proxy=${no_proxy},gerrit,scheduler - ZUUL_MYSQL_PASSWORD=secret - command: "zuul-executor -d" depends_on: - scheduler image: zuul/zuul-executor @@ -99,7 +98,6 @@ services: volumes: - "nodessh:/root/.ssh:z" launcher: - command: "nodepool-launcher -d" depends_on: - zk image: zuul/nodepool-launcher diff --git a/zuul/cmd/__init__.py b/zuul/cmd/__init__.py index 709c984303..9e5c6d40b1 100755 --- a/zuul/cmd/__init__.py +++ b/zuul/cmd/__init__.py @@ -120,6 +120,14 @@ class ZuulApp(object): def parseArguments(self, args=None): parser = self.createParser() self.args = parser.parse_args(args) + + # The arguments debug and foreground both lead to nodaemon mode so + # set nodaemon if one of them is set. + if ((hasattr(self.args, 'debug') and self.args.debug) or + (hasattr(self.args, 'foreground') and self.args.foreground)): + self.args.nodaemon = True + else: + self.args.nodaemon = False return parser def readConfig(self): @@ -148,12 +156,13 @@ class ZuulApp(object): # config, leave the config set to emit to stdout. if hasattr(self.args, 'nodaemon') and self.args.nodaemon: logging_config = logconfig.ServerLoggingConfig() - logging_config.setDebug() else: # Setting a server value updates the defaults to use # WatchedFileHandler on /var/log/zuul/{server}-debug.log # and /var/log/zuul/{server}.log logging_config = logconfig.ServerLoggingConfig(server=section) + if hasattr(self.args, 'debug') and self.args.debug: + logging_config.setDebug() logging_config.apply() def configure_connections(self, source_only=False, include_drivers=None): @@ -164,8 +173,10 @@ class ZuulApp(object): class ZuulDaemonApp(ZuulApp, metaclass=abc.ABCMeta): def createParser(self): parser = super(ZuulDaemonApp, self).createParser() - parser.add_argument('-d', dest='nodaemon', action='store_true', - help='do not run as a daemon') + parser.add_argument('-d', dest='debug', action='store_true', + help='run in foreground with debug log') + parser.add_argument('-f', dest='foreground', action='store_true', + help='run in foreground with info log') return parser def getPidFile(self):