From 1da055f809105c744a7c44331ab2515360a5822f Mon Sep 17 00:00:00 2001 From: Clark Boylan Date: Thu, 6 Aug 2020 15:20:51 -0700 Subject: [PATCH] Add option to disable daemonization We are double forking in the docker image and that seems to confuse docker because the process it started has exited. Fix this by adding a --no-daemon option to gerritbot then set that in the dockerfile. This should run gerritbot without any additional forking. Change-Id: I048115da5362a883360dcaf40860022ed5b63d47 --- Dockerfile | 2 +- gerritbot/bot.py | 29 +++++++++++++++++------------ 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/Dockerfile b/Dockerfile index 814186a..0f154a2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -23,4 +23,4 @@ FROM opendevorg/python-base:3.7 as gerritbot COPY --from=builder /output/ /output RUN /output/install-from-bindep -CMD ["/usr/local/bin/gerritbot", "/etc/gerritbot/gerritbot.config"] +CMD ["/usr/local/bin/gerritbot", "--no-daemon", "/etc/gerritbot/gerritbot.config"] diff --git a/gerritbot/bot.py b/gerritbot/bot.py index c711d5b..a65fcfc 100755 --- a/gerritbot/bot.py +++ b/gerritbot/bot.py @@ -15,6 +15,7 @@ # License for the specific language governing permissions and limitations # under the License. +import argparse import configparser import daemon from ib3.auth import SASL @@ -24,7 +25,6 @@ import json import logging.config import os import re -import sys import threading import time import yaml @@ -471,21 +471,26 @@ def _main(config): def main(): - if len(sys.argv) != 2: - print("Usage: %s CONFIGFILE" % sys.argv[0]) - sys.exit(1) + parser = argparse.ArgumentParser() + parser.add_argument('config_file', help='Path to the config file file') + parser.add_argument('--no-daemon', dest='daemon', action='store_false', + help='Option to disable daemonization') + args = parser.parse_args() config = configparser.ConfigParser() - config.read(sys.argv[1]) + config.read(args.config_file) - pid_path = "" - if config.has_option('ircbot', 'pid'): - pid_path = config.get('ircbot', 'pid') + if args.daemon: + pid_path = "" + if config.has_option('ircbot', 'pid'): + pid_path = config.get('ircbot', 'pid') + else: + pid_path = "/var/run/gerritbot/gerritbot.pid" + + pid = pid_file_module.TimeoutPIDLockFile(pid_path, 10) + with daemon.DaemonContext(pidfile=pid): + _main(config) else: - pid_path = "/var/run/gerritbot/gerritbot.pid" - - pid = pid_file_module.TimeoutPIDLockFile(pid_path, 10) - with daemon.DaemonContext(pidfile=pid): _main(config)