If, like me you wish to automatically restart bitcoind after some period of time, or if it crashes at least it will restart sometime on it's own you know that it can take a long time on Linux before process cache finishes writing to disk and then you can restart without the dreaded message
Error: Cannot obtain a lock on data directory /media/drive2/.bitcoin/. Bitcoin Core is probably already running.
How to restart bitcoind automatically using a script without error message and failure to start?
This question is specifically to allow
bitcoind to exit cleanly as it can take an inordinate amount of time to exit cleanly even though you cannot see the process with
ps -ae | grep bitcoind you can still see it with
htop until it finishes committing the process cache to disk and finally "Shutdown: done" is written to disk. If configured as daemon it is possible to have thousands of failures starting before the process finally exists.