mirror of
https://github.com/aljazceru/gcups.git
synced 2025-12-17 05:14:23 +01:00
feat: Add udev rules configuration script, fix CI, change docker wording to container when refering to OCI images
This commit is contained in:
2
.github/workflows/docker-publish.yaml
vendored
2
.github/workflows/docker-publish.yaml
vendored
@@ -63,7 +63,7 @@ jobs:
|
|||||||
id: build-and-push
|
id: build-and-push
|
||||||
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0
|
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0
|
||||||
with:
|
with:
|
||||||
context: .
|
context: gcups
|
||||||
push: ${{ github.event_name != 'pull_request' }}
|
push: ${{ github.event_name != 'pull_request' }}
|
||||||
tags: ${{ steps.meta.outputs.tags }}
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
labels: ${{ steps.meta.outputs.labels }}
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
|
|||||||
26
README.md
26
README.md
@@ -1,9 +1,9 @@
|
|||||||
<!--
|
<!--
|
||||||
SPDX-FileCopyrightText: 2024 Damian Fajfer <damian@fajfer.org>
|
SPDX-FileCopyrightText: 2024-2025 Damian Fajfer <damian@fajfer.org>
|
||||||
|
|
||||||
SPDX-License-Identifier: CC-BY-SA-4.0
|
SPDX-License-Identifier: CC-BY-SA-4.0
|
||||||
-->
|
-->
|
||||||
# GreenCell UPS App in docker
|
# GreenCell UPS App in container
|
||||||
GC UPS App is a program that enables preview in real time and displays measurement data including input and output voltages, load frequency of the UPS, its temperature and battery capacity.
|
GC UPS App is a program that enables preview in real time and displays measurement data including input and output voltages, load frequency of the UPS, its temperature and battery capacity.
|
||||||
|
|
||||||
You can setup automatic system shut-off, notifications and email warnings in the event of switching to batter operation.
|
You can setup automatic system shut-off, notifications and email warnings in the event of switching to batter operation.
|
||||||
@@ -12,7 +12,7 @@ You can setup automatic system shut-off, notifications and email warnings in the
|
|||||||
> I am not affiliated with GREENCELL.GLOBAL brand, I don't represent and I was never employed by CSG S.A. nor I was ever contracted by them for doing any work whatsoever
|
> I am not affiliated with GREENCELL.GLOBAL brand, I don't represent and I was never employed by CSG S.A. nor I was ever contracted by them for doing any work whatsoever
|
||||||
|
|
||||||
## About
|
## About
|
||||||
I took the desktop-only electron app and forced it to run in docker with HTTP webUI enabled. I wrote a [blog entry](https://blog.fajfer.org/2023/09/16/running-green-cell-ups-app-gcups-on-gnu-linux-server/) regarding the subject.
|
I took the desktop-only electron app and forced it to run in container with HTTP webUI enabled. I wrote a [blog entry](https://blog.fajfer.org/2023/09/16/running-green-cell-ups-app-gcups-on-gnu-linux-server/) regarding the subject.
|
||||||
|
|
||||||
Join us on [Matrix](https://matrix.to/#/#gcups:fsfe.org) to discuss and troubleshoot!
|
Join us on [Matrix](https://matrix.to/#/#gcups:fsfe.org) to discuss and troubleshoot!
|
||||||
|
|
||||||
@@ -30,25 +30,35 @@ Table of Contents
|
|||||||
|
|
||||||
## Quick Start
|
## Quick Start
|
||||||
For testing purposes (to see if this thing works on your machine) you can run the container in `privileged` mode but this is not recommended, [read](https://learn.snyk.io/lesson/container-runs-in-privileged-mode/).
|
For testing purposes (to see if this thing works on your machine) you can run the container in `privileged` mode but this is not recommended, [read](https://learn.snyk.io/lesson/container-runs-in-privileged-mode/).
|
||||||
|
|
||||||
|
1. Run the [udev.sh](udev.sh) file as root (sets up udev rules on host)
|
||||||
|
|
||||||
|
2. Run the container image as privileged
|
||||||
`docker run --privileged -p 0.0.0.0:8080:8080 ghcr.io/fajfer/gcups:1.1.7`
|
`docker run --privileged -p 0.0.0.0:8080:8080 ghcr.io/fajfer/gcups:1.1.7`
|
||||||
|
|
||||||
Image exposes port **8080** and the default password is **gcups123**
|
Image exposes port **8080** and the default password is **gcups123**
|
||||||
|
|
||||||
## How To Run It
|
## How To Run It
|
||||||
Container itself is ready to start, the only thing you need to do is to attach proper USB device:
|
The prerequisites are to:
|
||||||
|
- setup udev rules
|
||||||
|
- attach proper USB device
|
||||||
|
|
||||||
|
To setup udev rules, you need to run the [udev.sh](udev.sh) script on your host machine. The rules are taken from the official gcups apt package preinstall scripts.
|
||||||
|
|
||||||
|
Next, you need to attach proper USB device:
|
||||||
`docker run --device=/dev/bus/usb/001/011 -p 0.0.0.0:8080:8080 ghcr.io/fajfer/gcups:1.1.7`
|
`docker run --device=/dev/bus/usb/001/011 -p 0.0.0.0:8080:8080 ghcr.io/fajfer/gcups:1.1.7`
|
||||||
How to find which device to use? Read [USB detection](#usb-detection)
|
How to find which device to use? Read [USB detection](#usb-detection)
|
||||||
|
|
||||||
You can also run it via [Docker-compose](#docker-compose), for which I provided an [example](docker-compose.yaml) of. This is a desktop app that was forced inside of a container and it exposes a HTTP connection which makes you unable to configure following stuff:
|
You can also run it via [Docker-compose](#docker-compose), for which I provided an [example](docker-compose.yaml) of. This is a desktop app that was forced inside of a container and it exposes a HTTP connection which makes you unable to configure following options:
|
||||||
- enabling/disabling HTTP server
|
- enabling/disabling HTTP server
|
||||||
- changing password
|
- changing password
|
||||||
- changing HTTP server port
|
- changing HTTP server port
|
||||||
|
|
||||||
It's not much of a problem since we're using docker. You can decide to not publish the port and you can always map it to a different port on your host container so it isn't much of a problem. If you wish to change the password, however, then I recommend you read [Custom settings](#custom-settings) part.
|
You can decide to not publish the port and map it to a different port on your host container so it isn't much of a problem. If you wish to change the password, however, then I recommend you read [Custom settings](#custom-settings) part.
|
||||||
|
|
||||||
## USB detection
|
## USB detection
|
||||||
|
|
||||||
An example, based on my `UPS05`, on how to find which USB to mount to your docker.
|
An example, based on my `UPS05`, on how to find which USB to mount to your container.
|
||||||
|
|
||||||
If you plug your usb and then proceed with `sudo dmesg` you will see something like this:
|
If you plug your usb and then proceed with `sudo dmesg` you will see something like this:
|
||||||
```
|
```
|
||||||
@@ -119,4 +129,4 @@ If you are getting the following error:
|
|||||||
```
|
```
|
||||||
/opt/gcups/gcups[101]: ../../third_party/electron_node/src/node_api.cc:1332:napi_status napi_release_threadsafe_function(napi_threadsafe_function, napi_threadsafe_function_release_mode): Assertion `(func) != nullptr' failed.
|
/opt/gcups/gcups[101]: ../../third_party/electron_node/src/node_api.cc:1332:napi_status napi_release_threadsafe_function(napi_threadsafe_function, napi_threadsafe_function_release_mode): Assertion `(func) != nullptr' failed.
|
||||||
```
|
```
|
||||||
Then you have your UPS connected via USB and provided a wrong `--device` for the docker image. This will obviously make the HTTP server unable to start.
|
Then you have your UPS connected via USB and provided a wrong `--device` for the container image, passed the device from your hypervisor the wrong way or not configured udev rules. Overall, the error means that application is unable to start.
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
# SPDX-FileCopyrightText: 2024 Damian Fajfer <damian@fajfer.org>
|
# SPDX-FileCopyrightText: 2024-2025 Damian Fajfer <damian@fajfer.org>
|
||||||
#
|
#
|
||||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
version: '3'
|
version: '3'
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
# SPDX-FileCopyrightText: 2024 Damian Fajfer <damian@fajfer.org>
|
# SPDX-FileCopyrightText: 2024-2025 Damian Fajfer <damian@fajfer.org>
|
||||||
#
|
#
|
||||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
FROM docker.io/ubuntu:jammy-20240227
|
FROM docker.io/ubuntu:jammy-20240227
|
||||||
RUN apt-get update && apt-get install --no-install-recommends -y wget gpg xvfb libgbm-dev libasound2 python3-pip dbus-user-session && \
|
RUN apt-get update && apt-get install --no-install-recommends -y wget gpg xvfb libgbm-dev libasound2 python3-pip dbus-user-session && \
|
||||||
wget -qO- https://gcups-static.greencell.global/csgsa-keyring.gpg | gpg --dearmor | dd of=/usr/share/keyrings/csgsa-keyring.gpg && \
|
wget -qO- https://gcups-static.greencell.global/csgsa-keyring.gpg | gpg --dearmor | dd of=/usr/share/keyrings/csgsa-keyring.gpg && \
|
||||||
@@ -10,6 +11,8 @@ RUN apt-get update && apt-get install --no-install-recommends -y wget gpg xvfb l
|
|||||||
python3 -m pip --no-cache-dir install plyvel && \
|
python3 -m pip --no-cache-dir install plyvel && \
|
||||||
python3 -m pip --no-cache-dir uninstall setuptools wheel && \
|
python3 -m pip --no-cache-dir uninstall setuptools wheel && \
|
||||||
apt-get remove -y python3-pip && \
|
apt-get remove -y python3-pip && \
|
||||||
|
mkdir -m777 -p /opt/gcups/db && \
|
||||||
|
mkdir -m777 -p /opt/gcups/log && \
|
||||||
mkdir -m775 -p /opt/gcups/db/gcups-rxdb-1-settings && \
|
mkdir -m775 -p /opt/gcups/db/gcups-rxdb-1-settings && \
|
||||||
rm -rf /opt/gcups/license /opt/gcups/manuals && rm -rf /tmp/* && \
|
rm -rf /opt/gcups/license /opt/gcups/manuals && rm -rf /tmp/* && \
|
||||||
useradd -m gcups && chown -R gcups:gcups /opt/gcups && \
|
useradd -m gcups && chown -R gcups:gcups /opt/gcups && \
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
# SPDX-FileCopyrightText: 2024 Damian Fajfer <damian@fajfer.org>
|
#!/bin/bash
|
||||||
|
# SPDX-FileCopyrightText: 2024-2025 Damian Fajfer <damian@fajfer.org>
|
||||||
#
|
#
|
||||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
dbus-daemon --session --fork --print-address 1 > /tmp/dbus-session
|
dbus-daemon --session --fork --print-address 1 > /tmp/dbus-session
|
||||||
export DBUS_SESSION_BUS_ADDRESS=$(cat /tmp/dbus-session)
|
export DBUS_SESSION_BUS_ADDRESS=$(cat /tmp/dbus-session)
|
||||||
service dbus start
|
service dbus start
|
||||||
@@ -14,4 +13,4 @@ echo -n "Running gcups " && xvfb-run gcups --version --no-sandbox
|
|||||||
|
|
||||||
xvfb-run gcups --no-sandbox
|
xvfb-run gcups --no-sandbox
|
||||||
echo "GCUPS webserver started"
|
echo "GCUPS webserver started"
|
||||||
tail -f /opt/gcups/log/error.log
|
tail -f /opt/gcups/log/error.log
|
||||||
|
|||||||
24
udev.sh
Executable file
24
udev.sh
Executable file
@@ -0,0 +1,24 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# SPDX-FileCopyrightText: 2025 Damian Fajfer <damian@fajfer.org>
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
if [[ $(/usr/bin/id -u) -ne 0 ]]; then
|
||||||
|
echo "Not running as root"
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
UDEV_RULES_DIR=/etc/udev/rules.d
|
||||||
|
|
||||||
|
tee $UDEV_RULES_DIR/10-gcups.rules > /dev/null <<EOT
|
||||||
|
SUBSYSTEM=="input", GROUP="input", MODE="0666"
|
||||||
|
SUBSYSTEM=="usb", ATTRS{idVendor}=="0001", SYMLINK+="ups", ATTRS{idProduct}=="0000", MODE:="666", GROUP="plugdev"
|
||||||
|
KERNEL=="hidraw*", ATTRS{idVendor}=="0001", ATTRS{idProduct}=="0000", MODE="0666", GROUP="plugdev"
|
||||||
|
EOT
|
||||||
|
|
||||||
|
tee $UDEV_RULES_DIR/10-gcups17.rules > /dev/null <<EOT
|
||||||
|
SUBSYSTEM=="input", GROUP="input", MODE="0666"
|
||||||
|
SUBSYSTEM=="tty", ATTRS{idVendor}=="067b", SYMLINK+="ttyups", ATTRS{idProduct}=="2303", MODE:="666", GROUP="plugdev"
|
||||||
|
EOT
|
||||||
|
|
||||||
|
udevadm control --reload-rules
|
||||||
Reference in New Issue
Block a user