A common requirement is to adjust the LD_LIBRARY_PATH or add additional environment variables on all Connect applications to allow certain R packages or other resources to work with your deployed applications. For example: ROracle, Gurobi, Hadoop, etc.
We suggest placing these environment variable changes into the program supervisor script; this way, it's set in the shell before the application process starting. Setting the LD_LIBRARY_PATH before the process starts is necessary for it to take effect.
1. If you need to adjust the LD_LIBRARY_PATH used when the Connect service first starts and detects the available R versions, the program supervisor script will not apply. Instead, use the R startup file called ldpaths. This is stored in the R_HOME/etc/ location. For example:
Within that file, edit the
export LD_LIBRARY_PATH line at the end to include the modified path. e.g.,
export LD_LIBRARY_PATH = /new/path:$LD_LIBRARY_PATH
2. If you only need the environment variable available after the R process starts (e.g., if it contains a password or secret instead of a path modification), the best practice is to use the environment variable pane instead.
The /opt/scripts location is suggested to avoid the directories hidden by the sandbox mechanism that the process runs in. You may choose another location, but it cannot include any of these locations:
Server.DataDirdirectory containing all variable data used by Posit Connect.
SQLite.Dirdirectory, which can optionally be placed outside the data directory.
Configuration directories, including
Server.TempDirdirectory contains a
connect-workspacessub-directory with per-process temporary directories.
To implement, follow these steps:
1. Create a directory to store your program supervisor script. Note that this directory must be accessible by the sandbox. Below is an ideal directory example:
mkdir -p /opt/scripts
2. Example script contents to edit for your needs:
echo arguments: "$@" >&2
3. Allow access to the file with:
chmod 755 /opt/scripts/connect-env.sh
4. Add the following to /etc/rstudio-connect/rstudio-connect.gcfg
Supervisor = /opt/scripts/connect-env.sh
Once complete, restart the RStudio Connect service, then attempt to deploy or access the existing application.