1

The problem:

I have a python webapp running on heroku which creates a subprocess for communication with the Stockfish chess engine.

Everything JustWorks™ on my local machine, however upon attempting to deploy the project on Heroku, I get an error saying PermissionError: [Errno 13] Permission denied

Below, I have included the heroku logs from when I tried to deploy this.

I know other folks have heroku apps running the stockfish engine within the same dyno, however I haven't had much luck finding resources to assist me in getting it working. Any help is appreciated. Thanks!


The logs:

bash 2017-06-20T22:32:48.419694+00:00 heroku[web.1]: Starting process with command `python server.py` 2017-06-20T22:32:51.933668+00:00 app[web.1]: Traceback (most recent call last): 2017-06-20T22:32:51.933687+00:00 app[web.1]: File "server.py", line 23, in <module> 2017-06-20T22:32:51.933882+00:00 app[web.1]: engine = chess.uci.popen_engine(DIR_PATH + "/stockfish_8_x64") 2017-06-20T22:32:51.933884+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/chess/uci.py", line 1405, in popen_engine 2017-06-20T22:32:51.934623+00:00 app[web.1]: PopenProcess(engine, command, **kwargs) 2017-06-20T22:32:51.934625+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/chess/uci.py", line 404, in __init__ 2017-06-20T22:32:51.934874+00:00 app[web.1]: self.process = subprocess.Popen(command, **popen_args) 2017-06-20T22:32:51.934877+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/subprocess.py", line 707, in __init__ 2017-06-20T22:32:51.935286+00:00 app[web.1]: restore_signals, start_new_session) 2017-06-20T22:32:51.935288+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/subprocess.py", line 1326, in _execute_child 2017-06-20T22:32:51.935988+00:00 app[web.1]: raise child_exception_type(errno_num, err_msg) 2017-06-20T22:32:51.936008+00:00 app[web.1]: PermissionError: [Errno 13] Permission denied 2017-06-20T22:32:52.051035+00:00 heroku[web.1]: State changed from starting to crashed 2017-06-20T22:32:52.035235+00:00 heroku[web.1]: Process exited with status 1

  • I assume that you have the `stockfish` executable in `git`? If so, you'll need to check that the file has execute permissions. For example, https://stackoverflow.com/questions/6476513/git-file-permissions-on-windows (the command still applies, even if you are already on *nix) – bimsapi Jun 21 '17 at 13:19
  • How do I do that on Heroku, when the dyno gets torn down and restarted each time? Should I do that as part of the Procfile command? `web: chmod +x stockfish_8_x64 && python server.py` – TheAmazingFedex Jun 21 '17 at 15:25
  • Git can and should preserve file permissions. I would check - **1)** what permissions git has via `git ls-files HEAD` (or branch name). The last 3 digits of the first field are the file mode, in octal. Then **2)** what permissions are on the Heroku filesystem (via `heroku run 'ls -al'`). Then **3)** if git perms don't have execute, add it and redeploy. Finally, **4)** if that doesn't address the issue, then find a way to patch perms on app start (in-app, via `os.chmod()`, rather than Procfile). – bimsapi Jun 21 '17 at 16:31
  • Thanks @bimsapi, the 4th option, adding the chmod permissions in-app worked like a charm! – TheAmazingFedex Jun 21 '17 at 19:56
  • I got a very similar problem. How do you include the `os.chmod()`? Maybe you can help me on my question: https://stackoverflow.com/questions/72838592/heroku-permission-for-subprocess – GCMeccariello Jul 02 '22 at 12:20

1 Answers1

1

To answer my own question based off the comments: The stockfish executable did not have executable rights on the heroku server, and those needed to be added explicitly. As per guidance in the comments on the original question, I was able to modify my server.py to append the executable permission to the stockfish executable file.

Source -> SO: Simple chmod +x in python