Skip to content

Commit

Permalink
First version of systemd control panel
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesread committed Apr 3, 2024
1 parent 457e9d0 commit 8fa12a6
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 0 deletions.
34 changes: 34 additions & 0 deletions configs/systemd-control-panel/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
actions:
- title: Stop {{ systemd_unit.unit }}
shell: systemctl stop {{ systemd_unit.unit }}
icon: <iconify-icon icon="zondicons:hand-stop"></iconify-icon>
entity: systemd_unit
trigger: Update services file

- title: Start {{ systemd_unit.unit }}
shell: systemctl start {{ systemd_unit.unit }}
icon: <iconify-icon icon="ic:round-directions-run"></iconify-icon>
entity: systemd_unit
trigger: Update services file

- title: Update services file
shell: systemctl list-units -a -o json --no-pager | jq -c 'map(select (.unit | contains ("upsilon", "podman", "boot.mount"))) | .[]' > /etc/OliveTin/entities/systemd_units.json
hidden: true
execOnStartup: true

entities:
- file: /etc/OliveTin/entities/systemd_units.json
name: systemd_unit

dashboards:
- title: My Services
contents:
- title: '{{ systemd_unit.description }}'
type: fieldset
entity: systemd_unit
contents:
- title: 'Status: {{ systemd_unit.sub }}'
type: display

- title: Start {{ systemd_unit.unit }}
- title: Stop {{ systemd_unit.unit }}
4 changes: 4 additions & 0 deletions configs/systemd-control-panel/systemd_units.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{"unit":"boot.mount","load":"loaded","active":"active","sub":"mounted","description":"/boot"}
{"unit":"podman.service","load":"loaded","active":"inactive","sub":"dead","description":"Podman API Service"}
{"unit":"upsilon-drone.service","load":"loaded","active":"active","sub":"running","description":"upsilon-drone"}
{"unit":"podman.socket","load":"loaded","active":"active","sub":"listening","description":"Podman API Socket"}
Binary file added images/solution-systemd-control-panel.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
44 changes: 44 additions & 0 deletions solution_systemd_control_panel.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
[#systemd-control-panel]
=== Systemd Control Panel

OliveTin can be used to manage selected systemd units (services) as well. This is powered by OliveTin's powerful entity support. Here is a screenshot of what that can look like (dark theme preference enabled).

image::images/solution-systemd-control-panel.png[]

NOTE: To control systemd, you will need the root user. If you are running OliveTin systemd service itself, then OliveTin should be configured to run as root. The alternative is to use OliveTin in a container, and use <<action-ssh,SSH>> to connect back to the host (as a user that can manage systemd -usually root). This is not an OliveTin limitation, it's just how systemd security works.

==== Entity file

To build this Systemd Control dashboard, we use an <<entities,entity>> file that stores and updates produced by `systemctl list-units..`, output to a json format, and then filtered with jq (JSON Query). Here is the full command that we will use in our config later;

----
user@host: systemctl list-units -a -o json --no-pager | jq -c 'map(select (.unit | contains ("upsilon", "podman", "boot.mount"))) | .[]' > /etc/OliveTin/entities/systemd_units.json
----

That command will generate a file (example shown below). Let's break down that long command a little bit to explain what it is doing;

. `systemctl list-units -a -o json --no-pager` - will list units, regardless of status - started, stopped, etc (`-a`), in JSON format, and output the results
. `jq` (JSON Query) will select units from that output that match "upsilon", "podman", "boot.mount", and of course you can change this expression to add your own services.
. The `map()` and `.[]` parts of the expression basically just put those units line by line into the file

[source,json]
.An example generated `/etc/OliveTin/entities/systemd_units.json` file
----
include::configs/systemd-control-panel/systemd_units.json[]
----

You can generate this file yourself the first time, but the `config.yaml` below shows how OliveTin can run the `systemctl list-units ...` command on startup, and on a schedule to update the file.

Note that if the file does not exist the first time OliveTin starts up, then OliveTin will will issue an error about not finding the file to monitor it. An easy way around this is to simply restart OliveTin a 2nd time, so that on the 2nd startup it will find the file (because it will be created the first time OliveTin starts up).

==== Configuration

Finally, here is the example configuration file to build the dashboard;

[source,yaml]
.`config.yaml`
----
include::configs/systemd-control-panel/config.yaml[]
----


1 change: 1 addition & 0 deletions solutions.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ OliveTin was designed to be very simple, but sometimes OliveTin can get complex
This section of the docs is designed to bring everything into one place and present a scenario, with a single-page solution.

include::solution_container_control_panel.adoc[]
include::solution_systemd_control_panel.adoc[]
include::solution_heating_control_panel.adoc[]

=== GPIO Control on Raspberry Pi
Expand Down

0 comments on commit 8fa12a6

Please sign in to comment.