Host¶
posit-host¶
Reports on the server underneath the Posit products. It prints:
- System: the OS, kernel, uptime, CPU count and model, and memory.
- Disk: the size and use of
/,/opt,/var/lib,/var/log,/home, and/tmp, with a warning for any filesystem over 80% full. - Network: the interfaces, the default route, and the FQDN.
- DNS: the name servers and search domains in
/etc/resolv.conf, and whetherDNS_TEST_HOSTresolves. - Ports: the listening TCP ports.
- Services: the state of Workbench, Launcher, Connect, Package Manager,
httpd, andnginx. - Security: the SELinux mode and the firewall rules.
- Runtimes: R under
/opt/R, Python under/opt/python, and Quarto under/opt/quartoplus the copy bundled with Workbench. PATH: theR,python3, andquartoon yourPATH.
Workbench and Connect find R under /opt/R. Connect's starter configuration scans /opt/python, and Workbench recommends installing Python under /opt.1234
Without root, it cannot show which process owns each listening port or the size of other users' home directories. On some hosts it also cannot read the firewall rules. Those checks are deferred.
The script needs posit-lib.sh in the same directory.
Source: scripts/posit-host
#!/bin/bash
#
# posit-host: report on the server underneath the Posit products, without root.
#
# Shows the OS, CPU, memory, filesystems, network interfaces, DNS, listening
# TCP ports, Posit and proxy services, SELinux, the firewall, and the R,
# Python, and Quarto installations. Checks that need root are printed at
# the end as commands for the sudo administrator.
#
# Usage: posit-host
#
# 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
FQDN="$(hostname -f 2>/dev/null || hostname)"
readonly FQDN
readonly DNS_TEST_HOST="${DNS_TEST_HOST:-${FQDN}}"
readonly MOUNTS=(/ /opt /var/lib /var/log /home /tmp)
readonly UNITS=(
rstudio-server rstudio-launcher rstudio-connect rstudio-pm httpd nginx
)
readonly WB_QUARTO='/usr/lib/rstudio-server/bin/quarto/bin/quarto'
#######################################
# Print the OS name from /etc/os-release.
#######################################
os_name() {
(
# shellcheck source=/dev/null
. /etc/os-release 2>/dev/null && echo "${PRETTY_NAME}" || echo unknown
)
}
#######################################
# Print the CPU count and model.
#######################################
cpu_summary() {
local model
model="$(lscpu 2>/dev/null | awk -F: '
/^Model name/ { gsub(/^[ \t]+/, "", $2); print $2; exit }')"
echo "$(nproc) (${model})"
}
#######################################
# Print each R, Python, and Quarto installation under /opt.
#######################################
installed_tools() {
local r
local py
local q
shopt -s nullglob
for r in /opt/R/*/bin/R; do
[[ -x "${r}" ]] && item "${r}" "$(version_of "${r}")"
done
for py in /opt/python/*/bin/python3 /opt/python/*/bin/python; do
[[ -x "${py}" ]] && item "${py}" "$(version_of "${py}")"
done
for q in /opt/quarto/*/bin/quarto /opt/quarto/bin/quarto "${WB_QUARTO}"; do
[[ -x "${q}" ]] && item "${q}" "$(version_of "${q}")"
done
shopt -u nullglob
}
main() {
local unit
local rules
local cmd
report_start "Posit host report"
header "System"
item "OS" "$(os_name)"
item "Kernel" "$(uname -r)"
item "Uptime" "$(uptime -p 2>/dev/null || uptime)"
item "CPUs" "$(cpu_summary)"
item "Memory" "$(free -h \
| awk '/^Mem:/ { print $2 " total, " $7 " available" }')"
header "Filesystems"
df -hP "${MOUNTS[@]}" 2>/dev/null | awk '!seen[$6]++' | sed 's/^/ /'
df -P "${MOUNTS[@]}" 2>/dev/null \
| awk 'NR > 1 && $5 + 0 > 80 { print " WARNING: " $6 " is " $5 " full" }' \
| sort -u
header "Network"
item "FQDN" "${FQDN}"
ip -brief address 2>/dev/null | sed 's/^/ /'
item "Default route" "$(ip route show default 2>/dev/null | head -n 1)"
header "DNS"
grep -E '^[[:space:]]*(nameserver|search|domain)[[:space:]]' \
/etc/resolv.conf 2>/dev/null | sed 's/^/ /'
if getent ahosts "${DNS_TEST_HOST}" >/dev/null 2>&1; then
item "${DNS_TEST_HOST}" "$(getent ahosts "${DNS_TEST_HOST}" \
| awk '{ print $1 }' | sort -u | paste -sd' ' -)"
else
warn "${DNS_TEST_HOST} does not resolve"
fi
header "Listening TCP ports"
ss -Hltn 2>/dev/null | awk '{ print " " $4 }' | sort -u
defer "Process owning each port" "sudo ss -ltnp"
header "Services"
for unit in "${UNITS[@]}"; do
unit_status "${unit}"
done
header "Security"
item "SELinux" "$(getenforce 2>/dev/null || echo 'getenforce not found')"
if ! command -v firewall-cmd >/dev/null 2>&1; then
item "firewalld" "firewall-cmd not found"
elif rules="$(firewall-cmd --list-all 2>/dev/null)"; then
printf ' %s\n' "${rules//$'\n'/$'\n' }"
else
item "firewalld" "$(firewall-cmd --state 2>&1)"
defer "Firewall rules" "sudo firewall-cmd --list-all"
fi
header "R, Python, and Quarto"
installed_tools
for cmd in R python3 quarto; do
if command -v "${cmd}" >/dev/null 2>&1; then
item "${cmd} on PATH" \
"$(command -v "${cmd}") ($(version_of "${cmd}"))"
fi
done
header "Home directories"
item "Your home" "$(du -xsh -- "${HOME}" 2>/dev/null | cut -f1) in ${HOME}"
defer "Largest home directories" \
"sudo du -xsh /home/* | sort -rh | head -n 20"
print_deferred
}
main "$@"