TrueBlocks / trueblocks-core

The main repository for the TrueBlocks system
https://trueblocks.io
GNU General Public License v3.0
1.04k stars 194 forks source link

Move scrape.pid to temp dir #3785

Closed dszlachta closed 2 weeks ago

dszlachta commented 2 weeks ago

The motivation for this change was running scraper inside Docker, but I think it improves chifra runnig outside Docker, too.

Very, very rarely (after Ctrl-C fix) the .pid file was left after scraper had been killed. Moving the file to /tmp fixes the problem for Docker (because any directory not mounted to the host filesystem is ephemeral), but there's no guarantee that if running directly the OS will empty /tmp.

The code I added tries to use so called "variable directory" which is guaranteed to be emptied by the OS: https://refspecs.linuxfoundation.org/FHS_3.0/fhs/ch03s15.html

For Linux, it's /run/$UID, for Mac /usr/local/var/run. If the directory doesn't exist, we fall back to /tmp.