Skip to content

popoto.migrate_redis_to_postgres._watchdog

popoto.migrate_redis_to_postgres._watchdog

Supervisor for the migration's throwaway redis-server (#756).

Run by the migration tool as a separate process, by file path, before the throwaway server exists::

python -I _watchdog.py <tool pid>

It deliberately imports nothing but the standard library -- not popoto, not redis-py -- so it can never open a connection to anything.

The tool talks to it over a pipe, one JSON object per line:

  • {"op": "watch", "path": p}: remove directory p when the run ends;
  • {"op": "spawn", "argv": [...]}: start argv as a child of this process and answer {"pid": n};
  • {"op": "stop", "pid": n}: stop that child and answer {"ok": true}.

Whenever the tool goes away, for any reason, the supervisor stops every child it spawned and removes every watched directory, then exits. The tool going away is seen two independent ways: the command pipe reaches end of file (the kernel closes it when the tool exits, SIGKILL included), and this process's parent pid stops being the tool's (it is re-parented). A normal end of run is the same event: the tool closes the pipe.

It runs in its own session, so the SIGHUP an SSH drop sends and the SIGINT of a Ctrl-C reach neither it nor the server it spawned; it ignores both anyway, and treats SIGTERM as "clean up now".