diff --git a/bugsink/scripts/runsnappea.py b/bugsink/scripts/runsnappea.py new file mode 100644 index 0000000..3bd2078 --- /dev/null +++ b/bugsink/scripts/runsnappea.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python +"""A copy of manage.py from the bugsink project, but with sys.argv[1] inserted as 'runsnappea'; when run this way the +script shows up with a meaningful name in `ps` and other such tools. +""" +import os +import sys + + +def main(): + # To maintain equivalent behavior to `python manage.py` / `python -m bugsink.scripts.manage` when running this + # script as `bugsink-manage` we need to add the current directory to sys.path. Otherwise the Django settings module + # will not be found if it is in the current directory. + cwd = os.getcwd() + if cwd not in sys.path: + sys.path.insert(0, cwd) + + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'bugsink_conf') + try: + from django.core.management import execute_from_command_line + except ImportError as exc: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) from exc + sys.argv = sys.argv[:1] + ['runsnappea'] + sys.argv[1:] + execute_from_command_line(sys.argv) + + +if __name__ == '__main__': + main() diff --git a/docs/howto/deployment/single-server.md b/docs/howto/deployment/single-server.md index 74c7bcf..a649402 100644 --- a/docs/howto/deployment/single-server.md +++ b/docs/howto/deployment/single-server.md @@ -421,7 +421,7 @@ Group=bugsink Environment="PYTHONUNBUFFERED=1" RuntimeDirectory=gunicorn WorkingDirectory=/home/bugsink -ExecStart=/home/bugsink/venv/bin/bugsink-manage runsnappea +ExecStart=/home/bugsink/venv/bin/bugsink-runsnappea ExecReload=/bin/kill -s HUP $MAINPID KillMode=mixed TimeoutStopSec=5 diff --git a/pyproject.toml b/pyproject.toml index e0f14dc..031ea41 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,6 +23,7 @@ dynamic = ["version", "dependencies"] bugsink-show-version = "bugsink.scripts.show_version:main" bugsink-manage = "bugsink.scripts.manage:main" bugsink-create-conf = "bugsink.scripts.create_conf:main" +bugsink-runsnappea = "bugsink.scripts.runsnappea:main" [tool.setuptools] include-package-data = true # this is the default, but explicit is better than implicit