Hello there,
Our team has been trying to install and use JTOP on our Balena devices recently. However, as you can notice in the image below, the first step to use it along with Docker is to install it on the Host and share the JTOP volume. So, by my understanding of Balena, that’s kind of impossible.
Reference
Even trying to install it directly on the main service running on the board, results in:
$ jtop
> The jtop.service is not active. Please run:
> sudo systemctl restart jtop.service
$ systemctl restart jtop.service
> System has not been booted with systemd as init system (PID 1). Can't operate.
> Failed to connect to bus: Host is down
We’ve tried to follow the guide balenalib-systemd-example without real success. The board just keeps in a loop starting the service 
So, have you guys ever tried to use JTOP on a Balena device?
We have managed to solve it!
Example:
Dockerfile
RUN pip3 install jetson-stats~=4.2.4
######################
# Setup systemd
######################
RUN apt-get update && apt-get install -y --no-install-recommends \
systemd-sysv \
dbus \
systemd \
&& rm -rf /var/lib/apt/lists/*
# We never want these to run in a container
# Feel free to edit the list but this is the one we used
RUN systemctl mask \
dev-hugepages.mount \
sys-fs-fuse-connections.mount \
sys-kernel-config.mount \
display-manager.service \
getty@.service \
systemd-logind.service \
systemd-remount-fs.service \
getty.target \
graphical.target
COPY systemd/entry.sh /workspace/app/scripts/entry.sh
RUN chmod +x /workspace/app/scripts/entry.sh \
&& systemctl enable /etc/systemd/system/jtop.service \
&& sed -i '98d' /usr/local/lib/python3.10/dist-packages/jtop/__main__.py
STOPSIGNAL 37
######################
# Finish setup systemd
######################
ENTRYPOINT ["/workspace/app/scripts/entry.sh"]
entry.sh
#!/bin/bash
set -m
GREEN='\033[0;32m'
echo -e "${GREEN}Systemd init system enabled."
# systemd causes a POLLHUP for console FD to occur
# on startup once all other processes have stopped.
# We need this sleep to ensure this doesn't occur, else
# logging to the console will not work.
sleep infinity &
for var in $(compgen -e); do
printf '%q=%q\n' "$var" "${!var}"
done > /etc/docker.env
(sleep 10 && systemctl restart jtop.service && systemctl restart balena_start.service) &
systemctl start /etc/systemd/system/jtop.service
systemctl start /etc/systemd/system/balena_start.service
exec /lib/systemd/systemd --log-level=emerg
However, we should use another “service” to run our basic stack. This could be messy.
balena_start.service
[Unit]
Description=Balena Start
After=network.target
[Service]
Type=simple
ExecStart=/workspace/app/balena_start.sh
StandardOutput=journal+console
StandardError=journal+console
WorkingDirectory=/workspace/app
Restart=always
EnvironmentFile=/etc/docker.env
[Install]
WantedBy=multi-user.target