From abe03436d41de228cb4c2e3b2b5c7a1dd9fde169 Mon Sep 17 00:00:00 2001
From: t3chn0m4g3 <t3chn0m4g3@gmail.com>
Date: Tue, 19 Mar 2024 13:56:35 +0100
Subject: [PATCH] add tpot.service

---
 installer/install/tpot.service | 17 +++++++++++++++
 installer/install/tpot.yml     | 39 ++++++++++++++++++++++++++++++++++
 2 files changed, 56 insertions(+)
 create mode 100644 installer/install/tpot.service

diff --git a/installer/install/tpot.service b/installer/install/tpot.service
new file mode 100644
index 00000000..08968d76
--- /dev/null
+++ b/installer/install/tpot.service
@@ -0,0 +1,17 @@
+[Unit]
+Description=T-Pot
+Wants=docker.service network-online.target
+After=docker.service network-online.target
+
+[Service]
+Restart=always
+RestartSec=5
+Type=simple
+TimeoutSec=infinity
+ExecStartPre=-/usr/bin/docker compose -f /home/{{ ansible_user_id }}/tpotce/docker-compose.yml down -v
+ExecStart=/usr/bin/docker compose -f /home/{{ ansible_user_id }}/tpotce/docker-compose.yml up
+ExecStop=/usr/bin/docker compose -f /home/{{ ansible_user_id }}/tpotce/docker-compose.yml down -v
+RemainAfterExit=yes
+
+[Install]
+WantedBy=multi-user.target
diff --git a/installer/install/tpot.yml b/installer/install/tpot.yml
index e9b2523a..0f66d1b6 100644
--- a/installer/install/tpot.yml
+++ b/installer/install/tpot.yml
@@ -672,3 +672,42 @@
         msg: "Detected user: '{{ ansible_user_id }}'"
       when: ansible_distribution in ["AlmaLinux", "Debian", "Fedora", "openSUSE Tumbleweed", "Raspbian", "Rocky", "Ubuntu"]
       failed_when: ansible_user_id == "root"
+
+###########################
+# T-Pot - Install service #
+###########################
+
+- name: T-Pot - Install service
+  hosts: all
+  gather_facts: true
+  become: false
+  tags:
+    - "AlmaLinux"
+    - "Debian"
+    - "Fedora"
+    - "openSUSE Tumbleweed"
+    - "Raspbian"
+    - "Rocky"
+    - "Ubuntu"
+
+  tasks:
+    - name: Install systemd service (All)
+      become: true
+      ansible.builtin.template:
+        src: '/home/{{ ansible_user_id }}/tpotce/installer/install/tpot.service'
+        dest: '/etc/systemd/system/tpot.service'
+        owner: root
+        group: root
+        mode: '0755'
+      notify: Reload systemd and enable service
+      when: ansible_distribution in ["AlmaLinux", "Debian", "Fedora", "openSUSE Tumbleweed", "Raspbian", "Rocky", "Ubuntu"]
+
+  handlers:
+    - name: Reload systemd and enable service
+      become: true
+      ansible.builtin.systemd:
+        name: tpot.service
+        daemon_reload: yes
+        state: stopped
+        enabled: yes
+      when: ansible_distribution in ["AlmaLinux", "Debian", "Fedora", "openSUSE Tumbleweed", "Raspbian", "Rocky", "Ubuntu"]