From 4b9cc76bd57e69846816d7563624455e1fcd7f53 Mon Sep 17 00:00:00 2001 From: J-E Castagnede Date: Wed, 22 Nov 2023 17:29:32 +0100 Subject: [PATCH 1/7] fix subprocess remaining --- src/screenshotter/puppeteer.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/screenshotter/puppeteer.py b/src/screenshotter/puppeteer.py index 7e354f56..381f59da 100644 --- a/src/screenshotter/puppeteer.py +++ b/src/screenshotter/puppeteer.py @@ -1,5 +1,6 @@ import json import os +import signal import subprocess from tempfile import NamedTemporaryFile @@ -51,9 +52,10 @@ def take_screenshot(url, width=1920, height=1080, waitfor='body', wait_selectors screamshotter_css_class, '--headers', json.dumps(forward_headers), - ], stderr=subprocess.PIPE, env=os.environ) + ], stderr=subprocess.PIPE, env=os.environ, preexec_fn=os.setsid) if command.stderr: raise ScreenshotterException(command.stderr.decode()) + os.killpg(os.getpgid(command.pid), signal.SIGTERM) return screenshot_file.read() From 7be71bd4fadaf3c113fa507884008e89a093cf65 Mon Sep 17 00:00:00 2001 From: J-E Castagnede Date: Thu, 23 Nov 2023 09:36:39 +0100 Subject: [PATCH 2/7] fix subprocess remaining --- src/screenshotter/puppeteer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/screenshotter/puppeteer.py b/src/screenshotter/puppeteer.py index 381f59da..4e7fc351 100644 --- a/src/screenshotter/puppeteer.py +++ b/src/screenshotter/puppeteer.py @@ -19,7 +19,7 @@ def take_screenshot(url, width=1920, height=1080, waitfor='body', wait_selectors # We send sentry informations and version : when we use screamshotter as a package, informations are in settings only with NamedTemporaryFile(suffix='.png') as screenshot_file: - command = subprocess.run([ + command = subprocess.Popen([ os.getenv('NODE_BIN_PATH', 'node'), app_settings.PUPPETEER_JAVASCRIPT_FILEPATH, '--version', From 445f6742a521576da56a3e92a5f4a830f3f8f71d Mon Sep 17 00:00:00 2001 From: J-E Castagnede Date: Thu, 23 Nov 2023 09:44:34 +0100 Subject: [PATCH 3/7] fix subprocess remaining --- debian/control | 1 + src/screenshotter/puppeteer.py | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/debian/control b/debian/control index 56d9d693..dcfa5b99 100644 --- a/debian/control +++ b/debian/control @@ -20,6 +20,7 @@ Depends: ${misc:Depends}, ${shlibs:Depends}, gettext, + dumb-init, python3 (>= 3.6), libappindicator3-1, libasound2, diff --git a/src/screenshotter/puppeteer.py b/src/screenshotter/puppeteer.py index 4e7fc351..b5f34002 100644 --- a/src/screenshotter/puppeteer.py +++ b/src/screenshotter/puppeteer.py @@ -19,7 +19,10 @@ def take_screenshot(url, width=1920, height=1080, waitfor='body', wait_selectors # We send sentry informations and version : when we use screamshotter as a package, informations are in settings only with NamedTemporaryFile(suffix='.png') as screenshot_file: - command = subprocess.Popen([ + command = subprocess.run([ + "/usr/local/bin/dumb-init", + "--dumb-init", + "--", os.getenv('NODE_BIN_PATH', 'node'), app_settings.PUPPETEER_JAVASCRIPT_FILEPATH, '--version', @@ -52,10 +55,9 @@ def take_screenshot(url, width=1920, height=1080, waitfor='body', wait_selectors screamshotter_css_class, '--headers', json.dumps(forward_headers), - ], stderr=subprocess.PIPE, env=os.environ, preexec_fn=os.setsid) + ], stderr=subprocess.PIPE, env=os.environ) if command.stderr: raise ScreenshotterException(command.stderr.decode()) - os.killpg(os.getpgid(command.pid), signal.SIGTERM) return screenshot_file.read() From fc068b752871a30491d620ddd8945a4dee53d858 Mon Sep 17 00:00:00 2001 From: J-E Castagnede Date: Thu, 23 Nov 2023 09:58:57 +0100 Subject: [PATCH 4/7] fix subprocess remaining --- src/screenshotter/puppeteer.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/screenshotter/puppeteer.py b/src/screenshotter/puppeteer.py index b5f34002..23394dc4 100644 --- a/src/screenshotter/puppeteer.py +++ b/src/screenshotter/puppeteer.py @@ -1,6 +1,5 @@ import json import os -import signal import subprocess from tempfile import NamedTemporaryFile From 364a24ad5417b76037640b970aa5ad671bd0a3a4 Mon Sep 17 00:00:00 2001 From: J-E Castagnede Date: Thu, 23 Nov 2023 10:20:20 +0100 Subject: [PATCH 5/7] fix subprocess remaining --- Dockerfile | 4 +--- src/screenshotter/puppeteer.py | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index d2235f43..cc133230 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,6 +13,7 @@ RUN mkdir -p /app/static RUN chown django:django /app RUN apt-get -qq update && apt-get install -qq -y \ + dumb-init \ gconf-service \ libasound2 \ libatk1.0-0 \ @@ -103,8 +104,6 @@ COPY --from=build /app/node_modules /app/node_modules COPY src /app/src RUN mkdir -p /app/static && chown django:django /app/static -ADD https://github.com/Yelp/dumb-init/releases/download/v1.2.2/dumb-init_1.2.2_x86_64 /usr/local/bin/dumb-init -RUN chmod +x /usr/local/bin/dumb-init RUN apt-get -qq update && apt-get upgrade -qq -y && \ apt-get clean all && rm -rf /var/apt/lists/* && rm -rf /var/cache/apt/* @@ -113,6 +112,5 @@ VOLUME /app/static USER django -ENTRYPOINT ["dumb-init", "--", "/usr/local/bin/entrypoint.sh"] CMD gunicorn screamshotter.wsgi:application -w $WORKERS --max-requests $MAX_REQUESTS --timeout `expr $TIMEOUT + 10` --bind 0.0.0.0:8000 --worker-tmp-dir /dev/shm diff --git a/src/screenshotter/puppeteer.py b/src/screenshotter/puppeteer.py index 23394dc4..10653b16 100644 --- a/src/screenshotter/puppeteer.py +++ b/src/screenshotter/puppeteer.py @@ -19,7 +19,7 @@ def take_screenshot(url, width=1920, height=1080, waitfor='body', wait_selectors # We send sentry informations and version : when we use screamshotter as a package, informations are in settings only with NamedTemporaryFile(suffix='.png') as screenshot_file: command = subprocess.run([ - "/usr/local/bin/dumb-init", + "dumb-init", "--dumb-init", "--", os.getenv('NODE_BIN_PATH', 'node'), From 3d1787af90af1dc8542b29a693812b4481f88d4a Mon Sep 17 00:00:00 2001 From: J-E Castagnede Date: Thu, 23 Nov 2023 10:52:40 +0100 Subject: [PATCH 6/7] fix subprocess remaining --- src/screenshotter/puppeteer.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/screenshotter/puppeteer.py b/src/screenshotter/puppeteer.py index 10653b16..93e5781e 100644 --- a/src/screenshotter/puppeteer.py +++ b/src/screenshotter/puppeteer.py @@ -19,8 +19,7 @@ def take_screenshot(url, width=1920, height=1080, waitfor='body', wait_selectors # We send sentry informations and version : when we use screamshotter as a package, informations are in settings only with NamedTemporaryFile(suffix='.png') as screenshot_file: command = subprocess.run([ - "dumb-init", - "--dumb-init", + "/usr/bin/dumb-init", "--", os.getenv('NODE_BIN_PATH', 'node'), app_settings.PUPPETEER_JAVASCRIPT_FILEPATH, From afc5a6b51ce5b4d28fc99eb85a7f6dd62796ccce Mon Sep 17 00:00:00 2001 From: J-E Castagnede Date: Thu, 23 Nov 2023 10:55:50 +0100 Subject: [PATCH 7/7] fix subprocess remaining --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 66607b10..7944895a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -80,7 +80,7 @@ jobs: - name: Install dependencies run: | sudo apt-get update -q - sudo apt-get -q -y install nodejs npm ca-certificates + sudo apt-get -q -y install nodejs npm ca-certificates dumb-init python -m pip install --upgrade pip setuptools wheel pip install -r requirements.txt -U pip install -r requirements-dev.txt