From 431e38fec481403e3b4864186dac7132c9043034 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Sat, 27 May 2023 11:59:37 +0200 Subject: [PATCH] Implemented autostart of caffeine with the help of chat gpt: https://chat.openai.com/share/fa846dac-6068-4386-b3e7-b75f1248ec82 --- roles/pc_application-caffeine/tasks/main.yml | 5 ----- .../pc_application_caffeine/defaults/main.yml | 2 ++ .../pc_application_caffeine/handlers/main.yml | 10 ++++++++++ .../meta/main.yml | 0 roles/pc_application_caffeine/tasks/main.yml | 19 +++++++++++++++++++ .../templates/caffeine.service.j2 | 8 ++++++++ 6 files changed, 39 insertions(+), 5 deletions(-) delete mode 100644 roles/pc_application-caffeine/tasks/main.yml create mode 100644 roles/pc_application_caffeine/defaults/main.yml create mode 100644 roles/pc_application_caffeine/handlers/main.yml rename roles/{pc_application-caffeine => pc_application_caffeine}/meta/main.yml (100%) create mode 100644 roles/pc_application_caffeine/tasks/main.yml create mode 100644 roles/pc_application_caffeine/templates/caffeine.service.j2 diff --git a/roles/pc_application-caffeine/tasks/main.yml b/roles/pc_application-caffeine/tasks/main.yml deleted file mode 100644 index 738d4211..00000000 --- a/roles/pc_application-caffeine/tasks/main.yml +++ /dev/null @@ -1,5 +0,0 @@ -- name: Install caffeine - kewlfft.aur.aur: - use: yay - name: - - caffeine-ng \ No newline at end of file diff --git a/roles/pc_application_caffeine/defaults/main.yml b/roles/pc_application_caffeine/defaults/main.yml new file mode 100644 index 00000000..33ebdaf6 --- /dev/null +++ b/roles/pc_application_caffeine/defaults/main.yml @@ -0,0 +1,2 @@ +# Defaults for caffeine_auto_start role +caffeine_executable_path: "/usr/bin/caffeine" diff --git a/roles/pc_application_caffeine/handlers/main.yml b/roles/pc_application_caffeine/handlers/main.yml new file mode 100644 index 00000000..691b5cae --- /dev/null +++ b/roles/pc_application_caffeine/handlers/main.yml @@ -0,0 +1,10 @@ +# handlers file for caffeine_auto_start +- name: reload systemd + command: systemctl daemon-reload + +- name: enable and start caffeine + systemd: + name: caffeine.service + state: started + enabled: yes + daemon_reload: yes diff --git a/roles/pc_application-caffeine/meta/main.yml b/roles/pc_application_caffeine/meta/main.yml similarity index 100% rename from roles/pc_application-caffeine/meta/main.yml rename to roles/pc_application_caffeine/meta/main.yml diff --git a/roles/pc_application_caffeine/tasks/main.yml b/roles/pc_application_caffeine/tasks/main.yml new file mode 100644 index 00000000..1482282f --- /dev/null +++ b/roles/pc_application_caffeine/tasks/main.yml @@ -0,0 +1,19 @@ +- name: install caffeine + kewlfft.aur.aur: + use: yay + name: + - caffeine-ng + +- name: Check if caffeine is installed + command: command -v caffeine + register: caffeine_installed + changed_when: False + failed_when: caffeine_installed.rc != 0 + +- name: Copy caffeine systemd service file + template: + src: caffeine.service.j2 + dest: /etc/systemd/system/caffeine.service + notify: + - reload systemd + - enable and start caffeine diff --git a/roles/pc_application_caffeine/templates/caffeine.service.j2 b/roles/pc_application_caffeine/templates/caffeine.service.j2 new file mode 100644 index 00000000..0db8da26 --- /dev/null +++ b/roles/pc_application_caffeine/templates/caffeine.service.j2 @@ -0,0 +1,8 @@ +[Unit] +Description=Caffeine auto start + +[Service] +ExecStart={{ caffeine_executable_path }} + +[Install] +WantedBy=multi-user.target