discourse is script/discourse – executed via bundle exec and with rails_env=production. Look at /usr/local/bin/discourse.
Running bundle exec script/discourse takes care of the thor mismatched gem version, too. Or just using the discourse convenience script.