prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Docker container crashes if IPv6 is disabled at the system level.
  If listen [::] is found somewhere in the configs, but IPv6 is disabled at the host system level and in the docker, then the process crashes, and, accordingly, the docker container also crashes.
  
  This can be manually climbed into each container, corrected, but it is not very convenient.
  
  docker exec mailu_front_1 sed -i '/listen \[/d' /conf/nginx.conf
  docker exec mailu_front_1 sed -i '/listen \[/d' /etc/nginx/nginx.conf
  docker exec mailu_front_1 sed -i '/listen \[/d' /etc/nginx/http.d/default.conf
  docker restart mailu_front_1
  
  docker restart mailu_webdav_1 && docker exec -it mailu_webdav_1 sed -i 's/hosts =.*\[::\].*/hosts = 0.0.0.0:5232/g' /radicale.conf && docker restart mailu_webdav_1
  
  
  Can you add a container launch option to remove listen [::] from configs?
  
  </issue>
  <code>
  [start of core/admin/start.py]
  1 #!/usr/bin/env python3
  2 
  3 import os
  4 import logging as log
  5 import sys
  6 from socrate import system
  7 
  8 os.system("chown mailu:mailu -R /dkim")
  9 os.system("find /data | grep -v /fetchmail | xargs -n1 chown mailu:mailu")
  10 system.drop_privs_to('mailu')
  11 
  12 log.basicConfig(stream=sys.stderr, level=os.environ.get("LOG_LEVEL", "INFO"))
  13 system.set_env(['SECRET'])
  14 
  15 os.system("flask mailu advertise")
  16 os.system("flask db upgrade")
  17 
  18 account = os.environ.get("INITIAL_ADMIN_ACCOUNT")
  19 domain = os.environ.get("INITIAL_ADMIN_DOMAIN")
  20 password = os.environ.get("INITIAL_ADMIN_PW")
  21 
  22 if account is not None and domain is not None and password is not None:
  23     mode = os.environ.get("INITIAL_ADMIN_MODE", default="ifmissing")
  24     log.info("Creating initial admin account %s@%s with mode %s", account, domain, mode)
  25     os.system("flask mailu admin %s %s '%s' --mode %s" % (account, domain, password, mode))
  26 
  27 def test_DNS():
  28     import dns.resolver
  29     import dns.exception
  30     import dns.flags
  31     import dns.rdtypes
  32     import dns.rdatatype
  33     import dns.rdataclass
  34     import time
  35     # DNS stub configured to do DNSSEC enabled queries
  36     resolver = dns.resolver.Resolver()
  37     resolver.use_edns(0, dns.flags.DO, 1232)
  38     resolver.flags = dns.flags.AD | dns.flags.RD
  39     nameservers = resolver.nameservers
  40     for ns in nameservers:
  41         resolver.nameservers=[ns]
  42         while True:
  43             try:
  44                 result = resolver.resolve('example.org', dns.rdatatype.A, dns.rdataclass.IN, lifetime=10)
  45             except Exception as e:
  46                 log.critical("Your DNS resolver at %s is not working (%s). Please see https://mailu.io/master/faq.html#the-admin-container-won-t-start-and-its-log-says-critical-your-dns-resolver-isn-t-doing-dnssec-validation", ns, e)
  47             else:
  48                 if result.response.flags & dns.flags.AD:
  49                     break
  50                 log.critical("Your DNS resolver at %s isn't doing DNSSEC validation; Please see https://mailu.io/master/faq.html#the-admin-container-won-t-start-and-its-log-says-critical-your-dns-resolver-isn-t-doing-dnssec-validation.", ns)
  51             time.sleep(5)
  52 
  53 test_DNS()
  54 
  55 start_command=" ".join([
  56     "gunicorn",
  57     f"--threads {str(os.cpu_count())}",
  58     "-b :80",
  59     "--logger-class mailu.Logger",
  60     "--worker-tmp-dir /dev/shm",
  61     "--access-logfile -" if (log.root.level<=log.INFO) else "",
  62     "--error-logfile -",
  63     "--preload",
  64     "'mailu:create_app()'"])
  65 
  66 os.system(start_command)
  67
  [end of core/admin/start.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/core/admin/start.py b/core/admin/start.py
  --- a/core/admin/start.py
  +++ b/core/admin/start.py
  @@ -52,15 +52,21 @@
   
   test_DNS()
   
  -start_command=" ".join([
  -    "gunicorn",
  -    f"--threads {str(os.cpu_count())}",
  -    "-b :80",
  +cmdline = [
  +	"gunicorn",
  +	"--threads", f"{os.cpu_count()}",
  +	# If SUBNET6 is defined, gunicorn must listen on IPv6 as well as IPv4
  +	"-b", f"{'[::]' if os.environ.get('SUBNET6') else ''}:80",
       "--logger-class mailu.Logger",
       "--worker-tmp-dir /dev/shm",
  -    "--access-logfile -" if (log.root.level<=log.INFO) else "",
  -    "--error-logfile -",
  -    "--preload",
  -    "'mailu:create_app()'"])
  +	"--error-logfile", "-",
  +	"--preload"
  +]
   
  -os.system(start_command)
  +# logging
  +if log.root.level <= log.INFO:
  +	cmdline.extend(["--access-logfile", "-"])
  +
  +cmdline.append("'mailu:create_app()'")
  +
  +os.system(" ".join(cmdline))
  
verification_info: {"golden_diff": "diff --git a/core/admin/start.py b/core/admin/start.py\n--- a/core/admin/start.py\n+++ b/core/admin/start.py\n@@ -52,15 +52,21 @@\n \n test_DNS()\n \n-start_command=\" \".join([\n-    \"gunicorn\",\n-    f\"--threads {str(os.cpu_count())}\",\n-    \"-b :80\",\n+cmdline = [\n+\t\"gunicorn\",\n+\t\"--threads\", f\"{os.cpu_count()}\",\n+\t# If SUBNET6 is defined, gunicorn must listen on IPv6 as well as IPv4\n+\t\"-b\", f\"{'[::]' if os.environ.get('SUBNET6') else ''}:80\",\n     \"--logger-class mailu.Logger\",\n     \"--worker-tmp-dir /dev/shm\",\n-    \"--access-logfile -\" if (log.root.level<=log.INFO) else \"\",\n-    \"--error-logfile -\",\n-    \"--preload\",\n-    \"'mailu:create_app()'\"])\n+\t\"--error-logfile\", \"-\",\n+\t\"--preload\"\n+]\n \n-os.system(start_command)\n+# logging\n+if log.root.level <= log.INFO:\n+\tcmdline.extend([\"--access-logfile\", \"-\"])\n+\n+cmdline.append(\"'mailu:create_app()'\")\n+\n+os.system(\" \".join(cmdline))\n", "issue": "Docker container crashes if IPv6 is disabled at the system level.\nIf listen [::] is found somewhere in the configs, but IPv6 is disabled at the host system level and in the docker, then the process crashes, and, accordingly, the docker container also crashes.\r\n\r\nThis can be manually climbed into each container, corrected, but it is not very convenient.\r\n\r\ndocker exec mailu_front_1 sed -i '/listen \\[/d' /conf/nginx.conf\r\ndocker exec mailu_front_1 sed -i '/listen \\[/d' /etc/nginx/nginx.conf\r\ndocker exec mailu_front_1 sed -i '/listen \\[/d' /etc/nginx/http.d/default.conf\r\ndocker restart mailu_front_1\r\n\r\ndocker restart mailu_webdav_1 && docker exec -it mailu_webdav_1 sed -i 's/hosts =.*\\[::\\].*/hosts = 0.0.0.0:5232/g' /radicale.conf && docker restart mailu_webdav_1\r\n\r\n\r\nCan you add a container launch option to remove listen [::] from configs?\n", "before_files": [{"content": "#!/usr/bin/env python3\n\nimport os\nimport logging as log\nimport sys\nfrom socrate import system\n\nos.system(\"chown mailu:mailu -R /dkim\")\nos.system(\"find /data | grep -v /fetchmail | xargs -n1 chown mailu:mailu\")\nsystem.drop_privs_to('mailu')\n\nlog.basicConfig(stream=sys.stderr, level=os.environ.get(\"LOG_LEVEL\", \"INFO\"))\nsystem.set_env(['SECRET'])\n\nos.system(\"flask mailu advertise\")\nos.system(\"flask db upgrade\")\n\naccount = os.environ.get(\"INITIAL_ADMIN_ACCOUNT\")\ndomain = os.environ.get(\"INITIAL_ADMIN_DOMAIN\")\npassword = os.environ.get(\"INITIAL_ADMIN_PW\")\n\nif account is not None and domain is not None and password is not None:\n    mode = os.environ.get(\"INITIAL_ADMIN_MODE\", default=\"ifmissing\")\n    log.info(\"Creating initial admin account %s@%s with mode %s\", account, domain, mode)\n    os.system(\"flask mailu admin %s %s '%s' --mode %s\" % (account, domain, password, mode))\n\ndef test_DNS():\n    import dns.resolver\n    import dns.exception\n    import dns.flags\n    import dns.rdtypes\n    import dns.rdatatype\n    import dns.rdataclass\n    import time\n    # DNS stub configured to do DNSSEC enabled queries\n    resolver = dns.resolver.Resolver()\n    resolver.use_edns(0, dns.flags.DO, 1232)\n    resolver.flags = dns.flags.AD | dns.flags.RD\n    nameservers = resolver.nameservers\n    for ns in nameservers:\n        resolver.nameservers=[ns]\n        while True:\n            try:\n                result = resolver.resolve('example.org', dns.rdatatype.A, dns.rdataclass.IN, lifetime=10)\n            except Exception as e:\n                log.critical(\"Your DNS resolver at %s is not working (%s). Please see https://mailu.io/master/faq.html#the-admin-container-won-t-start-and-its-log-says-critical-your-dns-resolver-isn-t-doing-dnssec-validation\", ns, e)\n            else:\n                if result.response.flags & dns.flags.AD:\n                    break\n                log.critical(\"Your DNS resolver at %s isn't doing DNSSEC validation; Please see https://mailu.io/master/faq.html#the-admin-container-won-t-start-and-its-log-says-critical-your-dns-resolver-isn-t-doing-dnssec-validation.\", ns)\n            time.sleep(5)\n\ntest_DNS()\n\nstart_command=\" \".join([\n    \"gunicorn\",\n    f\"--threads {str(os.cpu_count())}\",\n    \"-b :80\",\n    \"--logger-class mailu.Logger\",\n    \"--worker-tmp-dir /dev/shm\",\n    \"--access-logfile -\" if (log.root.level<=log.INFO) else \"\",\n    \"--error-logfile -\",\n    \"--preload\",\n    \"'mailu:create_app()'\"])\n\nos.system(start_command)\n", "path": "core/admin/start.py"}]}