From 573c00adc63f0057091e476f02a2d4ce375c545e Mon Sep 17 00:00:00 2001 From: Jeremy Poulter Date: Thu, 21 May 2026 22:55:25 +0100 Subject: [PATCH] Remove the local `service-runner.py` now the upstream EmonCMS has the change --- web/Dockerfile | 3 -- web/service-runner.py | 81 ------------------------------------------- 2 files changed, 84 deletions(-) delete mode 100644 web/service-runner.py diff --git a/web/Dockerfile b/web/Dockerfile index 54c2b2f..790b83f 100644 --- a/web/Dockerfile +++ b/web/Dockerfile @@ -103,9 +103,6 @@ RUN set -x;\ cp EmonScripts/install/emonsd.config.ini EmonScripts/install/config.ini COPY docker.settings.ini /var/www/emoncms/settings.ini -# Upstream service-runner uses redis.Redis() (localhost); Docker needs REDIS_HOST (see service-runner.py). -COPY service-runner.py $WWW/emoncms/scripts/services/service-runner/service-runner.py -RUN chown $DAEMON $WWW/emoncms/scripts/services/service-runner/service-runner.py # Create folders & set permissions for feed-engine data, logs, and worker lock files RUN set -x;\ diff --git a/web/service-runner.py b/web/service-runner.py deleted file mode 100644 index eae0865..0000000 --- a/web/service-runner.py +++ /dev/null @@ -1,81 +0,0 @@ -#!/usr/bin/env python3 - -## Used to run arbitrary commands from the EmonCMS web interface -# EmonCMS submits commands to redis where this service picks them up -# Used in conjunction with: -# - Admin module to run service-runner-update.sh -# - Backup module -# - Others?? - -# Patched in emoncms-docker: default redis.Redis() uses localhost; Docker Compose uses hostname `redis`. - -import os -import subprocess -import time -import shlex -import redis - -KEYS = ["service-runner", "emoncms:service-runner"] - - -def _redis_client(): - return redis.Redis( - host=os.environ.get("REDIS_HOST", "127.0.0.1"), - port=int(os.environ.get("REDIS_PORT", "6379")), - ) - - -def connect_redis(): - while True: - try: - server = _redis_client() - if server.ping(): - print("Connected to redis server", flush=True) - return server - except redis.exceptions.ConnectionError: - print("Unable to connect to redis server, sleeping for 30s", flush=True) - time.sleep(30) - - -def main(): - print("Starting service-runner", flush=True) - server = connect_redis() - while True: - try: - # Get the next item from the 'service-runner' list, blocking until one exists - packed = server.blpop(KEYS) - if not packed: - continue - flag = packed[1].decode() - except redis.exceptions.ConnectionError: - print("Connection to redis server lost, attempting to reconnect", flush=True) - server = connect_redis() - continue - - print("Got flag:", flag, flush=True) - if ">" in flag: - script, logfile = flag.split(">") - print("STARTING:", script, '&>', logfile, flush=True) - # Got a cmdline, now run it. - with open(logfile, "w") as f: - try: - subprocess.call(shlex.split(script), stdout=f, stderr=f) - except Exception as exc: - # If an error occurs running the subprocess, add the error to - # the specified logfile - f.write("Error running [%s]" % script) - f.write("Exception occurred: %s" % exc) - continue - else: - script = flag - print("STARTING:", script, flush=True) - try: - subprocess.call(shlex.split(script), stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT) - except Exception as exc: - continue - - print("COMPLETE:", script, flush=True) - - -if __name__ == "__main__": - main()