From da20f1b0796dafe5476e02cc6e4165b418e2017a Mon Sep 17 00:00:00 2001 From: Leonard Ehrenfried Date: Mon, 6 Jan 2025 11:08:25 +0100 Subject: [PATCH] Add clean up role --- digitransit.yml | 2 +- group_vars/all.yml | 3 - roles/clean_up/handlers/main.yml | 3 + roles/clean_up/tasks/main.yml | 27 +++++++++ .../defaults/main.yml | 4 -- .../handlers/main.yml | 5 -- roles/delay-prediction-service/meta/main.yml | 4 -- roles/delay-prediction-service/tasks/main.yml | 60 ------------------- .../templates/delay-postgis.service | 25 -------- .../templates/delay-prediction-service | 29 --------- .../templates/delay-prediction.service | 16 ----- roles/mqtt/handlers/main.yml | 6 -- roles/mqtt/meta/main.yml | 3 - roles/mqtt/tasks/main.yml | 40 ------------- roles/mqtt/templates/mosquitto.acl | 4 -- roles/mqtt/templates/mosquitto.conf | 23 ------- roles/mqtt/templates/mosquitto.passwd | 1 - roles/mqtt/templates/mosquitto.service | 27 --------- roles/thingsboard-to-mqtt/handlers/main.yml | 5 -- roles/thingsboard-to-mqtt/meta/main.yml | 4 -- roles/thingsboard-to-mqtt/tasks/main.yml | 22 ------- .../templates/thingsboard-to-mqtt.service | 32 ---------- 22 files changed, 31 insertions(+), 314 deletions(-) create mode 100644 roles/clean_up/handlers/main.yml create mode 100644 roles/clean_up/tasks/main.yml delete mode 100644 roles/delay-prediction-service/defaults/main.yml delete mode 100644 roles/delay-prediction-service/handlers/main.yml delete mode 100644 roles/delay-prediction-service/meta/main.yml delete mode 100644 roles/delay-prediction-service/tasks/main.yml delete mode 100644 roles/delay-prediction-service/templates/delay-postgis.service delete mode 100644 roles/delay-prediction-service/templates/delay-prediction-service delete mode 100644 roles/delay-prediction-service/templates/delay-prediction.service delete mode 100644 roles/mqtt/handlers/main.yml delete mode 100644 roles/mqtt/meta/main.yml delete mode 100644 roles/mqtt/tasks/main.yml delete mode 100644 roles/mqtt/templates/mosquitto.acl delete mode 100644 roles/mqtt/templates/mosquitto.conf delete mode 100644 roles/mqtt/templates/mosquitto.passwd delete mode 100644 roles/mqtt/templates/mosquitto.service delete mode 100644 roles/thingsboard-to-mqtt/handlers/main.yml delete mode 100644 roles/thingsboard-to-mqtt/meta/main.yml delete mode 100644 roles/thingsboard-to-mqtt/tasks/main.yml delete mode 100644 roles/thingsboard-to-mqtt/templates/thingsboard-to-mqtt.service diff --git a/digitransit.yml b/digitransit.yml index 66a47d5b..770dfa41 100644 --- a/digitransit.yml +++ b/digitransit.yml @@ -5,7 +5,7 @@ become: yes roles: - base + - clean_up - digitransit - thingsboard-enhancer - - thingsboard-to-mqtt - matomo diff --git a/group_vars/all.yml b/group_vars/all.yml index e8b8fa32..8f4456d2 100644 --- a/group_vars/all.yml +++ b/group_vars/all.yml @@ -16,9 +16,6 @@ firewall_allowed_tcp_ports: - "22" - "80" - "443" - - "1883" # mqtt - - "1884" # mqtt-over-websockets - - "8883" # mqtts # firewall firewall_state: started diff --git a/roles/clean_up/handlers/main.yml b/roles/clean_up/handlers/main.yml new file mode 100644 index 00000000..153afb4d --- /dev/null +++ b/roles/clean_up/handlers/main.yml @@ -0,0 +1,3 @@ +--- +- name: Restart systemd-journald + service: name=systemd-journald state=restarted diff --git a/roles/clean_up/tasks/main.yml b/roles/clean_up/tasks/main.yml new file mode 100644 index 00000000..dfe65bf4 --- /dev/null +++ b/roles/clean_up/tasks/main.yml @@ -0,0 +1,27 @@ +--- +- name: Stop unused services + ansible.builtin.systemd: + name: "{{ item }}" + state: stopped + daemon_reload: true + with_items: + - mosquitto + - thingsboard-to-mqtt + ignore_errors: true + +- name: Remove systemd files + ansible.builtin.file: + dest: /etc/systemd/system/{{ item }} + state: absent + with_items: + - mosquitto.service + - thingsboard-to-mqtt.service + +- name: Remove folders + ansible.builtin.file: + path: "{{ item }}" + state: absent + with_items: + - /etc/mosquitto/ + - /var/graph-builder/ + - /var/delay-prediction/ diff --git a/roles/delay-prediction-service/defaults/main.yml b/roles/delay-prediction-service/defaults/main.yml deleted file mode 100644 index d4be5a44..00000000 --- a/roles/delay-prediction-service/defaults/main.yml +++ /dev/null @@ -1,4 +0,0 @@ ---- -delay_postgres_user: delay -delay_postgres_db: delay -mqtt_uri: mqtts://publisher:{{ mqtt_publisher_password }}@{{ api_hostname }}:8883 diff --git a/roles/delay-prediction-service/handlers/main.yml b/roles/delay-prediction-service/handlers/main.yml deleted file mode 100644 index cf32016a..00000000 --- a/roles/delay-prediction-service/handlers/main.yml +++ /dev/null @@ -1,5 +0,0 @@ ---- -- name: Restart delay-prediction-service - service: - name: delay-prediction - state: restarted diff --git a/roles/delay-prediction-service/meta/main.yml b/roles/delay-prediction-service/meta/main.yml deleted file mode 100644 index a9fe0ed5..00000000 --- a/roles/delay-prediction-service/meta/main.yml +++ /dev/null @@ -1,4 +0,0 @@ ---- -dependencies: - - role: geerlingguy.docker - - role: mqtt diff --git a/roles/delay-prediction-service/tasks/main.yml b/roles/delay-prediction-service/tasks/main.yml deleted file mode 100644 index 49d23c3d..00000000 --- a/roles/delay-prediction-service/tasks/main.yml +++ /dev/null @@ -1,60 +0,0 @@ ---- -- name: Create folder - file: - path: "{{ item }}" - state: directory - owner: root - group: root - mode: 0775 - with_items: - - /var/delay-prediction - -- name: Install script file - template: - src: "{{ item }}" - dest: /var/delay-prediction/ - mode: "+x" - with_items: - - delay-prediction-service - notify: Restart delay-prediction-service - -- name: Install base packages - package: - name: - - python3-docker - state: present - -- name: Create delay network - docker_network: - name: delay - -- name: Install systemd files - template: - src: '{{ item }}' - dest: /etc/systemd/system/ - with_items: - - delay-postgis.service - - delay-prediction.service - notify: Restart delay-prediction-service - -- name: Start service - systemd: - name: "{{ item }}" - state: started - enabled: yes - daemon_reload: yes - with_items: - - delay-postgis.service - - delay-prediction.service - when: enable_prediction_service - -- name: Stop service - systemd: - name: "{{ item }}" - state: stopped - enabled: yes - daemon_reload: yes - with_items: - - delay-postgis.service - - delay-prediction.service - when: enable_prediction_service == false diff --git a/roles/delay-prediction-service/templates/delay-postgis.service b/roles/delay-prediction-service/templates/delay-postgis.service deleted file mode 100644 index aba3d4a8..00000000 --- a/roles/delay-prediction-service/templates/delay-postgis.service +++ /dev/null @@ -1,25 +0,0 @@ -[Unit] -Description=Postgis instance for delay-prediction-service -After=network-online.target -Wants=network-online.target - -[Service] -Restart=always -RestartSec=5 - -Environment=DOCKER_IMAGE=postgis/postgis:13-3.1 -Environment=CONTAINER_NAME=delay-postgis - -ExecStart=docker run --rm \ - --network delay \ - --name ${CONTAINER_NAME} \ - --cpu-shares=256 \ - -e POSTGRES_DB={{ delay_postgres_db }} \ - -e POSTGRES_USER={{ delay_postgres_user }} \ - -e POSTGRES_PASSWORD={{ delay_postgres_password }} \ - -v delay-postgres-data:/var/lib/postgresql/data \ - ${DOCKER_IMAGE} - - -[Install] -WantedBy=multi-user.target diff --git a/roles/delay-prediction-service/templates/delay-prediction-service b/roles/delay-prediction-service/templates/delay-prediction-service deleted file mode 100644 index f593d5c2..00000000 --- a/roles/delay-prediction-service/templates/delay-prediction-service +++ /dev/null @@ -1,29 +0,0 @@ -#! /bin/bash -e - -DOCKER_IMAGE=stadtnavi/delay-prediction-service:{{ delay_prediction_service_version }} -CONTAINER_NAME=delay-prediction-$1 - -shift - -docker pull ${DOCKER_IMAGE} -docker run --rm -i \ - --network delay \ - -v delay-prediction-service-data:/app/data \ - -e TIMEZONE=Europe/Berlin \ - -e LOCALE=de-DE \ - -e THINGSBOARD_URL={{ thingsboard_api_url }} \ - -e THINGSBOARD_USER="{{ thingsboard_username }}" \ - -e THINGSBOARD_PASSWORD="{{ thingsboard_password }}" \ - -e THINGSBOARD_DEVICE_GROUP="f1740240-7b3f-11eb-970d-837f8b4d738d" \ - -e MQTT_URI="{{ mqtt_uri }}" \ - -e GTFS_NAME=vvs \ - -e GTFS_URL='https://download.vvs.de/gtfs_realtime.zip' \ - -e PGHOST="delay-postgis" \ - -e PGUSER="{{ delay_postgres_user }}" \ - -e PGPASSWORD="{{ delay_postgres_password }}" \ - -e PGDATABASE="{{ delay_postgres_db }}" \ - -e LOG_LEVEL=debug \ - -p {{ delay_prediction_service_port }}:3000 \ - --name ${CONTAINER_NAME} \ - ${DOCKER_IMAGE} \ - $@ diff --git a/roles/delay-prediction-service/templates/delay-prediction.service b/roles/delay-prediction-service/templates/delay-prediction.service deleted file mode 100644 index 9cc57c8c..00000000 --- a/roles/delay-prediction-service/templates/delay-prediction.service +++ /dev/null @@ -1,16 +0,0 @@ -[Unit] -Description=pull bus positions from Thingsboard, predict delays & positions, send GTFS-RT to MQTT -After=network-online.target -Wants=network-online.target -StartLimitBurst=5 -StartLimitIntervalSec=180 - -[Service] -Restart=always -RestartSec=30 - -ExecStart=/var/delay-prediction/delay-prediction-service service -ExecStop=-docker stop delay-prediction-service - -[Install] -WantedBy=multi-user.target diff --git a/roles/mqtt/handlers/main.yml b/roles/mqtt/handlers/main.yml deleted file mode 100644 index 1d6f7e0f..00000000 --- a/roles/mqtt/handlers/main.yml +++ /dev/null @@ -1,6 +0,0 @@ ---- -- name: Restart mosquitto service - service: - name: mosquitto - state: restarted - listen: "Restart mosquitto" diff --git a/roles/mqtt/meta/main.yml b/roles/mqtt/meta/main.yml deleted file mode 100644 index 2f3d253c..00000000 --- a/roles/mqtt/meta/main.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -dependencies: - - role: geerlingguy.certbot diff --git a/roles/mqtt/tasks/main.yml b/roles/mqtt/tasks/main.yml deleted file mode 100644 index a9561802..00000000 --- a/roles/mqtt/tasks/main.yml +++ /dev/null @@ -1,40 +0,0 @@ ---- -- name: Creates directory - file: - path: /etc/mosquitto/ - state: directory - owner: root - group: root - -- name: Install mosquitto config files - template: - src: '{{ item }}' - dest: /etc/mosquitto/ - with_items: - - mosquitto.conf - - mosquitto.acl - - mosquitto.passwd - notify: Restart mosquitto - -- name: Install systemd files - template: src={{ item }} dest=/etc/systemd/system/ - with_items: - - mosquitto.service - notify: Restart mosquitto - -- name: Start mosquitto - systemd: - name: mosquitto.service - state: started - enabled: yes - daemon_reload: yes - when: enable_mosquitto - - -- name: Stop mosquitto - systemd: - name: mosquitto.service - state: stopped - enabled: yes - daemon_reload: yes - when: enable_mosquitto == false diff --git a/roles/mqtt/templates/mosquitto.acl b/roles/mqtt/templates/mosquitto.acl deleted file mode 100644 index 9cc9f441..00000000 --- a/roles/mqtt/templates/mosquitto.acl +++ /dev/null @@ -1,4 +0,0 @@ -topic read # - -user publisher -topic readwrite # diff --git a/roles/mqtt/templates/mosquitto.conf b/roles/mqtt/templates/mosquitto.conf deleted file mode 100644 index 6345a93b..00000000 --- a/roles/mqtt/templates/mosquitto.conf +++ /dev/null @@ -1,23 +0,0 @@ -allow_anonymous true - -acl_file /mosquitto/config/mosquitto.acl -password_file /mosquitto/config/mosquitto.passwd - -# websockets -listener 1884 -protocol websockets -cafile /mosquitto/config/ca.pem -certfile /mosquitto/config/cert.pem -keyfile /mosquitto/config/key.pem - -#websockets without SSL -listener 1883 -protocol websockets - -# mqtts -listener 8883 -protocol mqtt -cafile /mosquitto/config/ca.pem -certfile /mosquitto/config/cert.pem -keyfile /mosquitto/config/key.pem - diff --git a/roles/mqtt/templates/mosquitto.passwd b/roles/mqtt/templates/mosquitto.passwd deleted file mode 100644 index bee40630..00000000 --- a/roles/mqtt/templates/mosquitto.passwd +++ /dev/null @@ -1 +0,0 @@ -publisher:$7$101$1NiEHV1KCNPcpIsR$oaRLmvzgjZs1cBwe18qATlLjqqMzkyR7gvWj1nB7VQ2iwe85dGlTtEkzdM2quDiE3ba9OsZK4AccSacaU9jyXA== diff --git a/roles/mqtt/templates/mosquitto.service b/roles/mqtt/templates/mosquitto.service deleted file mode 100644 index ca6e79c8..00000000 --- a/roles/mqtt/templates/mosquitto.service +++ /dev/null @@ -1,27 +0,0 @@ -[Unit] -Description=Mosquitto MQTT broker -After=network-online.target -Wants=network-online.target - -[Service] -Restart=always -# restart after a week in order to reload the TLS certificate -RuntimeMaxSec=604800 -Environment=IMAGE_NAME=eclipse-mosquitto:2.0.8 -Environment=CONTAINER_NAME=mosquitto -ExecStartPre=docker pull ${IMAGE_NAME} --quiet -ExecStart=docker run --name ${CONTAINER_NAME} --rm \ - -p 1883:1883 \ - -p 1884:1884 \ - -p 8883:8883 \ - -p 8884:8884 \ - -v /etc/mosquitto/mosquitto.conf:/mosquitto/config/mosquitto.conf \ - -v /etc/mosquitto/mosquitto.acl:/mosquitto/config/mosquitto.acl \ - -v /etc/mosquitto/mosquitto.passwd:/mosquitto/config/mosquitto.passwd \ - -v /etc/ssl/certs/DST_Root_CA_X3.pem:/mosquitto/config/ca.pem \ - -v /etc/letsencrypt/live/{{ api_hostname }}/fullchain.pem:/mosquitto/config/cert.pem \ - -v /etc/letsencrypt/live/{{ api_hostname }}/privkey.pem:/mosquitto/config/key.pem \ - ${IMAGE_NAME} - -[Install] -WantedBy=multi-user.target diff --git a/roles/thingsboard-to-mqtt/handlers/main.yml b/roles/thingsboard-to-mqtt/handlers/main.yml deleted file mode 100644 index 783cbb41..00000000 --- a/roles/thingsboard-to-mqtt/handlers/main.yml +++ /dev/null @@ -1,5 +0,0 @@ ---- -- name: Restart thingsboard-to-mqtt - service: - name: thingsboard-to-mqtt - state: restarted diff --git a/roles/thingsboard-to-mqtt/meta/main.yml b/roles/thingsboard-to-mqtt/meta/main.yml deleted file mode 100644 index a9fe0ed5..00000000 --- a/roles/thingsboard-to-mqtt/meta/main.yml +++ /dev/null @@ -1,4 +0,0 @@ ---- -dependencies: - - role: geerlingguy.docker - - role: mqtt diff --git a/roles/thingsboard-to-mqtt/tasks/main.yml b/roles/thingsboard-to-mqtt/tasks/main.yml deleted file mode 100644 index 5fdc9302..00000000 --- a/roles/thingsboard-to-mqtt/tasks/main.yml +++ /dev/null @@ -1,22 +0,0 @@ ---- -- name: Install systemd files - template: - src: '{{ item }}' - dest: /etc/systemd/system/ - with_items: - - thingsboard-to-mqtt.service - notify: Restart thingsboard-to-mqtt - -- name: Start thingsboard-to-mqtt - systemd: - name: thingsboard-to-mqtt.service - state: started - daemon_reload: yes - when: enable_prediction_service == false - -- name: Stop thingsboard-to-mqtt - systemd: - name: thingsboard-to-mqtt.service - state: stopped - daemon_reload: yes - when: enable_prediction_service \ No newline at end of file diff --git a/roles/thingsboard-to-mqtt/templates/thingsboard-to-mqtt.service b/roles/thingsboard-to-mqtt/templates/thingsboard-to-mqtt.service deleted file mode 100644 index ba076961..00000000 --- a/roles/thingsboard-to-mqtt/templates/thingsboard-to-mqtt.service +++ /dev/null @@ -1,32 +0,0 @@ -[Unit] -Description=Forward the bus positions from thingsboard to MQTT -After=network-online.target -Wants=network-online.target - -[Service] -Restart=always -RestartSec=5 -RuntimeMaxSec=14400 - -Environment=THINGSBOARD_HOST={{ thingsboard_api_url }} -Environment=THINGSBOARD_USERNAME={{ thingsboard_username }} -Environment=THINGSBOARD_PASSWORD="{{ thingsboard_password }}" -Environment=MQTT_BROKER_URL={{ api_hostname }} -Environment=MQTT_USER=publisher -Environment=MQTT_PASSWORD="{{ mqtt_publisher_password }}" -Environment=DOCKER_IMAGE=stadtnavi/thingsboard-to-gtfsrt-mqtt:{{ thingsboard_to_mqtt_version }} -Environment=CONTAINER_NAME=thingsboard-to-mqtt - -ExecStart=docker run --rm \ - -e THINGSBOARD_HOST \ - -e THINGSBOARD_USERNAME \ - -e THINGSBOARD_PASSWORD \ - -e MQTT_USER \ - -e MQTT_PASSWORD \ - -e MQTT_BROKER_URL \ - --name ${CONTAINER_NAME} \ - ${DOCKER_IMAGE} -ExecStop=-docker kill ${CONTAINER_NAME} - -[Install] -WantedBy=multi-user.target