Added nostr relayer role.
authorLuke Hoersten <luke@hoersten.org>
Thu, 20 Jul 2023 18:07:44 -0500
changeset 214 3069b7d001f7
parent 213 245f2e093398
child 215 dd52907adff9
Added nostr relayer role.
relayer/defaults/main.yaml
relayer/files/relayer.service
relayer/handlers/main.yaml
relayer/tasks/main.yaml
relayer/templates/relayer.env.j2
relayer/templates/setup_db.psql.j2
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/relayer/defaults/main.yaml	Thu Jul 20 18:07:44 2023 -0500
@@ -0,0 +1,9 @@
+---
+
+# https://github.com/fiatjaf/relayer/releases
+relayer_user: "relayer"
+relayer_pubkey: ""
+relayer_port: "7447"
+relayer_db: "relayer"
+relayer_db_user: "relayer"
+relayer_db_pass: "relayer"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/relayer/files/relayer.service	Thu Jul 20 18:07:44 2023 -0500
@@ -0,0 +1,14 @@
+[Unit]
+Description=relayer nostr relay
+Requires=network.target postgresql.service
+Before=nginx.service
+
+[Service]
+User=relayer
+EnvironmentFile=/etc/relayer/relayer.env
+
+ExecStart=/usr/local/bin/relayer
+Restart=on-failure
+
+[Install]
+WantedBy=multi-user.target
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/relayer/handlers/main.yaml	Thu Jul 20 18:07:44 2023 -0500
@@ -0,0 +1,5 @@
+---
+
+- name: restart relayer service
+  become: yes
+  systemd: name="relayer.service" state="restarted" daemon_reload="yes"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/relayer/tasks/main.yaml	Thu Jul 20 18:07:44 2023 -0500
@@ -0,0 +1,60 @@
+---
+
+- name: add relayer user
+  become: yes
+  user: name="{{relayer_user}}" shell="/bin/false" create_home="false" system="yes"
+
+- name: install relayer systemd service
+  become: yes
+  copy:
+    src: "relayer.service"
+    dest: "/lib/systemd/system/relayer.service"
+  notify: restart relayer service
+
+- name: install relayer bin
+  become: yes
+  copy:
+    src: "whitelisted"
+    dest: "/usr/local/bin/relayer"
+    owner: "root"
+    group: "root"
+    mode: "0755"
+  notify: restart relayer service
+
+- name: create relayer dirs
+  become: yes
+  file:
+    path: "/etc/relayer"
+    owner: "root"
+    group: "root"
+    mode: "0755"
+    state: "directory"
+
+- name: install relayer config
+  become: yes
+  template:
+    src: "relayer.env.j2"
+    dest: "/etc/relayer/relayer.env"
+    owner: "root"
+    group: "root"
+    mode: "0600"
+  notify: restart relayer service
+
+- name: copy db schema file
+  become: yes
+  template:
+    src: "setup_db.psql.j2"
+    dest: "/tmp/setup_db_relayer.psql"
+    owner: "postgres"
+    group: "postgres"
+    mode: "0600"
+
+- name: install db schema psql
+  become: yes
+  become_user: "postgres"
+  command: "psql -f /tmp/setup_db_relayer.psql"
+  changed_when: false
+
+- name: ensure service is started
+  become: yes
+  systemd: name="relayer.service" enabled="yes" state="started"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/relayer/templates/relayer.env.j2	Thu Jul 20 18:07:44 2023 -0500
@@ -0,0 +1,4 @@
+POSTGRESQL_DATABASE=postgres://{{relayer_db_user}}:{{relayer_db_pass}}@localhost:5432/{{relayer_db}}
+WHITELIST={{relayer_pubkey}}
+HOST=127.0.0.1
+PORT={{relayer_port}}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/relayer/templates/setup_db.psql.j2	Thu Jul 20 18:07:44 2023 -0500
@@ -0,0 +1,2 @@
+CREATE USER {{relayer_db_user}} WITH ENCRYPTED PASSWORD '{{relayer_db_pass}}';
+CREATE DATABASE {{relayer_db}} WITH OWNER {{relayer_db_user}};