title: run shiny server as non-root
body: <p>I installed shiny server in a virtual machine (ubuntu server 14.04.4 in  VirtualBox)</p>
  
  <pre><code>shiny-server --version
  
  Shiny Server v1.4.2.786
  Node.js v0.10.40
  </code></pre>
  
  <p>All in all the server runs nicely and starts apps as intended. </p>
  
  <p>The only thing I'm missing and failing to achieve is that shiny server is running as an unprivileged user. I even completely set up a new VM and shiny server to make sure no trial config changes still take effect.</p>
  
  <p>I changed my config to not contain any folders one needs root permissions for:</p>
  
  <pre><code>$ cat /etc/shiny-server/shiny-server.conf
  # 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;
      site_dir /home/shiny/shiny_sitedir/apps; 
  
      # Log all Shiny output to files in this directory
      # log_dir /var/log/shiny-server;
      log_dir /home/shiny/shiny_sitedir/logs;
  
      # 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;
    }
  }
  
  
  # privileges of shiny user
  uid=1000(shiny) gid=1000(shiny) groups=1000(shiny),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),110(lpadmin),111(sambashare)
  
  # owner of /etc/shiny-server
  -rw-r--r--  1 root root shiny-server.conf
  
  # trying to start shiny server as user shiny without sudo
  $ start shiny-server 
  start: Rejected send message, 1 matched rules; type="method_call", sender=":1.6" (uid=1000 pid=1134 comm="start shiny-server ") interface="com.ubuntu.Upstart0_6.Job" member="Start" error name="(unset)" requested_reply="0" destination="com.ubuntu.Upstart" (uid=0 pid=1 comm="/sbin/init ")
  </code></pre>
  
  <p>The server log tells me the same I see from the htop output that shiny server runs as root. (A side note: <code>shiny server</code> still uses <code>/var/log/shiny-server.log</code> instead  of <code>/home/shiny/shiny_sitedir/logs</code>, which annoys me as well)</p>
  
  <pre><code>[...] [INFO] shiny-server - Shiny Server v1.4.2.786 (Node.js v0.10.40)
  [...] [INFO] shiny-server - Using pidfile /var/run/shiny-server.pid
  [...] [INFO] shiny-server - Using config file "/etc/shiny-server/shiny-server.conf"
  [...] [WARN] shiny-server - Running as root unnecessarily is a security risk! You could be running more securely as non-root.
  [...] [INFO] shiny-server - Starting listener on 0.0.0.0:3838
  </code></pre>
  
  <p>The shiny server documentation <code>http://docs.rstudio.com/shiny-server/#running-shiny-server-with-root-privileges</code> ships out a list of requirements to be fulfilled for non-root usage. Actually it defines states in which the shiny server needs to run as root:</p>
  
  <ol>
  <li>If user_apps or user_dirs is enabled for any location. In order to host applications as various users, Shiny Server must have root privileges.
  
  <ul>
  <li>check. My shiny-server.conf neither uses user_apps nor user_dirs</li>
  </ul></li>
  <li>If your configuration uses run_as to spawn applications as multiple different users.
  
  <ul>
  <li>check. run_as defines shiny as the only user</li>
  </ul></li>
  <li>If you're running any server on a privileged port (a port in the range of 1-1024).
  
  <ul>
  <li>check. shiny server listens on port 3838</li>
  </ul></li>
  </ol>
  
  <p>Although I think the installation fulfils the requirements shiny server still runs as root. </p>
  
  <ul>
  <li>How do I force shiny server to run as shiny user or even an user not part of the sudoers group?</li>
  <li>Does the shiny-server.conf need to locate anywhere else? </li>
  <li>How would I make shiny-server aware of this new location then?</li>
  <li>Do I need to change anything in <code>/opt/shiny-server/config/</code> or any permissions on <code>/etc/shiny-server/</code>?</li>
  </ul>
  
  <p>Edit after a comment by @warmoverflow I moved <code>/etc/init/shiny-server.conf</code> to <code>~/.init</code>. Now, shiny server does not start automatically at boot up. But neither does <code>start shiny-server</code> succeed, because upstart is not aware of the <code>~/.init</code> folder. From some forum posts it seems that dbus needs start, which it usually does by starting a graphical environment. As I'm running Ubuntu server this doesn't happen. Creating the two files mentioned in the upstart manual <code>http://upstart.ubuntu.com/cookbook/#session-init</code> doesn't help either, because the jobs fail to start.</p>
  
  <p>Does anybody have a hint how to proceed or where I could find some information?</p>