Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,19 @@ or
sudo pip3 install --break-system-packages git+https://github.com/rbonghi/jetson_stats.git
```

### Option 4: Ubuntu 24.04 run jtop without sudo and without "--break-system-packages"
```console
First run "sudo -v"
-v, --validate does not run any command, but does allow the use of sudo in the bash script.
Then "download install_jtop_torun_without_sudo.sh"
Make it executible:
chmod +x install_jtop_torun_without_sudo.sh
Then run it:
./install_jtop_torun_without_sudo.sh
```
See the full guide: [How it works & why](docs/nosudo.rst)

```
_Don't forget to **logout/login** or **reboot** your board_

<div align="center">
Expand Down
53 changes: 53 additions & 0 deletions docs/nosudo.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
🧩 How it works
===============

The ``install_jtop_torun_without_sudo.sh`` script automates a safe,
user-friendly installation of **jtop** that allows you to run it without
``sudo``. It performs the following steps:

1. **Safety check**

- Refuses to run if invoked as ``root`` or via ``sudo``.
- Instructs you to run ``sudo -v`` first so that later privileged
commands (``apt``, ``systemctl``) can execute without repeated password prompts.

2. **Prepare environment**

- Verifies whether ``pip3`` and ``pipx`` are installed; if either is missing, installs them via ``apt``.
- Ensures ``~/.local/bin`` is on your ``PATH`` so that ``pipx`` applications are available in future shells.

3. **Install jtop via pipx**

- Uses ``pipx install "git+https://github.com/rbonghi/jetson_stats.git"`` to install the latest version in an isolated user environment.
- Determines the correct executable path (usually ``~/.local/bin/jtop`` or inside the pipx venv).

4. **Systemd service setup**

- Creates or updates ``/etc/systemd/system/jtop.service`` to point to your user’s jtop binary.
- Sets safe defaults (``Restart=on-failure``, ``RestartSec=10s``, etc.) to make the service robust.

5. **Enable and start the service**

- Reloads systemd, enables ``jtop.service`` to start automatically at boot,
and restarts it immediately.

6. **Result**

After installation, you can simply launch jtop from your terminal
as a normal user (no ``sudo`` required):

.. code-block:: bash

jtop


Why use this method
===================

.. code-block:: text

• Keeps the system (root) Python environment clean and untouched
• Uses pipx’s isolation, making upgrades and uninstalls clean and safe
• Fully compatible with Ubuntu 24.04+ and later Debian-based systems
• Ensures jtop runs under your user account (avoids root-owned processes)
• Provides systemd integration for automatic startup and recovery
75 changes: 75 additions & 0 deletions install_jtop_torun_without_sudo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/usr/bin/env bash
set -euo pipefail

PKG_NAME="jetson_stats"
APP_NAME="jtop"
SYSTEMD_UNIT="jtop.service"

if [[ $EUID -eq 0 ]]; then
echo "Please first run 'sudo -v'"
echo "Then run this script by itself, NOT with sudo"
exit 1
fi

echo "Ensuring pip3 & pipx exist"

need_update=0
to_install=()

if ! command -v pip3 >/dev/null 2>&1; then
to_install+=("python3-pip")
need_update=1
fi

if ! command -v pipx >/dev/null 2>&1; then
to_install+=("pipx")
need_update=1
fi

if (( need_update )); then
echo "Missing: ${to_install[*]} → installing via apt"
sudo apt-get update
sudo apt-get install -y "${to_install[@]}"
else
echo "pip3 and pipx already installed."
fi

# Make sure future shells have ~/.local/bin in PATH (no-op if already set)
pipx ensurepath || true

echo "Installing ${APP_NAME} with pipx"
pipx install "git+https://github.com/rbonghi/jetson_stats.git"

JTOP_BIN="$HOME/.local/bin/${APP_NAME}"
[ -x "$JTOP_BIN" ] || JTOP_BIN="$HOME/.local/share/pipx/venvs/${PKG_NAME}/bin/${APP_NAME}"

echo "Ensuring a systemd unit exists and points to ${JTOP_BIN}"
UNIT_FILE="/etc/systemd/system/${SYSTEMD_UNIT}"
if [ ! -f "${UNIT_FILE}" ]; then
# Create a minimal unit if repo didn't install one
echo "Creating ${UNIT_FILE}…"
sudo tee "${UNIT_FILE}" >/dev/null <<EOF
[Unit]
Description=Jetson Stats (jtop)
After=network.target

[Service]
Environment="JTOP_SERVICE=True"
ExecStart=${JTOP_BIN} --force
Restart=on-failure
RestartSec=10s
TimeoutStartSec=30s
TimeoutStopSec=30s

[Install]
WantedBy=multi-user.target
EOF
fi

echo "Enabling and starting ${SYSTEMD_UNIT}…"
sudo systemctl daemon-reload
sudo systemctl enable "${SYSTEMD_UNIT}"
sudo systemctl restart "${SYSTEMD_UNIT}"

echo
echo "You can now run '${APP_NAME}' sudo NOT needed)."
Loading