From 2ca8f11cc6f172e108218951e0270142ce8de834 Mon Sep 17 00:00:00 2001 From: Pig Monkey Date: Tue, 3 Apr 2018 19:14:46 -0700 Subject: [PATCH] run himawaripy as a user service Existing users should first stop, disable, and remove the old system timer and service: $ sudo systemctl stop himawaripy@$USER.timer $ sudo systemctl disable himawaripy@$USER.timer $ sudo rm /etc/systemd/system/himawaripy@.* If the system timer is present in the trusted unit file, remove it. --- roles/himawaripy/tasks/main.yml | 20 +++++++++++++------ .../templates/himawaripy.service.j2 | 3 +-- .../himawaripy/templates/himawaripy.timer.j2 | 2 +- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/roles/himawaripy/tasks/main.yml b/roles/himawaripy/tasks/main.yml index b46f348..0f70974 100644 --- a/roles/himawaripy/tasks/main.yml +++ b/roles/himawaripy/tasks/main.yml @@ -10,32 +10,40 @@ state=link - name: Push himawaripy service file - template: src=himawaripy.service.j2 dest=/etc/systemd/system/himawaripy@.service + template: src=himawaripy.service.j2 dest=/etc/systemd/user/himawaripy.service notify: - reload systemd config - name: Push himawaripy timer file - template: src=himawaripy.timer.j2 dest=/etc/systemd/system/himawaripy@.timer + template: src=himawaripy.timer.j2 dest=/etc/systemd/user/himawaripy.timer notify: - reload systemd config - restart himawaripy - name: Enable and start himawaripy timer - service: name="himawaripy@{{ user.name }}.timer" enabled=yes state=started + systemd: name=himawaripy.timer user=yes enabled=yes state=started + become: yes + become_user: "{{ user.name }}" + environment: + XDG_RUNTIME_DIR: "/run/user/{{ user.uid }}" when: himawaripy.run_on == "all" - name: Remove himawaripy from trusted unit list lineinfile: dest=/usr/local/etc/trusted_units state=absent - line="himawaripy@{{ user.name }}.timer" + line="himawaripy.timer,user:{{ user.name }}" when: himawaripy.run_on == "all" - name: Disable himawaripy timer - service: name="himawaripy@{{ user.name }}.timer" enabled=no + systemd: name=himawaripy.timer user=yes enabled=no + become: yes + become_user: "{{ user.name }}" + environment: + XDG_RUNTIME_DIR: "/run/user/{{ user.uid }}" when: himawaripy.run_on == "trusted" - name: Add himawaripy to trusted unit list lineinfile: dest=/usr/local/etc/trusted_units state=present - line="himawaripy@{{ user.name }}.timer" + line="himawaripy.timer,user:{{ user.name }}" when: himawaripy.run_on == "trusted" diff --git a/roles/himawaripy/templates/himawaripy.service.j2 b/roles/himawaripy/templates/himawaripy.service.j2 index 5b5438e..ea9316e 100644 --- a/roles/himawaripy/templates/himawaripy.service.j2 +++ b/roles/himawaripy/templates/himawaripy.service.j2 @@ -1,8 +1,7 @@ # {{ ansible_managed }} [Unit] -Description=Update desktop background with satellite imagery for user %I +Description=Update desktop background with satellite imagery [Service] Type=oneshot ExecStart=/usr/local/bin/himawaripy {{ himawaripy.flags }} -User=%i diff --git a/roles/himawaripy/templates/himawaripy.timer.j2 b/roles/himawaripy/templates/himawaripy.timer.j2 index 033a878..1bd352f 100644 --- a/roles/himawaripy/templates/himawaripy.timer.j2 +++ b/roles/himawaripy/templates/himawaripy.timer.j2 @@ -5,7 +5,7 @@ Description=Himawaripy satellite imagery timer [Timer] OnBootSec={{ himawaripy.run_boot_delay }} OnUnitActiveSec={{ himawaripy.run_time }} -Unit=himawaripy@%i.service +Unit=himawaripy.service [Install] WantedBy=timers.target