PiShrink icon indicating copy to clipboard operation
PiShrink copied to clipboard

Some software does not want to see their log file disappear

Open gromain opened this issue 4 years ago • 3 comments

Cleanup the logs by removing everything inside /var/log/ wreaks havoc for some programs that expect the files to be there. Two are of note: Apache and Mosquitto. They both fail on startup if the log files or folders are not there.

Maybe a good way to solve this would be to only remove .gz logs (with sudo find /var/log/ -type f -regex '.*\.[0-9]+\.gz$' -delete as suggested here) and to empty existing files (with > /var/log/logfile.log as suggested here) ?

gromain avatar Oct 17 '20 12:10 gromain

The suggested regex could even be changed to .*\.\([0-9]*\|gz\)$ to match any files whose names ends with either numbers or gz (to match on files like error.log.1 for example)

gromain avatar Oct 17 '20 12:10 gromain

Also, the command > /var/log/logfile.log can be replace with sudo find mnt/var/log/ -type f -regex '.*\.log$' -exec truncate -s0 {} + which I think is more suited to a script.

gromain avatar Oct 17 '20 13:10 gromain

nginx is another example of software that fails if the log folder is removed:

Sep 03 16:30:56 tinypilot systemd[1]: Starting A high performance web server and a reverse proxy server...
Sep 03 16:30:56 tinypilot nginx[5229]: nginx: [alert] could not open error log file: open() "/var/log/nginx/error.log" failed (2: No such file or directory)
Sep 03 16:30:56 tinypilot nginx[5229]: 2021/09/03 16:30:56 [emerg] 5229#5229: open() "/var/log/nginx/error.log" failed (2: No such file or directory)
Sep 03 16:30:56 tinypilot nginx[5229]: nginx: configuration file /etc/nginx/nginx.conf test failed
Sep 03 16:30:56 tinypilot systemd[1]: nginx.service: Control process exited, code=exited, status=1/FAILURE
Sep 03 16:30:56 tinypilot systemd[1]: nginx.service: Failed with result 'exit-code'.
Sep 03 16:30:56 tinypilot systemd[1]: Failed to start A high performance web server and a reverse proxy server.

mtlynch avatar Sep 08 '21 13:09 mtlynch

I am looking into better ways to support cleanup. Closing this until thats done

Drewsif avatar Feb 14 '23 06:02 Drewsif