Hi there,
I've have issues adding environment variables (e.g., LD_LIBRARY_PATH) to the shiny R sessions when starting the shiny-server as user shiny and running the apps also as user shiny as it seems that the .bash_profile of user shiny did not get sourced. When the shiny server is started as root and the apps were run as shiny then the .bash_profile is sourced.
I have to start the shiny server as user shiny (company rules) which is achieved by giving the User and Group keywords in /etc/systemd/system/shiny-server.service (the rest is the default):
[Unit]
Description=ShinyServer
[Service]
User=shiny
Group=shiny
Type=simple
ExecStart=/usr/bin/env bash -c 'exec /opt/shiny-server/bin/shiny-server >> /var/log/shiny-server.log 2>&1'
KillMode=process
ExecReload=/usr/bin/env kill -HUP $MAINPID
ExecStopPost=/usr/bin/env sleep 5
Restart=on-failure
RestartSec=1
Environment="LANG=de_CH.UTF-8"
StartLimitInterval=45
StartLimitBurst=3
[Install]
WantedBy=multi-user.target
The /etc/shiny-server/shiny-server.conf is the default one:
# Instruct Shiny Server to run applications as the user "shiny"
run_as shiny;
# Define a server that listens on port 3838
server {
listen 3838;
# Define a location at the base URL
location / {
# Host the directory of Shiny Apps stored in this directory
site_dir /srv/shiny-server;
# Log all Shiny output to files in this directory
log_dir /var/log/shiny-server;
# When a user visits the base URL rather than a particular application,
# an index of the applications available in this directory will be shown.
directory_index on;
}
}
With this setup shiny's .bash_profile did not get loaded. Removing the User and the Group keywords from the service file helped (as the shiny-server is then startet as root) and shiny's .bash_profile got loaded. But this is not an option due to company security rules.
For the time being I found a workaround by sourcing the .bash_profile directly before starting the shiny-server within the service file:
ExecStart=/usr/bin/env bash -c 'source ${HOME}/.bash_profile; exec /opt/shiny-server/bin/shiny-server >> /var/log/shiny-server.log 2>&1'
However, I think this is just a workaround but not a final solution. Is there a reason, why shiny's .bash_profile is not loaded when user shiny is starting shiny-server and running the apps? Is there a better solution for this issue?
Thanks a lot in advance for any lights shed on this issue.
PS:
I am working on a Ubuntu 18.04 machine:
> uname -a
Linux myuser 4.18.0-16-generic #17-Ubuntu SMP Fri Feb 8 00:06:57 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
with RStudio Shiny Server v1.5.9.923 (Open Source version)