From 1ffa4a326ca44b1d0f8eb4ebaddeab265ca8cda8 Mon Sep 17 00:00:00 2001 From: benkuly <12199167+benkuly@users.noreply.github.com> Date: Sat, 23 May 2020 13:14:24 +0200 Subject: [PATCH] matrix-sms-bridge: added docs, added seperate service for database, pr comments --- README.md | 4 +++ .../configuring-playbook-matrix-sms-bridge.md | 24 +++++++++++++ docs/configuring-playbook.md | 2 ++ group_vars/matrix_servers | 2 -- roles/matrix-sms-bridge/defaults/main.yml | 8 +++-- .../matrix-sms-bridge/tasks/setup_install.yml | 11 ++++-- .../tasks/setup_uninstall.yml | 22 ++++++++++-- .../matrix-sms-bridge-database.service.j2 | 36 +++++++++++++++++++ .../systemd/matrix-sms-bridge.service.j2 | 18 +--------- 9 files changed, 101 insertions(+), 26 deletions(-) create mode 100644 docs/configuring-playbook-matrix-sms-bridge.md create mode 100644 roles/matrix-sms-bridge/templates/systemd/matrix-sms-bridge-database.service.j2 diff --git a/README.md b/README.md index 6f7d25e0..a5ec78d3 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,8 @@ Using this playbook, you can get the following services configured on your serve - (optional) the [matrix-appservice-webhooks](https://github.com/turt2live/matrix-appservice-webhooks) bridge for slack compatible webhooks ([ConcourseCI](https://concourse-ci.org/), [Slack](https://slack.com/) etc. pp.) +- (optional) the [matrix-sms-bridge](https://github.com/benkuly/matrix-sms-bridge) for bridging your Matrix server to SMS + - (optional) [Email2Matrix](https://github.com/devture/email2matrix) for relaying email messages to Matrix rooms - (optional) [Dimension](https://github.com/turt2live/matrix-dimension), an open source integrations manager for matrix clients @@ -144,6 +146,8 @@ This playbook sets up your server using the following Docker images: - [turt2live/matrix-appservice-webhooks](https://hub.docker.com/r/turt2live/matrix-appservice-webhooks) - the [Appservice Webhooks](https://github.com/turt2live/matrix-appservice-webhooks) bridge (optional) +- [folivonet/matrix-sms-bridge](https://hub.docker.com/repository/docker/folivonet/matrix-sms-bridge) - the [matrix-sms-brdige](https://github.com/benkuly/matrix-sms-bridge) (optional) + - [sorunome/mx-puppet-skype](https://hub.docker.com/r/sorunome/mx-puppet-skype) - the [mx-puppet-skype](https://github.com/Sorunome/mx-puppet-skype) bridge to [Skype](https:/www.skype.com) (optional) - [sorunome/mx-puppet-slack](https://hub.docker.com/r/sorunome/mx-puppet-slack) - the [mx-puppet-slack](https://github.com/Sorunome/mx-puppet-slack) bridge to [Slack](https:/slack.com) (optional) diff --git a/docs/configuring-playbook-matrix-sms-bridge.md b/docs/configuring-playbook-matrix-sms-bridge.md new file mode 100644 index 00000000..ef2aeb08 --- /dev/null +++ b/docs/configuring-playbook-matrix-sms-bridge.md @@ -0,0 +1,24 @@ +# Setting up matrix-sms-bridge (optional) + +The playbook can install and configure +[matrix-sms-brdige](https://github.com/benkuly/matrix-sms-bridge) for you. + +See the project page to learn what it does and why it might be useful to you. + +To enable the bridge just use the following +playbook configuration: + + +```yaml +matrix_sms_bridge_enabled: true +matrix_sms_bridge_gammu_modem: "/path/to/modem" +# generate a secret passwort e.g. with pwgen -s 64 1 +matrix_sms_bridge_database_password: "" +# (optional) a room id to a default room +matrix_sms_bridge_default_room: "" +``` + + +## Usage + +Read the [user guide](https://github.com/benkuly/matrix-sms-bridge/blob/master/README.md#user-guide) to see how this bridge works. diff --git a/docs/configuring-playbook.md b/docs/configuring-playbook.md index 7e911095..90771cf3 100644 --- a/docs/configuring-playbook.md +++ b/docs/configuring-playbook.md @@ -102,3 +102,5 @@ When you're done with all the configuration you'd like to do, continue with [Ins - [Setting up MX Puppet Slack bridging](configuring-playbook-bridge-mx-puppet-slack.md) (optional) - [Setting up Email2Matrix](configuring-playbook-email2matrix.md) (optional) + +- [Setting up Matrix SMS bridging](configuring-playbook-matrix-sms-bridge.md) (optional) diff --git a/group_vars/matrix_servers b/group_vars/matrix_servers index 1fb1ea0f..8ff5ce96 100755 --- a/group_vars/matrix_servers +++ b/group_vars/matrix_servers @@ -324,8 +324,6 @@ matrix_sms_bridge_appservice_token: "{{ matrix_synapse_macaroon_secret_key | pas matrix_sms_bridge_homeserver_token: "{{ matrix_synapse_macaroon_secret_key | password_hash('sha512', 'sms.hs.token') | to_uuid }}" -matrix_sms_bridge_database_password: "{{ matrix_synapse_macaroon_secret_key | password_hash('sha512', 'sms.db.password') | to_uuid }}" - ###################################################################### # # /matrix-sms-bridge diff --git a/roles/matrix-sms-bridge/defaults/main.yml b/roles/matrix-sms-bridge/defaults/main.yml index d69724bd..57a7a373 100644 --- a/roles/matrix-sms-bridge/defaults/main.yml +++ b/roles/matrix-sms-bridge/defaults/main.yml @@ -31,11 +31,13 @@ matrix_sms_bridge_container_http_host_bind_port: '' # A list of extra arguments to pass to the container matrix_sms_bridge_container_extra_arguments: [] -# List of systemd services that matrix-appservice-discord.service depends on. -matrix_sms_bridge_systemd_required_services_list: ['docker.service'] +# List of systemd services that service depends on. +matrix_sms_bridge_systemd_required_services_list: ['docker.service','matrix-sms-bridge-database.service'] +matrix_sms_bridge_database_systemd_required_services_list: ['docker.service'] -# List of systemd services that matrix-appservice-discord.service wants +# List of systemd services that service wants matrix_sms_bridge_systemd_wanted_services_list: [] +matrix_sms_bridge_database_systemd_wanted_services_list: [] matrix_sms_bridge_appservice_url: 'http://matrix-sms-bridge:8080' matrix_sms_bridge_database_url: 'bolt://matrix-sms-bridge-database:7687' diff --git a/roles/matrix-sms-bridge/tasks/setup_install.yml b/roles/matrix-sms-bridge/tasks/setup_install.yml index 6a800892..1e86f2e6 100644 --- a/roles/matrix-sms-bridge/tasks/setup_install.yml +++ b/roles/matrix-sms-bridge/tasks/setup_install.yml @@ -66,7 +66,14 @@ mode: 0644 register: matrix_sms_bridge_systemd_service_result -- name: Ensure systemd reloaded after matrix-sms-bridge.service installation +- name: Ensure matrix-sms-bridge-database.service installed + template: + src: "{{ role_path }}/templates/systemd/matrix-sms-bridge-database.service.j2" + dest: "{{ matrix_systemd_path }}/matrix-sms-bridge-database.service" + mode: 0644 + register: matrix_sms_bridge_database_systemd_service_result + +- name: Ensure systemd reloaded after matrix-sms-bridge.service or matrix-sms-bridge-database.service installation service: daemon_reload: yes - when: "matrix_sms_bridge_systemd_service_result.changed" + when: matrix_sms_bridge_systemd_service_result.changed or matrix_sms_bridge_database_systemd_service_result.changed diff --git a/roles/matrix-sms-bridge/tasks/setup_uninstall.yml b/roles/matrix-sms-bridge/tasks/setup_uninstall.yml index 10912700..87436687 100644 --- a/roles/matrix-sms-bridge/tasks/setup_uninstall.yml +++ b/roles/matrix-sms-bridge/tasks/setup_uninstall.yml @@ -5,6 +5,11 @@ path: "{{ matrix_systemd_path }}/matrix-sms-bridge.service" register: matrix_sms_bridge_service_stat +- name: Check existence of matrix-sms-bridge-database service + stat: + path: "{{ matrix_systemd_path }}/matrix-sms-bridge-database.service" + register: matrix_sms_bridge_database_service_stat + - name: Ensure matrix-sms-bridge is stopped service: name: matrix-sms-bridge @@ -12,13 +17,26 @@ daemon_reload: yes when: "matrix_sms_bridge_service_stat.stat.exists" +- name: Ensure matrix-sms-bridge-database is stopped + service: + name: matrix-sms-bridge-database + state: stopped + daemon_reload: yes + when: "matrix_sms_bridge_database_service_stat.stat.exists" + - name: Ensure matrix-sms-bridge.service doesn't exist file: path: "{{ matrix_systemd_path }}/matrix-sms-bridge.service" state: absent when: "matrix_sms_bridge_service_stat.stat.exists" -- name: Ensure systemd reloaded after matrix-sms-bridge.service removal +- name: Ensure matrix-sms-bridge-database.service doesn't exist + file: + path: "{{ matrix_systemd_path }}/matrix-sms-bridge-database.service" + state: absent + when: "matrix_sms_bridge_database_service_stat.stat.exists" + +- name: Ensure systemd reloaded after matrix-sms-bridge.service or matrix-sms-bridge-database.service removal service: daemon_reload: yes - when: "matrix_sms_bridge_service_stat.stat.exists" + when: matrix_sms_bridge_service_stat.stat.exists or matrix_sms_bridge_database_service_stat.stat.exists diff --git a/roles/matrix-sms-bridge/templates/systemd/matrix-sms-bridge-database.service.j2 b/roles/matrix-sms-bridge/templates/systemd/matrix-sms-bridge-database.service.j2 new file mode 100644 index 00000000..e2cad164 --- /dev/null +++ b/roles/matrix-sms-bridge/templates/systemd/matrix-sms-bridge-database.service.j2 @@ -0,0 +1,36 @@ +#jinja2: lstrip_blocks: "True" +[Unit] +Description=matrix-sms-bridge-database server +{% for service in matrix_sms_bridge_database_systemd_required_services_list %} +Requires={{ service }} +After={{ service }} +{% endfor %} +{% for service in matrix_sms_bridge_database_systemd_wanted_services_list %} +Wants={{ service }} +{% endfor %} + +[Service] +Type=simple +ExecStartPre=-/usr/bin/docker kill matrix-sms-bridge-database +ExecStartPre=-/usr/bin/docker rm matrix-sms-bridge-database + +# Intentional delay, so that the homeserver (we likely depend on) can manage to start. +ExecStartPre=/bin/sleep 5 + +ExecStart=/usr/bin/docker run --rm --name matrix-sms-bridge-database \ + --log-driver=none \ + --user={{ matrix_user_uid }}:{{ matrix_user_gid }} \ + --cap-drop=ALL \ + --network={{ matrix_docker_network }} \ + -v {{ matrix_sms_bridge_database_path }}:/data:z \ + -e NEO4J_AUTH={{ matrix_sms_bridge_database_username }}/{{ matrix_sms_bridge_database_password }} \ + {{ matrix_sms_bridge_database_docker_image }} + +ExecStop=-/usr/bin/docker kill matrix-sms-bridge-database +ExecStop=-/usr/bin/docker rm matrix-sms-bridge-database +Restart=always +RestartSec=30 +SyslogIdentifier=matrix-sms-bridge + + [Install] +WantedBy=multi-user.target diff --git a/roles/matrix-sms-bridge/templates/systemd/matrix-sms-bridge.service.j2 b/roles/matrix-sms-bridge/templates/systemd/matrix-sms-bridge.service.j2 index a97db783..86ac264d 100644 --- a/roles/matrix-sms-bridge/templates/systemd/matrix-sms-bridge.service.j2 +++ b/roles/matrix-sms-bridge/templates/systemd/matrix-sms-bridge.service.j2 @@ -13,20 +13,6 @@ Wants={{ service }} Type=simple ExecStartPre=-/usr/bin/docker kill matrix-sms-bridge ExecStartPre=-/usr/bin/docker rm matrix-sms-bridge -ExecStartPre=-/usr/bin/docker kill matrix-sms-bridge-database -ExecStartPre=-/usr/bin/docker rm matrix-sms-bridge-database - -ExecStartPre=/usr/bin/docker run --rm --name matrix-sms-bridge-database \ - --log-driver=none \ - --user={{ matrix_user_uid }}:{{ matrix_user_gid }} \ - --cap-drop=ALL \ - --network={{ matrix_docker_network }} \ - {% if matrix_sms_bridge_container_http_host_bind_port %} - -p {{ matrix_sms_bridge_container_http_host_bind_port }}:7687 \ - {% endif %} - -v {{ matrix_sms_bridge_database_path }}:/data:z \ - -e NEO4J_AUTH={{ matrix_sms_bridge_database_username }}/{{ matrix_sms_bridge_database_password }} - {{ matrix_sms_bridge_database_docker_image }} # Intentional delay, so that the homeserver (we likely depend on) can manage to start. ExecStartPre=/bin/sleep 5 @@ -41,7 +27,7 @@ ExecStart=/usr/bin/docker run --rm --name matrix-sms-bridge \ {% endif %} -v {{ matrix_sms_bridge_config_path }}:/config:z \ -v {{ matrix_sms_bridge_data_path }}:/data:z \ - --device {{ matrix_sms_bridge_gammu_modem }}:/dev/ttyModem + --device {{ matrix_sms_bridge_gammu_modem }}:/dev/ttyModem \ {% for arg in matrix_sms_bridge_container_extra_arguments %} {{ arg }} \ {% endfor %} @@ -49,8 +35,6 @@ ExecStart=/usr/bin/docker run --rm --name matrix-sms-bridge \ ExecStop=-/usr/bin/docker kill matrix-sms-bridge ExecStop=-/usr/bin/docker rm matrix-sms-bridge -ExecStop=-/usr/bin/docker kill matrix-sms-database -ExecStop=-/usr/bin/docker rm matrix-sms-database Restart=always RestartSec=30 SyslogIdentifier=matrix-sms-bridge