Skip to content

Connect

posit-connect

Reports on Connect. It prints the version from /opt/rstudio-connect/bin/connect --version, the state of the rstudio-connect service, and rstudio-connect.gcfg. It then checks:

  • Server.Address, whether anything listens on HTTP.Listen and HTTPS.Listen, whether the address answers, and the HTTPS certificate if one is set.
  • Authentication.Provider, Lifetime, and Inactivity, and Applications.RunAsCurrentUser.
  • Every R.Executable, Python.Executable, and Quarto.Executable, each with its version, or a warning if the path is missing. Each setting can be listed more than once, one entry per installation.1 It warns about Server.RVersion, Server.RVersionScanning, and Server.RVersionMatching, which were removed in Connect 2024.09.0 in favor of R.Executable, R.ExecutableScanning, and R.VersionMatching,2 and prints R.ExecutableScanning, R.VersionMatching, and Python.VersionMatching.
  • Whether the SMTP host and port accept a TCP connection, and SMTP.StartTLS.
  • Free space for Server.DataDir (default /var/lib/rstudio-connect) and the log directory.

rstudio-connect.gcfg is installed owned by root with mode 0600, and the data directory is owned by root.3 On a default install, most of this report needs root. If the configuration file is not readable, the script stops after the service status and defers the rest. Ask your sudo administrator for a copy of the file with secrets removed, and point the script at it with POSIT_CONNECT_CONF. The diagnostics report and the data directory size are always deferred.

posit-connect
POSIT_CONNECT_CONF=~/rstudio-connect.gcfg posit-connect

The script needs posit-lib.sh in the same directory.

Source: scripts/posit-connect
#!/bin/bash
#
# posit-connect: report on Posit Connect without root.
#
# Shows the version, service, configuration, listening ports, the public
# address, configured R, Python, and Quarto executables, SMTP reachability,
# and the data directory. Checks that need root are printed at the end as
# commands for the sudo administrator.
#
# Usage: posit-connect
#

# Report scripts keep going when one check fails, so -e is not set
set -uo pipefail

# shellcheck source=posit-lib.sh
. "$(dirname "$(readlink -f "$0")")/posit-lib.sh" || exit 1

readonly DEFAULT_CONF='/etc/rstudio-connect/rstudio-connect.gcfg'
readonly CONF="${POSIT_CONNECT_CONF:-${DEFAULT_CONF}}"
readonly CONNECT_BIN='/opt/rstudio-connect/bin/connect'

#######################################
# Print each R, Python, and Quarto setting with its path, one per line.
# Connect accepts R paths from the R section and, in older files, the
# Server section.
# Globals:
#   CONF
# Outputs:
#   "SETTING PATH" lines.
#######################################
executables() {
  gcfg_values "${CONF}" R Executable | sed 's/^/R.Executable /'
  gcfg_values "${CONF}" Server RVersion | sed 's/^/Server.RVersion /'
  gcfg_values "${CONF}" Python Executable | sed 's/^/Python.Executable /'
  gcfg_values "${CONF}" Quarto Executable | sed 's/^/Quarto.Executable /'
}

main() {
  local address
  local section
  local listen
  local k
  local v
  local setting
  local path
  local exe
  local smtp_host
  local smtp_port
  local data_dir
  local removed='was removed in Connect 2024.09.0; the R section replaces it'

  report_start "Posit Connect report"

  header "Version and service"
  if [[ -x "${CONNECT_BIN}" ]]; then
    item "Version" "$("${CONNECT_BIN}" --version 2>/dev/null | head -n 1)"
  else
    item "Version" "${CONNECT_BIN} not found"
  fi
  unit_status rstudio-connect

  header "Configuration"
  config_file "rstudio-connect.gcfg" "${CONF}"
  if [[ ! -r "${CONF}" ]]; then
    print_deferred
    exit 0
  fi

  header "Addresses"
  address="$(gcfg_value "${CONF}" Server Address)"
  item "Server.Address" "${address:-not set}"
  for section in HTTP HTTPS; do
    listen="$(gcfg_value "${CONF}" "${section}" Listen)"
    [[ -z "${listen}" ]] && continue
    check_listen "${section}.Listen" "${listen%:*}" "${listen##*:}"
  done
  [[ -n "${address}" ]] && http_check "Address reachable" "${address}"
  cert_check "HTTPS certificate" \
    "$(gcfg_value "${CONF}" HTTPS Certificate)" \
    "$(gcfg_value "${CONF}" HTTPS Key)"

  header "Authentication"
  for k in Provider Lifetime Inactivity; do
    v="$(gcfg_value "${CONF}" Authentication "${k}")"
    item "Authentication.${k}" "${v:-not set}"
  done
  v="$(gcfg_value "${CONF}" Applications RunAsCurrentUser)"
  item "Applications.RunAsCurrentUser" "${v:-not set}"

  header "R, Python, and Quarto"
  while read -r setting path; do
    exe="${path}"
    # Server.RVersion names an R installation directory, not the R binary
    [[ -d "${path}" ]] && exe="${path}/bin/R"
    if [[ -x "${exe}" ]]; then
      item "${setting}" "${path} ($(version_of "${exe}"))"
    else
      warn "${setting} ${path}: not found or not executable"
    fi
  done < <(executables)
  for k in RVersion RVersionScanning RVersionMatching; do
    if [[ -n "$(gcfg_value "${CONF}" Server "${k}")" ]]; then
      warn "Server.${k} ${removed}"
    fi
  done
  for k in R.ExecutableScanning R.VersionMatching Python.VersionMatching; do
    v="$(gcfg_value "${CONF}" "${k%%.*}" "${k#*.}")"
    item "${k}" "${v:-not set}"
  done

  header "Email"
  smtp_host="$(gcfg_value "${CONF}" SMTP Host)"
  if [[ -n "${smtp_host}" ]]; then
    smtp_port="$(gcfg_value "${CONF}" SMTP Port)"
    tcp_check "SMTP" "${smtp_host}" "${smtp_port:-25}"
    item "SMTP.StartTLS" "$(gcfg_value "${CONF}" SMTP StartTLS)"
  else
    item "SMTP.Host" "not set"
  fi

  header "Data and logs"
  data_dir="$(gcfg_value "${CONF}" Server DataDir)"
  dir_size "Connect data" "${data_dir:-/var/lib/rstudio-connect}"
  log_dir "Connect logs" /var/log/rstudio/rstudio-connect
  defer "Diagnostics report" \
    "sudo /opt/rstudio-connect/scripts/run-diagnostics.sh"

  print_deferred
}

main "$@"