Commit 794e1085 authored by godog's avatar godog
Browse files

Fix chaperone for Python 3.7+

parent e1ffac6e
Pipeline #6544 passed with stage
in 1 minute and 14 seconds
FROM bitnami/minideb:buster
COPY build.sh /tmp/build.sh
COPY python37_compat.patch /tmp/python37_compat.patch
COPY chaperone.conf /etc/chaperone.d/chaperone.conf
COPY deb_autistici_org.gpg /etc/apt/trusted.gpg.d/
......
......@@ -5,7 +5,7 @@
# Packages that are only used to build the container. These will be
# removed once we're done.
BUILD_PACKAGES="python3-dev"
BUILD_PACKAGES="python3-dev patch"
# Packages required to serve the website and run the services.
# We have to keep the python3 packages around in order to run
......@@ -42,6 +42,11 @@ pip3 install chaperone \
|| die "could not install chaperone"
rm -fr /root/.cache/pip
# https://github.com/garywiz/chaperone/pull/27.patch
# async and await are reserved keywords starting with python 3.7
patch -d /usr/local/lib/$(py3versions -d)/dist-packages \
-p1 < /tmp/python37_compat.patch
# Users of this base image should provide their own Chaperone config.
#cp /tmp/conf/chaperone.conf /etc/chaperone.d/chaperone.conf
......
From a4206bb34ac454f3f5eea39a01d4f12ff3c0e981 Mon Sep 17 00:00:00 2001
From: necrophcodr <nc@scalehost.eu>
Date: Fri, 29 Nov 2019 09:22:14 +0100
Subject: [PATCH] Fix python.37 asyncio incompatability.
---
chaperone/cproc/commands.py | 4 ++--
chaperone/cproc/process_manager.py | 6 +++---
chaperone/cproc/pt/cron.py | 2 +-
chaperone/cproc/pt/inetd.py | 2 +-
chaperone/cproc/pt/simple.py | 2 +-
chaperone/cproc/subproc.py | 18 +++++++++---------
chaperone/cutil/notify.py | 2 +-
chaperone/cutil/syslog_handlers.py | 2 +-
chaperone/exec/sdnotify_exec.py | 6 +++---
9 files changed, 22 insertions(+), 22 deletions(-)
diff --git a/chaperone/cproc/commands.py b/chaperone/cproc/commands.py
index 2b7a0dd..7d0a7c4 100644
--- a/chaperone/cproc/commands.py
+++ b/chaperone/cproc/commands.py
@@ -224,11 +224,11 @@ def _command_task(self, cmd, interactive = False):
def data_received(self, data):
if self.interactive:
- asyncio.async(self._command_task(data.decode(), True))
+ asyncio.ensure_future(self._command_task(data.decode(), True))
else:
commands = data.decode().split("\n")
for c in commands:
- asyncio.async(self._command_task(c))
+ asyncio.ensure_future(self._command_task(c))
class _InteractiveServer(Server):
diff --git a/chaperone/cproc/process_manager.py b/chaperone/cproc/process_manager.py
index 0ac74e7..4fa28cc 100644
--- a/chaperone/cproc/process_manager.py
+++ b/chaperone/cproc/process_manager.py
@@ -229,7 +229,7 @@ def kill_system(self, errno = None, force = False):
warn("Request made to kill system." + ((force and " (forced)") or ""))
self._killing_system = True
- self._kill_future = asyncio.async(self._kill_system_co())
+ self._kill_future = asyncio.ensure_future(self._kill_system_co())
def _cancel_pending(self):
"Cancel any pending activated tasks"
@@ -289,7 +289,7 @@ def activate_result(self, future):
self._pending.discard(future)
def activate(self, cr):
- future = asyncio.async(cr)
+ future = asyncio.ensure_future(cr)
future.add_done_callback(self.activate_result)
self._pending.add(future)
return future
@@ -341,7 +341,7 @@ def run_event_loop(self, startup_coro = None, exit_when_done = True):
to tailor the environment and start up other services as needed.
"""
- initfuture = asyncio.async(self._start_system_services())
+ initfuture = asyncio.ensure_future(self._start_system_services())
initfuture.add_done_callback(lambda f: self._system_started(startup_coro, f))
self.loop.run_forever()
diff --git a/chaperone/cproc/pt/cron.py b/chaperone/cproc/pt/cron.py
index 803f289..e7e623c 100644
--- a/chaperone/cproc/pt/cron.py
+++ b/chaperone/cproc/pt/cron.py
@@ -93,7 +93,7 @@ def process_started_co(self):
# We have a successful start. Monitor this service.
- self._fut_monitor = asyncio.async(self._monitor_service())
+ self._fut_monitor = asyncio.ensure_future(self._monitor_service())
self.add_pending(self._fut_monitor)
@asyncio.coroutine
diff --git a/chaperone/cproc/pt/inetd.py b/chaperone/cproc/pt/inetd.py
index d9728da..48a7a96 100644
--- a/chaperone/cproc/pt/inetd.py
+++ b/chaperone/cproc/pt/inetd.py
@@ -17,7 +17,7 @@ def acquire_socket(self, sock):
self._fd = sock.detach()
sock.close()
- future = asyncio.async(self.start_socket_process(self._fd))
+ future = asyncio.ensure_future(self.start_socket_process(self._fd))
future.add_done_callback(self._done)
self.process.counter += 1
diff --git a/chaperone/cproc/pt/simple.py b/chaperone/cproc/pt/simple.py
index da8f258..c4548df 100644
--- a/chaperone/cproc/pt/simple.py
+++ b/chaperone/cproc/pt/simple.py
@@ -21,7 +21,7 @@ def process_started_co(self):
# We have a successful start. Monitor this service.
- self._fut_monitor = asyncio.async(self._monitor_service())
+ self._fut_monitor = asyncio.ensure_future(self._monitor_service())
self.add_pending(self._fut_monitor)
@asyncio.coroutine
diff --git a/chaperone/cproc/subproc.py b/chaperone/cproc/subproc.py
index eae1d9a..c432c7d 100644
--- a/chaperone/cproc/subproc.py
+++ b/chaperone/cproc/subproc.py
@@ -478,12 +478,12 @@ def start_subprocess(self):
self.pid = proc.pid
if service.stdout == 'log':
- self.add_pending(asyncio.async(_process_logger(proc.stdout, 'stdout', self)))
+ self.add_pending(asyncio.ensure_future(_process_logger(proc.stdout, 'stdout', self)))
if service.stderr == 'log':
- self.add_pending(asyncio.async(_process_logger(proc.stderr, 'stderr', self)))
+ self.add_pending(asyncio.ensure_future(_process_logger(proc.stderr, 'stderr', self)))
if service.exit_kills and not self.defer_exit_kills:
- self.add_pending(asyncio.async(self._wait_kill_on_exit()))
+ self.add_pending(asyncio.ensure_future(self._wait_kill_on_exit()))
yield from self.process_started_co()
@@ -574,7 +574,7 @@ def process_exit(self, code):
if code.normal_exit or self.kill_signal == code.signal:
return
- asyncio.async(self._abnormal_exit(code))
+ asyncio.ensure_future(self._abnormal_exit(code))
@asyncio.coroutine
def _abnormal_exit(self, code):
@@ -602,7 +602,7 @@ def _abnormal_exit(self, code):
if controller.system_alive:
yield from self.reset()
#yield from self.start()
- f = asyncio.async(self.start()) # queue it since we will just return here
+ f = asyncio.ensure_future(self.start()) # queue it since we will just return here
f.add_done_callback(self._restart_callback)
return
@@ -621,7 +621,7 @@ def _restart_callback(self, fut):
self.logdebug("{0} restart succeeded", self.name)
else:
self.logwarn("{0} restart failed: {1}", self.name, ex)
- asyncio.async(self._abnormal_exit(self._proc and self._proc.returncode))
+ asyncio.ensure_future(self._abnormal_exit(self._proc and self._proc.returncode))
def _kill_system(self):
self.family.controller.kill_system()
@@ -887,7 +887,7 @@ def start(self, service_names, force = False, wait = False, enable = False):
yield from s.reset(dependents=True, enable=enable, restarts_ok=True)
if not wait:
- asyncio.async(self._queued_start(slist, service_names))
+ asyncio.ensure_future(self._queued_start(slist, service_names))
else:
yield from self.run(slist)
@@ -909,7 +909,7 @@ def stop(self, service_names, force = False, wait = False, disable = False):
", ".join([s.shortname for s in slist if not s.stoppable]))
if not wait:
- asyncio.async(self._queued_stop(slist, service_names, disable))
+ asyncio.ensure_future(self._queued_stop(slist, service_names, disable))
else:
for s in slist:
yield from s.stop()
@@ -936,7 +936,7 @@ def reset(self, service_names, force = False, wait = False):
raise Exception("can't reset services which are running: " + ", ".join([s.shortname for s in running]))
if not wait:
- asyncio.async(self._queued_reset(slist, service_names))
+ asyncio.ensure_future(self._queued_reset(slist, service_names))
else:
for s in slist:
yield from s.reset(restarts_ok = True)
diff --git a/chaperone/cutil/notify.py b/chaperone/cutil/notify.py
index d942934..90c2827 100644
--- a/chaperone/cutil/notify.py
+++ b/chaperone/cutil/notify.py
@@ -153,7 +153,7 @@ def send(self, name, val):
self._sent.add(name)
if self._client:
debug("queueing '{0}={1}' to notify socket '{2}'".format(name, val, self._client.socket_name))
- asyncio.async(self._do_send("{0}={1}".format(name, val)))
+ asyncio.ensure_future(self._do_send("{0}={1}".format(name, val)))
@asyncio.coroutine
def _do_send(self, msg):
diff --git a/chaperone/cutil/syslog_handlers.py b/chaperone/cutil/syslog_handlers.py
index 044ba7f..78c215b 100644
--- a/chaperone/cutil/syslog_handlers.py
+++ b/chaperone/cutil/syslog_handlers.py
@@ -133,7 +133,7 @@ def setup_handler(self):
def __init__(self, config):
super().__init__(config)
- self._pending = asyncio.async(self.setup_handler())
+ self._pending = asyncio.ensure_future(self.setup_handler())
def write(self, data):
if self._protocol:
diff --git a/chaperone/exec/sdnotify_exec.py b/chaperone/exec/sdnotify_exec.py
index 6af1170..af5d3b8 100644
--- a/chaperone/exec/sdnotify_exec.py
+++ b/chaperone/exec/sdnotify_exec.py
@@ -175,7 +175,7 @@ def _do_proxy_send(self, name, value):
yield from self.parent_client.send("{0}={1}".format(name, value))
def send_to_proxy(self, name, value):
- asyncio.async(self._do_proxy_send(name, value))
+ asyncio.ensure_future(self._do_proxy_send(name, value))
def notify_received(self, which, name, value):
self.send_to_proxy(name, value)
@@ -217,7 +217,7 @@ def _run_process(self):
proc = yield from create
if self.timeout:
- asyncio.async(self._notify_timeout())
+ asyncio.ensure_future(self._notify_timeout())
exitcode = yield from proc.wait()
if not self.exitcode: # may have arrived from ERRNO
@@ -248,7 +248,7 @@ def main_entry():
options = docopt(__doc__, options_first=True, version=VERSION_MESSAGE)
mainclass = SDNotifyExec(options)
- asyncio.async(mainclass.run())
+ asyncio.ensure_future(mainclass.run())
loop.run_forever()
loop.close()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment