liquidctl

This commit is contained in:
2023-12-22 14:35:22 -05:00
parent c01611317a
commit fb3a0471b7
6 changed files with 90 additions and 11 deletions

25
_grains/lsusb.py Normal file
View File

@@ -0,0 +1,25 @@
import re
from subprocess import check_output
def main():
dev_re = re.compile(r"Bus\s+(\d+)\s+Device\s+(\d+):\s+ID\s(\w+:\w+)\s(.+)$")
lsusb = check_output("lsusb", encoding='UTF-8')
devices = []
corsair_aio = None
for line in lsusb.splitlines():
info = dev_re.match(line)
if not info:
continue
bus, device, dev_id, tag = info.groups()
dev_info = {
"device": f"/dev/bus/usb/{bus}/{device}",
"id": dev_id,
"tag": tag,
}
if tag.startswith('Corsair H'):
corsair_aio = tag.split(maxsplit=3)[1]
devices.append(dev_info)
return {
'corsair_aio': corsair_aio,
'lsusb': devices,
}

View File

@@ -0,0 +1,11 @@
[Unit]
Description=AIO startup service
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/root/liquidctl/bin/liquidctl --match {{ salt.grains.get('corsair_aio') }} initialize --pump-mode=extreme
ExecStart=/root/liquidctl/bin/liquidctl --match {{ salt.grains.get('corsair_aio') }} set fan speed 90
[Install]
WantedBy=default.target

36
liquidctl/init.sls Normal file
View File

@@ -0,0 +1,36 @@
# Ref: https://github.com/liquidctl/liquidctl#set-up-linux-using-systemd
{% set venv = '/usr/local/lib/liquidctl' %}
setup liquidctl venv:
cmd.run:
- name: python3 -m venv {{ venv }}
- creates: {{ venv }}
install liquidctl:
cmd.run:
- name: {{ venv }}/bin/pip3 install liquidctl
- unless: /usr/local/lib/liquidctl/bin/pip3 freeze | grep -q ^liquidctl==
- require:
- cmd: setup liquidctl venv
/etc/systemd/system/liquidcfg.service:
file.managed:
- template: jinja
- user: root
- group: root
- mode: 644
- source: salt://liquidctl/files/liquidcfg.service
systemd reload for liquidcfg.service:
module.run:
- name: service.systemctl_reload
- onchanges:
- file: /etc/systemd/system/liquidcfg.service
liquidcfg.service:
service.running:
- enable: true
- watch:
- file: /etc/systemd/system/liquidcfg.service
- module: systemd reload for liquidcfg.service

11
salt/configs.sls Normal file
View File

@@ -0,0 +1,11 @@
{% from "salt/map.jinja" import salt_daemons with context %}
{% for daemon in salt_daemons %}
/etc/salt/{{ daemon }}:
file.managed:
- source: salt://salt/files/{{ daemon }}.jinja
- template: jinja
- user: root
- group: root
- mode: 644
{% endfor %}

View File

@@ -1,6 +1,5 @@
{% from "salt/map.jinja" import salt_daemons with context %}
include:
- salt.configs
{% if grains['osarch'].lower().startswith('arm') %}
- salt.pypi_install
{% elif grains['os_family'] == 'Debian' %}
@@ -11,12 +10,6 @@ include:
{{ raise("Unsupported grains.os") }}
{% endif %}
{% for daemon in salt_daemons %}
/etc/salt/{{ daemon }}:
file.managed:
- source: salt://salt/files/{{ daemon }}.jinja
- template: jinja
- user: root
- group: root
- mode: 644
{% endfor %}
saltutil.sync_all:
saltutil.sync_all:
- refresh: True

View File

@@ -13,6 +13,9 @@
{% endif %}
{% if salt.pillar.get("gitea", None) is not none %}
- gitea
{% endif %}
{% if salt.grains.get('corsair_aio', None) %}
- liquidctl
{% endif %}
'*.keiran.us':
- firewall