# Rstudio-server fails to start with database error

**URL:** <https://discourse.openondemand.org/t/rstudio-server-fails-to-start-with-database-error/1895>\
**Category:** Get Help\
**Tags:** question\
**Created:** [February 2, 2022, 4:13pm UTC](https://discourse.openondemand.org/t/rstudio-server-fails-to-start-with-database-error/1895 "2022-02-02T16:13:31Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![gwylym](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/gwylym/32/140_2.png) [@gwylym](https://discourse.openondemand.org/u/gwylym)\
**Post date:** [February 2, 2022, 4:13pm UTC](https://discourse.openondemand.org/t/rstudio-server-fails-to-start-with-database-error/1895/1 "2022-02-02T16:13:31Z")

</div>

We are using the ondemand app setup for rstudio that works with rstudio 1.3.1093-1. We are trying to get the new rstudio 2021.09.2 and when we launch the app it fails with no errors in the output.

The launch from the script file is as follows:  
/usr/lib/rstudio-server/bin/rserver   
–www-port “${port}”   
–auth-none 0   
–auth-pam-helper-path “${RSTUDIO\_AUTH}”   
–auth-encrypt-password 0   
–rsession-path “${RSESSION\_WRAPPER\_FILE}”   
–server-data-dir “${TMPDIR}”   
–secure-cookie-key-file “${TMPDIR}/rstudio-server/secure-cookie-key”  
–server-user “$USER”

When we run the command run the command line we get the following error with filling in the variables:  
2022-02-02T00:07:25.255149Z [rserver] ERROR database error 7 (sqlite3\_statement\_backend::loadOne: attempt to write a readonly database) [description: Could not delete expired revoked cookies from the database, description: Could not read revoked cookies from the database]; OCCURRED AT virtual rstudio::core::Error rstudio::core::database::Connection::execute(rstudio::core::database::Query&, bool\*) src/cpp/core/Database.cpp:517; LOGGED FROM: int main(int, char\* const\*) src/cpp/server/ServerMain.cpp:791

Has anyone else seen this issue?

---

<div class="post-metadata">

**Author:** ![maflister](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/maflister/32/139_2.png) [@maflister](https://discourse.openondemand.org/u/maflister)\
**Post date:** [February 2, 2022, 4:41pm UTC](https://discourse.openondemand.org/t/rstudio-server-fails-to-start-with-database-error/1895/2 "2022-02-02T16:41:55Z")

</div>

Try adding something like this to your script.sh.erb file above your rserver command:

```auto
# Generate a database.conf file
export DBCONF="${PWD}/database.conf"
(
umask 077
sed 's/^ \{2\}//' > "${DBCONF}" << EOL
  # set database location
  provider=sqlite
  directory=${TMPDIR}/rstudio-server/db
EOL
)
chmod 700 "${DBCONF}"

```

Then add this to your rserver command:

```auto
  --database-config-file "${DBCONF}" 

```

---

<div class="post-metadata">

**Author:** ![jeff.ohrstrom](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/jeff.ohrstrom/32/136_2.png) [@jeff.ohrstrom](https://discourse.openondemand.org/u/jeff.ohrstrom)\
**Post date:** [February 2, 2022, 4:47pm UTC](https://discourse.openondemand.org/t/rstudio-server-fails-to-start-with-database-error/1895/3 "2022-02-02T16:47:54Z")

</div>

We use a container, so we mount in a bunch of `/etc/` configurations - like the one you can inline in @maflister’s example.

This database configuration being one.

> <https://github.com/OSC/bc_osc_rstudio_server/blob/master/template/etc/database.conf>

Also I just added a reference of `rserver`'s --help output to my own app’s README. It takes way to long to look up `--database-config-file` in RStudio docs for me - so it’ll be a nice reference for me. I would suggest folks doing the same if you maintain an Rstudio app.

---

<div class="post-metadata">

**Author:** ![gwylym](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/gwylym/32/140_2.png) [@gwylym](https://discourse.openondemand.org/u/gwylym)\
**Post date:** [February 2, 2022, 10:45pm UTC](https://discourse.openondemand.org/t/rstudio-server-fails-to-start-with-database-error/1895/4 "2022-02-02T22:45:11Z")

</div>

> [@maflister](#):
>
> `--database-config-file "${DBCONF}" `

I tried the edit to the script file and it comes up with a login prompt. Our old rstudio setup never prompted for a username and password.

---

<div class="post-metadata">

**Author:** ![maflister](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/maflister/32/139_2.png) [@maflister](https://discourse.openondemand.org/u/maflister)\
**Post date:** [February 3, 2022, 6:51pm UTC](https://discourse.openondemand.org/t/rstudio-server-fails-to-start-with-database-error/1895/5 "2022-02-03T18:51:20Z")

</div>

Can you share the total content of your `script.sh.erb` file and your `template/bin/auth` file?

---

<div class="post-metadata">

**Author:** ![gwylym](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/gwylym/32/140_2.png) [@gwylym](https://discourse.openondemand.org/u/gwylym)\
**Post date:** [February 4, 2022, 2:50pm UTC](https://discourse.openondemand.org/t/rstudio-server-fails-to-start-with-database-error/1895/6 "2022-02-04T14:50:35Z")

</div>

After doing some extensive reading on the web and trying a few things we now can launch the 2021.09 version and run R commands. However, unlike the prior version 1.3.1093 we cannot run a plot such as hist(mtcars$mpg)

We get the error message:  
Error in RStudioGD() :  
Shadow graphics device error: r error 4 (R code execution error)  
In addition: Warning message:  
In grDevices:::png(“/tmp/RtmpGBrHIj/f0e5ed5dee574bcb8008f07d0242a974.png”, :  
unable to open connection to X11 display "

I have not been able to track down anything on that issue yet. The following are copies of our script.sh.erb file and our template/bin/auth:  
#!/usr/bin/env bash

# Load the required environment

setup\_env () {

# Additional environment which could be moved into a module

# Change these to suit

export PATH=“$PATH:/usr/lib/rstudio-server/bin”

module load \<%= context.r\_version %\>  
module load anaconda3  
echo " [from script.sh.erb] Module to load: \<%= context.r\_version %\>"  
echo " [from script.sh.erb] Loaded modules:" && module list  
}  
setup\_env

# 

# Start RStudio Server

# 

# PAM auth helper used by RStudio

export RSTUDIO\_AUTH=“${PWD}/bin/auth”

# Generate an `rsession` wrapper script

export RSESSION\_WRAPPER\_FILE=“${PWD}/rsession.sh”  
(  
umask 077  
sed ‘s/^ {2}//’ \> “${RSESSION\_WRAPPER\_FILE}” \<\< EOL  
#!/usr/bin/env bash

# Log all output from this script

export RSESSION\_LOG\_FILE=“${PWD}/rsession.log”

exec &\>\>“${RSESSION\_LOG\_FILE}”

# Launch the original command

echo “Launching rsession…”  
set -x  
exec rsession --r-libs-user “${R\_LIBS\_USER}” “${@}”  
EOL  
)  
chmod 700 “${RSESSION\_WRAPPER\_FILE}”

# Set working directory to home directory

cd “${HOME}”

hostname

export TMPDIR=“$(mktemp -d)”

mkdir -p “$TMPDIR/rstudio-server”  
python -c ‘from uuid import uuid4; print(uuid4())’ \> “$TMPDIR/rstudio-server/secure-cookie-key”  
chmod 0600 “$TMPDIR/rstudio-server/secure-cookie-key”

set -x

# Launch the RStudio Server

echo “Starting up rserver for $USER…”

# Generate a database.conf file

export DBCONF=“${PWD}/database.conf”  
(  
umask 077  
sed ‘s/^ {2}//’ \> “${DBCONF}” \<\< EOL

# set database location

provider=sqlite  
directory=${TMPDIR}/rstudio-server/db  
EOL  
)  
chmod 700 “${DBCONF}”

DISABLE\_AUTH=true

RSTUDIO\_PASSWORD=“password” /usr/lib/rstudio-server/bin/rserver   
–server-daemonize=0   
–www-port “${port}”   
–auth-none 1   
–auth-pam-helper “/var/lib/rstudio-server/rstudio\_auth.sh”   
–auth-encrypt-password 0   
–rsession-path “${RSESSION\_WRAPPER\_FILE}”   
–server-data-dir “${TMPDIR}”   
–database-config-file “${DBCONF}”   
–secure-cookie-key-file “${TMPDIR}/rstudio-server/secure-cookie-key”  
–server-user “$USER”

* * *

#!/usr/bin/env bash

# Confirm username is supplied

if [[$# -lt 1]]; then  
echo “Usage: auth USERNAME”  
exit 1  
fi  
USERNAME=“${1}”

# Confirm password environment variable exists

if [[-z ${RSTUDIO\_PASSWORD}]]; then  
echo “The environment variable RSTUDIO\_PASSWORD is not set”  
exit 1  
fi

# Read in the password from user

read -s -p "Password: " PASSWORD  
echo “”

if [[${USERNAME} == ${USER} && ${PASSWORD} == ${RSTUDIO\_PASSWORD}]]; then  
echo “Successful authentication”  
exit 0  
else  
echo “Invalid authentication”  
exit 1  
fi

---

<div class="post-metadata">

**Author:** ![jeff.ohrstrom](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/jeff.ohrstrom/32/136_2.png) [@jeff.ohrstrom](https://discourse.openondemand.org/u/jeff.ohrstrom)\
**Post date:** [February 4, 2022, 3:54pm UTC](https://discourse.openondemand.org/t/rstudio-server-fails-to-start-with-database-error/1895/7 "2022-02-04T15:54:10Z")

</div>

That error has to do with the `cairo` package and R/Rstudio not being able to find it somehow.

Here’s a similar topic.

> [@Graphics display issues with R built from source for RStudio Server](https://discourse.openondemand.org/t/graphics-display-issues-with-r-built-from-source-for-rstudio-server/1123):
>
> Hi All, I am having some trouble getting plots to display in our RStudio Server interactive app. We are running this app without Singularity, in the same manner as [described in this post](https://discourse.openondemand.org/t/rstudio-without-singularity/773/13). The R interpreter we use for this, we built from source, but I suspect I’m missing some libraries, or compiler flags, or both. When we try to run a plot in RStudio Server, we get this error: Error in RStudioGD() : Shadow graphics device error: r error 4 (R code execution error) In addition: Warning message…

I found this hack I put into a container to fix the issue

```auto
RUN echo "options(bitmapType='cairo')" > /usr/local/lib64/R/etc/Rprofile.site

```

I’m reaching out to my apps group to see what flags they pass when they build R and Rstudio.

---

<div class="post-metadata">

**Author:** ![maflister](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/maflister/32/139_2.png) [@maflister](https://discourse.openondemand.org/u/maflister)\
**Post date:** [February 4, 2022, 4:32pm UTC](https://discourse.openondemand.org/t/rstudio-server-fails-to-start-with-database-error/1895/8 "2022-02-04T16:32:56Z")

</div>

You can check for cairo support in your R by running `capabilities()` command in an R prompt. If it is false, then install cairo (OS package is easiest) and recompile R including the `--with-cairo` flag.

---

<div class="post-metadata">

**Author:** ![gwylym](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/gwylym/32/140_2.png) [@gwylym](https://discourse.openondemand.org/u/gwylym)\
**Post date:** [February 4, 2022, 6:30pm UTC](https://discourse.openondemand.org/t/rstudio-server-fails-to-start-with-database-error/1895/9 "2022-02-04T18:30:13Z")

</div>

Cairo was true when I checked capabilities.

---

<div class="post-metadata">

**Author:** ![maflister](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/maflister/32/139_2.png) [@maflister](https://discourse.openondemand.org/u/maflister)\
**Post date:** [February 4, 2022, 6:46pm UTC](https://discourse.openondemand.org/t/rstudio-server-fails-to-start-with-database-error/1895/10 "2022-02-04T18:46:28Z")

</div>

That’s great! As @jeff.ohrstrom said, adding `options(bitmapType='cairo')` to the `Rprofile.site` file is the potential fix. That’s what we use at my site.

---

<div class="post-metadata">

**Author:** ![gwylym](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/gwylym/32/140_2.png) [@gwylym](https://discourse.openondemand.org/u/gwylym)\
**Post date:** [February 4, 2022, 8:08pm UTC](https://discourse.openondemand.org/t/rstudio-server-fails-to-start-with-database-error/1895/11 "2022-02-04T20:08:00Z")

</div>

> [@jeff.ohrstrom](#):
>
> `/usr/local/lib64/R/etc/Rprofile.site`

I’m not finding a Rprofile.site in our installation of R on our 4.1.2 setup. We have R set up as a package on our cluster.

But I found it in another version and copied it over. plots now working great!

---

<div class="post-metadata">

**Author:** ![maflister](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/maflister/32/139_2.png) [@maflister](https://discourse.openondemand.org/u/maflister)\
**Post date:** [February 4, 2022, 8:18pm UTC](https://discourse.openondemand.org/t/rstudio-server-fails-to-start-with-database-error/1895/12 "2022-02-04T20:18:59Z")

</div>

If you have a vanilla install, Rprofile.site will not be present. If you found `/usr/local/lib64/R/etc`, which is likely if you have a package manager install, you can create the file. If you have a non-standard install path, you’ll need to look for the `lib64/R/etc` path in your R install root.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex015/uploads/osc/original/2X/b/bae70bd0ed39a3ae769c2108155f4cb3e9da8385.png) [@system](https://discourse.openondemand.org/u/system)\
**Post date:** [August 3, 2022, 8:19pm UTC](https://discourse.openondemand.org/t/rstudio-server-fails-to-start-with-database-error/1895/13 "2022-08-03T20:19:04Z")

</div>

Closed on August 3, 2022, 8:19pm UTC

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
