Skip to content

Instantly share code, notes, and snippets.

@jtmoon79
Last active October 26, 2022 02:33
Show Gist options
  • Save jtmoon79/1bd435862f7fd06cf1ed98ce9b05f672 to your computer and use it in GitHub Desktop.
Save jtmoon79/1bd435862f7fd06cf1ed98ce9b05f672 to your computer and use it in GitHub Desktop.
start glances, single instance, user glances
#!/usr/bin/env bash
#
# run single instance of glances on the system as user glances.
# follows from https://gist.github.com/jtmoon79/1b5a806b3e71874542c21b1578156a42
# designed for a Debian-based Linux
#
# place this file at /var/lib/glances/glances-start.sh
# chmod +x /var/lib/glances/glances-start.sh
# should look like:
# ls -l /var/lib/glances/glances-start.sh
# -rwxr-xr-x 1 root root 620 Jul 14 11:40 /var/lib/glances/glances-start.sh
#
set -e
set -u
if [ "$(whoami)" != "glances" ]; then
set -x
exec sudo -u glances -- "${0}" "${@}"
fi
if pgrep --exact glances &>/dev/null; then
pkill --echo glances
fi
export VENV_GLANCES="/var/lib/glances/.venv-glances"
if [[ ! -d "${VENV_GLANCES}" ]]; then
echo "Virtual Environment path not found '${VENV_GLANCES}'" >&2
exit 1
fi
set +u
source "${VENV_GLANCES}/bin/activate"
set -u
python --version
glances --version
set -x
# XXX: glances does not seem to output anything if stdout/stderr are redirected to a file
glances \
--webserver \
--debug \
--diskio-show-ramfs \
--diskio-iops \
--fs-free-space \
--byte \
--enable-process-extended \
&>/var/lib/glances/glances.log &
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment