add --trace and --use-pid options to cli

- refactor chdir
- better errors on missing required files
fix lock file garbage collection bug
check for stale pid files