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
This commit is contained in:
Clark Boylan 2020-08-06 15:20:51 -07:00
parent a934f90f74
commit 1da055f809
2 changed files with 18 additions and 13 deletions

View File

@ -23,4 +23,4 @@ FROM opendevorg/python-base:3.7 as gerritbot
COPY --from=builder /output/ /output COPY --from=builder /output/ /output
RUN /output/install-from-bindep 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"]

View File

@ -15,6 +15,7 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import argparse
import configparser import configparser
import daemon import daemon
from ib3.auth import SASL from ib3.auth import SASL
@ -24,7 +25,6 @@ import json
import logging.config import logging.config
import os import os
import re import re
import sys
import threading import threading
import time import time
import yaml import yaml
@ -471,21 +471,26 @@ def _main(config):
def main(): def main():
if len(sys.argv) != 2: parser = argparse.ArgumentParser()
print("Usage: %s CONFIGFILE" % sys.argv[0]) parser.add_argument('config_file', help='Path to the config file file')
sys.exit(1) parser.add_argument('--no-daemon', dest='daemon', action='store_false',
help='Option to disable daemonization')
args = parser.parse_args()
config = configparser.ConfigParser() config = configparser.ConfigParser()
config.read(sys.argv[1]) config.read(args.config_file)
pid_path = "" if args.daemon:
if config.has_option('ircbot', 'pid'): pid_path = ""
pid_path = config.get('ircbot', 'pid') 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: else:
pid_path = "/var/run/gerritbot/gerritbot.pid"
pid = pid_file_module.TimeoutPIDLockFile(pid_path, 10)
with daemon.DaemonContext(pidfile=pid):
_main(config) _main(config)