Implement command to reset the pid lock
Since #93, I don't believe pid is ever reset as a fail-safe?
Logs indicated that pre-generate was always returning command is already running so I was getting suspicious. I finally checked the appconfig and noticed that pid == 1, which will never not be running.
I believe this could happen if the preview generator crashes or is interrupted while executing php occ directly (via docker run/exec). If this is the case, some time-based check might still be valuable in addition to the pid check - that is, periodically update a watchdog timestamp in the appconfig and treat the previous instance as dead if it hasn't been updated for a while?
Or it might be easier to just special-case PID1? :P
I believe this could happen if the preview generator crashes or is interrupted while executing php occ directly (via docker run/exec).
Agreed, this could happen under some circumstances:
https://github.com/nextcloud/previewgenerator/blob/bf04c0afc850db10fc0a4f74234b17fc1c241462/lib/Command/PreGenerate.php#L105-L115
Or it might be easier to just special-case PID1? :P
True, it is probably most likely to happen with 1. Tempting! :)
Maybe also with Docker environments with their own PID namespaces?
If this is the case, some time-based check might still be valuable in addition to the pid check - that is, periodically update a watchdog timestamp in the appconfig and treat the previous instance as dead if it hasn't been updated for a while?
Maybe. Or just check for the other matching running processes (that look like other copies of us) outright and error out as already running in that case.
Related: #328
That is weird. Running exec should not start the command with PID 1 inside the running container.
But yeah, having a command to reset the pid lock or a fail-safe is probably a good idea.
In the meantime, the log can be reset by running the following raw SQL query:
DELETE FROM
oc_appconfig
WHERE
appid = 'previewgenerator'
AND configkey = 'pid';