-
-
Notifications
You must be signed in to change notification settings - Fork 299
docs: add no-sudo jtop install guide and helper script #725
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
whitesscott
wants to merge
3
commits into
rbonghi:master
Choose a base branch
from
whitesscott:jtop-without-sudo
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)." |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.