From a9d7564b40b0b0db0cfee98c10f27e9d6d9e8836 Mon Sep 17 00:00:00 2001 From: Martin Janser Date: Tue, 1 Nov 2016 21:38:11 +0100 Subject: [PATCH] Add support for systemd timers and add /.well-known access on http --- Vagrantfile | 4 ++++ tasks/main.yml | 12 +++++------- tasks/timer/cron.yml | 8 ++++++++ tasks/timer/systemd.yml | 16 ++++++++++++++++ templates/nginx_vhost.conf.j2 | 10 +++++++++- templates/systemd.service.j2 | 6 ++++++ templates/systemd.timer.j2 | 5 +++++ 7 files changed, 53 insertions(+), 8 deletions(-) create mode 100644 tasks/timer/cron.yml create mode 100644 tasks/timer/systemd.yml create mode 100644 templates/systemd.service.j2 create mode 100644 templates/systemd.timer.j2 diff --git a/Vagrantfile b/Vagrantfile index 532e047..20ce3a7 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -36,6 +36,10 @@ echo "specified vendor: $VENDOR" curl -s --insecure -H "Host: example.com" https://localhost/login | grep -qi "$VENDOR" && echo "curl request for vendor was successful" || { echo "curl request for vendor failed" && exit 1; } curl -s --insecure -H "Host: example.com" https://localhost/login | grep -qi "username" && echo "curl request for login was successful" || { echo "curl request for login failed" && exit 1; } +mkdir /var/www/$VENDOR/.well-known +echo foo > /var/www/$VENDOR/.well-known/foo.txt +curl -s --max-redirs 0 -H "Host: example.com" http://localhost/.well-known/foo.txt | grep -q "foo" && echo "curl request for well-known was successful" || { echo "curl request for well-known failed" && exit 1; } + cd /vagrant/ ansible-playbook playbook.yml --limit $(hostname) --inventory-file /tmp/vagrant-ansible/inventory/vagrant_ansible_local_inventory 2>&1 | tee /tmp/ansible.log diff --git a/tasks/main.yml b/tasks/main.yml index 241f038..b21f23e 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -89,10 +89,8 @@ - include: install.yml - include: apps.yml -- name: ensure cron job is installed - cron: - name: "{{ owncloud_vendor }} cron" - cron_file: "{{ owncloud_vendor }}" - user: apache - minute: "*/15" - job: "php -f {{ owncloud_destination }}/cron.php" +- include: timer/cron.yml + when: ansible_service_mgr != 'systemd' + +- include: timer/systemd.yml + when: ansible_service_mgr == 'systemd' diff --git a/tasks/timer/cron.yml b/tasks/timer/cron.yml new file mode 100644 index 0000000..ebac891 --- /dev/null +++ b/tasks/timer/cron.yml @@ -0,0 +1,8 @@ +--- +- name: ensure cron job is installed + cron: + name: "{{ owncloud_vendor }} cron" + cron_file: "{{ owncloud_vendor }}" + user: apache + minute: "*/15" + job: "php -f {{ owncloud_destination }}/cron.php" \ No newline at end of file diff --git a/tasks/timer/systemd.yml b/tasks/timer/systemd.yml new file mode 100644 index 0000000..72d7ea1 --- /dev/null +++ b/tasks/timer/systemd.yml @@ -0,0 +1,16 @@ +--- +- name: ensure systemd service is installed + template: + src: systemd.service.j2 + dest: "/etc/systemd/system/{{ owncloud_vendor }}.service" + +- name: ensure systemd timer is installed + template: + src: systemd.timer.j2 + dest: "/etc/systemd/system/{{ owncloud_vendor }}.timer" + +- name: ensure systemd timer is enabled + service: + name: "{{ owncloud_vendor }}.timer" + state: started + enabled: yes diff --git a/templates/nginx_vhost.conf.j2 b/templates/nginx_vhost.conf.j2 index 77325d8..8a267a4 100644 --- a/templates/nginx_vhost.conf.j2 +++ b/templates/nginx_vhost.conf.j2 @@ -1,7 +1,15 @@ server { listen 80; server_name {{ owncloud_server_name }}; - return 301 https://$server_name$request_uri; + root {{ owncloud_destination }}/; + + location ^~ /.well-known/ { + allow all; + } + + location / { + return 301 https://$server_name$request_uri; + } } server { diff --git a/templates/systemd.service.j2 b/templates/systemd.service.j2 new file mode 100644 index 0000000..7b5b139 --- /dev/null +++ b/templates/systemd.service.j2 @@ -0,0 +1,6 @@ +[Unit] +Description=Perform {{ owncloud_vendor }} tasks + +[Service] +Type=oneshot +ExecStart=/usr/bin/php -f {{ owncloud_destination }}/cron.php diff --git a/templates/systemd.timer.j2 b/templates/systemd.timer.j2 new file mode 100644 index 0000000..14ee698 --- /dev/null +++ b/templates/systemd.timer.j2 @@ -0,0 +1,5 @@ +[Unit] +Description=Perform {{ owncloud_vendor }} tasks + +[Timer] +OnCalendar=*:0/15