From 715480754f2cc4f993547be74efba99debba913d Mon Sep 17 00:00:00 2001 From: Pig Monkey Date: Tue, 3 Apr 2018 19:09:25 -0700 Subject: [PATCH] run git-annex as a user service When this role was created, Ansible did not support sytemd user units, so we setup git-annex as a system service running as the user. The only practical difference in moving to a user service is that the user can control the service without sudo, but we might as well. Existing users should first stop, disable, and remove the old system service: $ sudo systemctl stop git-annex@$USER.service $ sudo systemctl disable git-annex@$USER.service $ sudo rm /etc/systemd/system/git-annex@.* If the system service is present in the trusted unit file, remove it. --- roles/git-annex/files/git-annex.service | 3 +-- roles/git-annex/tasks/main.yml | 12 ++++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/roles/git-annex/files/git-annex.service b/roles/git-annex/files/git-annex.service index f24c842..aa6d0c4 100644 --- a/roles/git-annex/files/git-annex.service +++ b/roles/git-annex/files/git-annex.service @@ -1,10 +1,9 @@ [Unit] -Description=Git Annex Assistant Service for %I +Description=Git Annex Assistant Service [Service] Type=simple ExecStart=/usr/bin/git-annex assistant --foreground --autostart -User=%i StandardOutput=syslog StandardError=syslog diff --git a/roles/git-annex/tasks/main.yml b/roles/git-annex/tasks/main.yml index 87a767c..edc3735 100644 --- a/roles/git-annex/tasks/main.yml +++ b/roles/git-annex/tasks/main.yml @@ -8,7 +8,7 @@ - aur - name: Push git-annex assistant service file - copy: src=git-annex.service dest=/etc/systemd/system/git-annex@.service + copy: src=git-annex.service dest=/etc/systemd/user/git-annex.service notify: - reload systemd config - restart git-annex @@ -18,19 +18,23 @@ register: autostart - name: Enable and start git-annex assistant service - service: name="git-annex@{{ user.name }}.service" enabled=yes state=started + systemd: name=git-annex.service user=yes enabled=yes state=started + become: yes + become_user: "{{ user.name }}" + environment: + XDG_RUNTIME_DIR: "/run/user/{{ user.uid }}" when: autostart.stat is defined and autostart.stat.size > 0 - name: Add git-annex to trusted unit list lineinfile: dest=/usr/local/etc/trusted_units state=present - line="git-annex@{{ user.name }}.service,allow_offline" + line="git-annex.service,user:{{ user.name }},allow_offline" when: gitannex.stop_on_untrusted is defined and gitannex.stop_on_untrusted == True - name: Remove git-annex from trusted unit list lineinfile: dest=/usr/local/etc/trusted_units state=absent - line="git-annex@{{ user.name }}.service,allow_offline" + line="git-annex.service,user:{{ user.name }},allow_offline" when: gitannex.stop_on_untrusted is not defined or gitannex.stop_on_untrusted != True - name: Increase the amount of inotify watchers