For a number of security and performance reasons I tend to put /var/log in tmpfs in RAM (at least on machines where I either don’t care about logs or where syslog is forwarded to a central server).
That practice can sometimes cause issues with services that requires a particular file or folder in /var/log when the service starts at boot. Tor is a perfect example as it looks for /var/log/tor at boot and fails to start if the directory does not exist.
The file /etc/rc.local is a common place to add boot-time commands. Unfortunately for this issue, rc.local is the last thing to run which means Tor has already failed to start. Placing “mkdir /var/log/tor && service tor start” in there wasn’t very elegant in my opinion.
I wanted a cleaner fix in the startup script itself. Fortunately, there is already a function in the startup script that checks for a valid PID file location. It becomes pretty simple to use that logic applied to the log directory instead, in line with the existing style and structure of the startup script.