CGIV-4084 Implement locking to avoid running multiple instances at the same time and use logging instead of stdout