Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(63) - Configure nostr-sync server with cronjobs #136

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
**Description/Goals**
_Why did you make this PR?_

**Summary of Changes**
_Example_
* I updated the metrics inventory to target the correct host.

**Tasks Before Merging**
_Do you need to remember to do anything BEFORE merging?_
9 changes: 9 additions & 0 deletions inventories/nostr_sync/inventory.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
nostr_sync:
vars:
ansible_user: admin
ansible_become: true
admin_username: admin
venv_path: "/home/{{ admin_username }}/sync_venv"
hosts:
sync.nos.social:
4 changes: 4 additions & 0 deletions playbooks/nostr_sync.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- name: Configure the nostr-sync server
hosts: nostr_sync
roles:
- nostr_sync
1 change: 1 addition & 0 deletions roles/nostr_sync/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Nostr Sync
73 changes: 73 additions & 0 deletions roles/nostr_sync/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
---
- name: Update cache
ansible.builtin.apt:
update_cache: true

- name: Ensure required packages are installed
ansible.builtin.package:
name:
- python3
- python3-pip
- python3-venv
- pkg-config
- util-linux # for flock
state: present

- name: Create venv
ansible.builtin.shell:
cmd: "python3 -m venv {{ venv_path }}"

- name: Make venv activate script executable
ansible.builtin.file:
path: "{{ venv_path }}/bin/activate"
mode: '0755'

- name: Upgrade pip
ansible.builtin.command:
cmd: "{{ venv_path }}/bin/python -m pip install --upgrade pip"
creates: "{{ venv_path }}/bin/pip"

- name: Clone our Repo
ansible.builtin.git:
repo: https://github.com/verse-pbc/nostr-sync-scripts
dest: /home/{{ admin_username }}/nostr-sync-scripts
version: 'main'
force: yes

- name: Clean up old .pyc files and __pycache__ directories
ansible.builtin.file:
path: "{{ item }}"
state: absent
with_fileglob:
- "/home/{{ admin_username }}/nostr-sync-scripts/**/*.pyc"
- "/home/{{ admin_username }}/nostr-sync-scripts/**/__pycache__"

- name: Create lock directory
ansible.builtin.file:
path: /var/lock/nostr-sync
state: directory
mode: '0755'
owner: "{{ admin_username }}"
group: "{{ admin_username }}"

- name: Install requirements in the virtual environment
ansible.builtin.command:
cmd: "{{ venv_path }}/bin/pip install -r /home/{{ admin_username }}/nostr-sync-scripts/requirements.txt"

- name: Add grow_fedi_nhex Sync to Crontab
ansible.builtin.cron:
name: "grow_fedi_nhex"
minute: 0
job: "cd /home/{{ admin_username }}/nostr-sync-scripts && flock -n /var/lock/nostr-sync/grow_fedi_nhex.lock {{ venv_path }}/bin/python grow_fedi_nhex.py 2>&1 | logger -t grow_fedi_nhex"

- name: Add fedi_sync to Crontab
ansible.builtin.cron:
name: "fedi_sync"
minute: 30
job: "cd /home/{{ admin_username }}/nostr-sync-scripts && flock -n /var/lock/nostr-sync/fedi_sync.lock {{ venv_path }}/bin/python fedi_sync.py 2>&1 | logger -t fedi_sync"

- name: Add news_sync to Crontab
ansible.builtin.cron:
name: "news_sync"
minute: 45
job: "cd /home/{{ admin_username }}/nostr-sync-scripts && flock -n /var/lock/nostr-sync/news_sync.lock {{ venv_path }}/bin/python news_sync.py 2>&1 | logger -t news_sync"