From 676f9ce7d7e8eac3a76b269eee4dd3b68bd75bf1 Mon Sep 17 00:00:00 2001 From: Pig Monkey Date: Sun, 9 Apr 2017 12:34:59 -0700 Subject: [PATCH] add himawaripy --- README.md | 27 ++++++++++++ group_vars/all | 6 +++ playbook.yml | 1 + roles/himawaripy/handlers/main.yml | 4 ++ roles/himawaripy/meta/main.yml | 3 ++ roles/himawaripy/tasks/main.yml | 41 +++++++++++++++++++ .../templates/himawaripy.service.j2 | 8 ++++ .../himawaripy/templates/himawaripy.timer.j2 | 11 +++++ 8 files changed, 101 insertions(+) create mode 100644 roles/himawaripy/handlers/main.yml create mode 100644 roles/himawaripy/meta/main.yml create mode 100644 roles/himawaripy/tasks/main.yml create mode 100644 roles/himawaripy/templates/himawaripy.service.j2 create mode 100644 roles/himawaripy/templates/himawaripy.timer.j2 diff --git a/README.md b/README.md index c1abe7f..e0d9bcd 100644 --- a/README.md +++ b/README.md @@ -297,6 +297,31 @@ PostgreSQL service is not added to `/usr/local/etc/trusted_units`. Additional configuration options are set which improve performance but make the database service inappropriate for production use. +## Himawaripy + +[Himawaripy][28] is provided to fetch near-realtime photos of Earth from the +Japanese [Himawari 8][29] weather satellite and set them as the user's desktop +background via feh. This should provide early warning of the presence of any +Vogon constructor fleets appearing over the Eastern Hemisphere. + +A systemd service unit and timer is installed, but not enabled or started by +default. Instead, the service is added to `/usr/local/etc/trusted_units`, +causing the NetworkManager trusted unit dispatcher to activate the service +whenever a connection is established to a trusted network. The service is +stopped whenever the network goes down or a connection is established to an +untrusted network. + +To have the service activated at boot, change the `himawaripy.run_on` variable +from `trusted` to `all`. + +If the `himawaripy.run_on` variable is set to anything other than `trusted` or +`all`, the service will never be activated. + +By default the timer is scheduled to fetch a new image at 15 minute intervals. +This can be changed by modifying the `himawaripy.run_time` variable. + +By completely removing the `himawaripy` variable, no related tasks will be run. + [1]: http://www.ansible.com [2]: https://www.archlinux.org @@ -325,3 +350,5 @@ database service inappropriate for production use. [25]: https://weechat.org/ [26]: https://git-annex.branchable.com/ [27]: http://www.postgresql.org/ +[28]: https://github.com/boramalper/himawaripy +[29]: https://en.wikipedia.org/wiki/Himawari_8 diff --git a/group_vars/all b/group_vars/all index 8053eaf..ad4e25b 100644 --- a/group_vars/all +++ b/group_vars/all @@ -184,3 +184,9 @@ udisks: hostsctl: url: https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts + +himawaripy: + run_time: 15min + run_boot_delay: 2min + run_on: trusted + flags: --auto-offset --level 4 diff --git a/playbook.yml b/playbook.yml index b35c679..f3e1a15 100644 --- a/playbook.yml +++ b/playbook.yml @@ -67,6 +67,7 @@ - { role: bluetooth, tags: ['bluetooth'], when: "bluetooth is defined" } - { role: wttr, tags: ['wttr'] } - { role: hostsctl, tags: ['hostsctl'], when: "hostsctl is defined" } + - { role: himawaripy, tags: ['himawaripy'], when: "himawaripy is defined" } vars_prompt: - name: user_password prompt: "Enter desired user password" diff --git a/roles/himawaripy/handlers/main.yml b/roles/himawaripy/handlers/main.yml new file mode 100644 index 0000000..d5e3c07 --- /dev/null +++ b/roles/himawaripy/handlers/main.yml @@ -0,0 +1,4 @@ +--- +- name: restart himawaripy + service: name="himawaripy@{{ user.name }}.timer" state=restarted + when: himawaripy.run_on == "all" diff --git a/roles/himawaripy/meta/main.yml b/roles/himawaripy/meta/main.yml new file mode 100644 index 0000000..a0729fb --- /dev/null +++ b/roles/himawaripy/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - { role: systemd } diff --git a/roles/himawaripy/tasks/main.yml b/roles/himawaripy/tasks/main.yml new file mode 100644 index 0000000..b46f348 --- /dev/null +++ b/roles/himawaripy/tasks/main.yml @@ -0,0 +1,41 @@ +--- +- name: Install himawaripy into virtual environment + pip: name=git+https://github.com/boramalper/himawaripy#egg=himawaripy + virtualenv=/usr/local/env/himawaripy + virtualenv_command=virtualenv3 + +- name: Link himawaripy to bin + file: src=/usr/local/env/himawaripy/bin/himawaripy + dest=/usr/local/bin/himawaripy + state=link + +- name: Push himawaripy service file + template: src=himawaripy.service.j2 dest=/etc/systemd/system/himawaripy@.service + notify: + - reload systemd config + +- name: Push himawaripy timer file + template: src=himawaripy.timer.j2 dest=/etc/systemd/system/himawaripy@.timer + notify: + - reload systemd config + - restart himawaripy + +- name: Enable and start himawaripy timer + service: name="himawaripy@{{ user.name }}.timer" enabled=yes state=started + 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" + when: himawaripy.run_on == "all" + +- name: Disable himawaripy timer + service: name="himawaripy@{{ user.name }}.timer" enabled=no + 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" + when: himawaripy.run_on == "trusted" diff --git a/roles/himawaripy/templates/himawaripy.service.j2 b/roles/himawaripy/templates/himawaripy.service.j2 new file mode 100644 index 0000000..5b5438e --- /dev/null +++ b/roles/himawaripy/templates/himawaripy.service.j2 @@ -0,0 +1,8 @@ +# {{ ansible_managed }} +[Unit] +Description=Update desktop background with satellite imagery for user %I + +[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 new file mode 100644 index 0000000..033a878 --- /dev/null +++ b/roles/himawaripy/templates/himawaripy.timer.j2 @@ -0,0 +1,11 @@ +# {{ ansible_managed }} +[Unit] +Description=Himawaripy satellite imagery timer + +[Timer] +OnBootSec={{ himawaripy.run_boot_delay }} +OnUnitActiveSec={{ himawaripy.run_time }} +Unit=himawaripy@%i.service + +[Install] +WantedBy=timers.target