From f51478efa13406e93542d259ab78232ed3f149d0 Mon Sep 17 00:00:00 2001 From: Chandragupt Singh Date: Sun, 28 Jun 2026 19:09:28 +0530 Subject: [PATCH 1/2] Replace SysV init with native systemd unit to fix gunicorn duplicate-master race --- bootstrap_gunicorn.py | 8 ++++---- install/install.sh | 10 ++++++---- install/installation.md | 2 +- install/platform | 27 --------------------------- install/platform.service | 19 +++++++++++++++++++ 5 files changed, 30 insertions(+), 36 deletions(-) delete mode 100644 install/platform create mode 100644 install/platform.service diff --git a/bootstrap_gunicorn.py b/bootstrap_gunicorn.py index 0cdfdd37a..a6ea7efc5 100644 --- a/bootstrap_gunicorn.py +++ b/bootstrap_gunicorn.py @@ -6,12 +6,12 @@ current_dir = path.dirname(path.abspath(__file__)) TIMEOUT = 120 # In seconds -# Arguments to start gunicorn args = [ - "gunicorn", "-w", "4", "--daemon", "--pid", "gunicorn.pid", "-b", "unix:sampleplatform.sock", "-m", "007", - "-g", "www-data", "-u", "www-data", f"--chdir={current_dir}", "--log-level", "debug", "--timeout", f"{TIMEOUT}", + "gunicorn", "-w", "4", "-b", "unix:sampleplatform.sock", "-m", "007", + "-g", "www-data", "-u", "www-data", f"--chdir={current_dir}", "--log-level", "debug", + "--timeout", f"{TIMEOUT}", "--access-logfile", f"{current_dir}/logs/access.log", "--capture-output", "--log-file", f"{current_dir}/logs/error.log", "run:app" ] -subprocess.Popen(args) +subprocess.run(args) \ No newline at end of file diff --git a/install/install.sh b/install/install.sh index 75ed79623..dfedbc129 100644 --- a/install/install.sh +++ b/install/install.sh @@ -264,10 +264,12 @@ chown -R www-data:www-data "${root_dir}" "${sample_repository}" echo "* Creating startup script" { - cp "${dir}/platform" /etc/init.d/platform - sed -i "s#BASE_DIR#${root_dir}#g" /etc/init.d/platform - chmod 755 /etc/init.d/platform - update-rc.d platform defaults + rm -f /etc/init.d/platform + update-rc.d platform remove || true + cp "${dir}/platform.service" /etc/systemd/system/platform.service + sed -i "s#/var/www/sample-platform#${root_dir}#g" /etc/systemd/system/platform.service + systemctl daemon-reload + systemctl enable platform.service } >> "$install_log" 2>&1 echo "* Creating RClone config file" diff --git a/install/installation.md b/install/installation.md index 74575fdf9..4464febf0 100644 --- a/install/installation.md +++ b/install/installation.md @@ -172,7 +172,7 @@ sudo python3 bootstrap_gunicorn.py 1. Firstly check the Platform Installation log file in the install folder. Check for any errors, which may have been caused during platform installation on your system, and then try to resolve them accordingly. 2. Next check for nginx status by `service nginx status` command, if it is not active, check nginx error log file, possibly in `/var/log/nginx/error.log` file. 3. Next check for platform status by `service platform status` command, if it is not `active(running)` then check for platform logs in the `logs` directory of your project. - 4. In case of any gunicorn error try manually running `/etc/init.d/platform start` command and recheck the platform status. + 4. In case of any gunicorn error try manually running `sudo systemctl start platform.service` command and recheck the platform status. ### Setting Up The Bucket diff --git a/install/platform b/install/platform deleted file mode 100644 index 21c161f8e..000000000 --- a/install/platform +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash -# /etc/init.d/platform -# -# Carry out specific functions when asked to by the system -case "${1}" in - start) - echo "Starting Platform daemon..." - cd BASE_DIR - python bootstrap_gunicorn.py - ;; - stop) - echo "Stopping Platform daemon..." - pid=`cat "BASE_DIR/gunicorn.pid"` - kill "${pid}" - ;; - reload) - echo "Reloading Platform daemon..." - pid=`cat "BASE_DIR/gunicorn.pid"` - kill -HUP "${pid}" - ;; - *) - echo "Usage: /etc/init.d/platform {start|stop|reload}" - exit 1 - ;; -esac - -exit 0 \ No newline at end of file diff --git a/install/platform.service b/install/platform.service new file mode 100644 index 000000000..3b2a875d3 --- /dev/null +++ b/install/platform.service @@ -0,0 +1,19 @@ +[Unit] +Description=CCExtractor Sample Platform (gunicorn) +After=network.target mysql.service +Wants=mysql.service + +[Service] +Type=simple +User=www-data +Group=www-data +WorkingDirectory=/var/www/sample-platform +ExecStart=/usr/bin/gunicorn -w 4 -b unix:/var/www/sample-platform/sampleplatform.sock -m 007 --timeout 120 --log-level debug --access-logfile /var/www/sample-platform/logs/access.log --capture-output --log-file /var/www/sample-platform/logs/error.log run:app +ExecReload=/bin/kill -s HUP $MAINPID +Restart=on-failure +RestartSec=5 +KillMode=control-group +TimeoutStopSec=30 + +[Install] +WantedBy=multi-user.target From ef96a6deb01d8c1d7b53e0d504df7b55a21514a3 Mon Sep 17 00:00:00 2001 From: Chandragupt Singh Date: Mon, 29 Jun 2026 01:15:15 +0530 Subject: [PATCH 2/2] Add trailing newline to bootstrap_gunicorn.py --- bootstrap_gunicorn.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bootstrap_gunicorn.py b/bootstrap_gunicorn.py index a6ea7efc5..30fd9d4f3 100644 --- a/bootstrap_gunicorn.py +++ b/bootstrap_gunicorn.py @@ -14,4 +14,4 @@ "--log-file", f"{current_dir}/logs/error.log", "run:app" ] -subprocess.run(args) \ No newline at end of file +subprocess.run(args)