Overview
When deploying applications to Posit Connect that include executable files (e.g., compiled binaries, shell scripts), you may encounter a situation where those files lose their executable permissions after deployment. This can result in errors like the following when using subprocess.run()
in Python:
FileNotFoundError: [Errno 2] No such file or directory: './executable_file'
This guide outlines why this happens and provides two common solutions depending on your Connect environment.
Why This Happens
When content is deployed to Posit Connect, the system does not retain the original file permissions (including the executable bit) from your local machine. This means that even if a file is marked executable before deployment (e.g., with chmod +x
), that permission may not carry over once the bundle is unpacked on the server.
As a result, applications that rely on launching binaries or shell scripts may fail at runtime unless the file's executable permissions are restored.
For Self-Managed Connect Servers (With OS Access)
If you have administrative access to the Connect server, you can manually restore the executable bit after deployment:
sudo chmod +x /opt/rstudio-connect/mnt/app/your_executable
Replace your_executable
with the name of the file you need to execute.
For Posit-Hosted Connect or When OS Access Is Unavailable
If you do not have access to the server’s file system (e.g., in a Posit-hosted Connect environment), you can programmatically restore permissions within your application using one of the following methods:
Option 1: Set executable permissions at runtime in Python
import os import shutil import subprocess # Copy the binary to a writable location shutil.copy('./your_executable', '/tmp/your_executable') # Set the executable bit os.chmod('/tmp/your_executable', 0o755) # Call the binary using subprocess subprocess.run(['/tmp/your_executable'])
Option 2: Use a wrapper script
Create a shell script (e.g., launch.sh
) that sets permissions and then calls the binary:
#!/bin/bash chmod +x ./your_executable ./your_executable "$@"
Then invoke launch.sh
from your app using subprocess
.
Still running into issues?
If these workarounds don’t resolve the issue or your use case is more complex, feel free to open a support ticket so we can help troubleshoot further.
Comments
0 comments
Article is closed for comments.