Warning, /swf-monitor/docs/SCRIPTS.md is written in an unsupported language. File is not indexed.
0001 # Standalone scripts
0002
0003 The doers in `scripts/` that read or write the monitor's records (the
0004 segfault catalog's inventory, dig, reproductions and studies, the
0005 reconciliations, the reporters' ingests and the like) are standalone
0006 Python scripts that configure Django themselves. They are run by hand,
0007 from cron, or by the production operations agent as `run_in_background`
0008 doers (swf-epicprod `docs/EPICPROD_OPS_AGENT.md`); none is a Django
0009 management command. The logic they apply lives in `monitor_app`
0010 modules, which the pages, the MCP tools and the REST API share; a script
0011 is the entry point that runs it with its arguments and records the run.
0012
0013 ## Shape
0014
0015 The header, before any import from the project:
0016
0017 ```python
0018 THIS_DIR = os.path.dirname(os.path.abspath(__file__))
0019 sys.path.insert(0, os.path.join(THIS_DIR, '..', 'src'))
0020 os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'swf_monitor_project.settings')
0021
0022 import django # noqa: E402
0023 django.setup()
0024
0025 from monitor_app.... import ... # noqa: E402
0026 ```
0027
0028 Then:
0029
0030 - **Arguments** by `argparse`, the description taken from the
0031 docstring's first line. A script that writes offers `--dry-run`,
0032 which prints what it would do and writes nothing.
0033 - **Output**: progress and errors to stderr through `logging`
0034 (`basicConfig(level=INFO, stream=sys.stderr)`); the last stdout line
0035 one JSON summary of the run, which the agent or a session reads.
0036 - **Exit status** 0 on success, 1 on an error.
0037 - **The action stream**: a run that changed something, or failed,
0038 records one action through
0039 `monitor_app.epicprod_logging.log_epicprod_action(instance, action,
0040 outcome=..., sublevel=..., live_default=..., message=..., **fields)`
0041 (`docs/ACTION_STREAM.md`); a failure is an action with outcome
0042 `error`, never a silent exit. `live_default=True` only for what
0043 belongs on epicprod-live (`docs/NOTICE_ROUTING.md`).
0044 - **The docstring** states what the script does, where its design is
0045 documented, and the invocation by hand.
0046
0047 ## Running one by hand
0048
0049 On swf-testbed, from the source directory, with the testbed's virtual
0050 environment's interpreter (after `~/.env`, `python3` on the path is not
0051 that interpreter):
0052
0053 ```bash
0054 cd /data/wenauseic/github/swf-monitor/src
0055 ../../swf-testbed/.venv/bin/python ../scripts/<script>.py [arguments]
0056 ```
0057
0058 A run longer than a few seconds is started in the background and its
0059 summary read when it ends. A script that works on another host reaches
0060 it through that host's documented route (for npps0, the npps0 skill's
0061 `npps0.sh`), never by a credential of its own.