Add systemd units

This commit is contained in:
Antonio J. Delgado 2022-11-20 20:55:08 +02:00
parent 7a99bbd06a
commit 6c313627d4
11 changed files with 165 additions and 5 deletions

View file

@ -4,14 +4,17 @@
Thanks for this post https://sleeplessbeastie.eu/2022/05/02/how-to-take-advantage-of-docker-to-install-mastodon/ that helped a lot
# Description
This Ansible role would install a Mastodon instance either directly in the computer or a set of docker containers using docker-compose. You will need to have a reverse proxy pointing then to ports 3000 and 4000.
# Configuration
Check the default/main.yml for used variables and customize. If you don't have secrets already generated, leave them empty and the role will create them and you can pick them up from the application.env.production file created in the Mastodon folder.
# To-Do
- Create systemd units to start as a service
- Create scheduled jobs (systemd timer units) for ```tootctl media remove``` and ```tootctl preview_cards remove```
- Is federation working?
- Test bare metal installation (so far only tested with docker)
- There are 500 errors on my instance
- There are 500 errors on my instance when accessing "Administration"
- Include reverse proxy web server (nginx and apache)

View file

@ -20,6 +20,9 @@ mastodon_docker_image: "moritzheiber/mastodon-docker"
mastodon_docker_network: "mastodon_network"
docker_command: docker
docker_daemon_settings:
iptables: false
log-driver: journald
install_python_packages:
- package: "docker"
@ -65,6 +68,9 @@ redis_port: 6379
self_signed_cert_location: /etc/ssl/certs
self_signed_key_location: /etc/ssl/private
mastodon_composer_folder: /opt/mastodon
media_remove_schedule: 'Sat *-*-* 00:10:00'
preview_cards_remove_schedule: 'Sat *-*-* 00:20:00'
search_deploy_schedule: 'Sat *-*-* 03:00:00'
es_enabled: 'false'
es_host: localhost

View file

@ -1,4 +1,16 @@
---
- name: Configure docker daemon
copy:
dest: /etc/docker/daemon.json
content: "{{ docker_daemon_settings|to_json(indent=4, sort_keys=True) }}"
- name: Configure docker service and reload it
systemd:
name: docker
state: reloaded
enabled: true
masked: false
- name: Create Mastodon folder
file:
path: "{{ mastodon_composer_folder }}"
@ -225,6 +237,52 @@
var: owner_result
when: mastodon_initial_setup
- name: Deploy Mastodon systemd service unit
template:
src: templates/mastodon.service.j2
dest: /etc/systemd/system/mastodon.service
# ToDo: (adelgado) Systemd units
# ToDo: (adelgado) Scheduled jobs for tootctl media remove and tootctl preview_cards remove
- name: Deploy Mastodon Media Remove systemd service unit
template:
src: templates/mastodon-media-remove.service.j2
dest: /etc/systemd/system/mastodon-media-remove.service
- name: Deploy Mastodon Media Remove systemd timer unit
template:
src: templates/mastodon-media-remove.timer.j2
dest: /etc/systemd/system/mastodon-media-remove.timer
- name: Deploy Mastodon Preview Cards Remove systemd service unit
template:
src: templates/mastodon-preview_cards-remove.service.j2
dest: /etc/systemd/system/mastodon-preview_cards-remove.service
- name: Deploy Mastodon Preview Cards Remove systemd timer unit
template:
src: templates/mastodon-preview_cards-remove.timer.j2
dest: /etc/systemd/system/mastodon-preview_cards-remove.timer
- name: Deploy Mastodon Search Deploy systemd service unit
template:
src: templates/mastodon-search-deploy.service.j2
dest: /etc/systemd/system/mastodon-search-deploy.service
- name: Deploy Mastodon Search Deploy systemd timer unit
template:
src: templates/mastodon-search-deploy.timer.j2
dest: /etc/systemd/system/mastodon-search-deploy.timer
- name: Enable Mastodon Media Remove systemd timer unit
systemd:
name: mastodon-media-remove
state: enabled
daemon_reload: true
- name: Enable Mastodon Media Remove systemd timer unit
systemd:
name: "{{ item }}"
state: enabled
loop:
- mastodon-preview_cards-remove.timer
- mastodon-media-remove.timer
- mastodon-search-deploy.timer

View file

@ -1,4 +1,11 @@
---
- name: Increase mmap counts
ansible.posix.sysctl:
name: vm.max_map_count
value: '262144'
state: present
- name: Ensure bare metal installation
include_tasks: bare.yml
when: mastodon_bare_installation

View file

@ -0,0 +1,14 @@
[Unit]
Description=Mastodon - media remove service
Wants=mastodon-media-remove.timer
[Service]
Type=oneshot
StandardError=null
StandardOutput=null
WorkingDirectory={{ mastodon_composer_folder }}
ExecStart=/usr/bin/docker-compose -f {{ mastodon_composer_folder }}/docker-compose.yml run --rm shell tootctl media remove
[Install]
WantedBy=multi-user.target

View file

@ -0,0 +1,10 @@
[Unit]
Description=Schedule a media remove every week
[Timer]
Persistent=true
OnCalendar={{ media_remove_schedule }}
Unit=mastodon-media-remove.service
[Install]
WantedBy=timers.target

View file

@ -0,0 +1,14 @@
[Unit]
Description=Mastodon - preview cards remove service
Wants=mastodon-preview_cards-remove.timer
[Service]
Type=oneshot
StandardError=null
StandardOutput=null
WorkingDirectory={{ mastodon_composer_folder }}
ExecStart=/usr/bin/docker-compose -f {{ mastodon_composer_folder }}/docker-compose.yml run --rm shell tootctl preview_cards remove
[Install]
WantedBy=multi-user.target

View file

@ -0,0 +1,10 @@
[Unit]
Description=Schedule a preview cards remove every week
[Timer]
Persistent=true
OnCalendar={{ preview_cards_remove_schedule }}
Unit=mastodon-preview_cards-remove.service
[Install]
WantedBy=timers.target

View file

@ -0,0 +1,14 @@
[Unit]
Description=Mastodon - update Elasticsearch indices
Wants=mastodon-search-deploy.timer
[Service]
Type=oneshot
StandardError=null
StandardOutput=null
WorkingDirectory={{ mastodon_composer_folder }}
ExecStart=/usr/bin/docker-compose -f {{ mastodon_composer_folder }}/docker-compose.yml run --rm shell tootctl search deploy
[Install]
WantedBy=multi-user.target

View file

@ -0,0 +1,10 @@
[Unit]
Description=Schedule a preview cards remove every week
[Timer]
Persistent=true
OnCalendar={{ search_deploy_schedule }}
Unit=mastodon-search-deploy.service
[Install]
WantedBy=timers.target

View file

@ -0,0 +1,14 @@
[Unit]
Description=Mastodon service
After=docker.service
[Service]
Type=oneshot
RemainAfterExit=yes
WorkingDirectory={{ mastodon_composer_folder }}
ExecStart=/usr/bin/docker-compose -f {{ mastodon_composer_folder }}/docker-compose.yml up -d
ExecStop=/usr/bin/docker-compose -f {{ mastodon_composer_folder }}/docker-compose.yml down
[Install]
WantedBy=multi-user.target