CGIV-4084 Add functions to handle locking and logging
CGIV-4084 Use locking to avoid running multiple instances and use log file to report errors instead of stdout