3
0

Refactor NGS Pulsar role: remove obsolete files and add new task and handler definitions

This commit is contained in:
NiceDevil
2025-08-24 10:05:24 +02:00
parent c17fe406f2
commit 5d3aed6890
7 changed files with 302 additions and 12 deletions

View File

@@ -0,0 +1,5 @@
# roles/install_ngs-pulsar/handlers/main.yml
---
- name: "SystemD Daemon neu laden"
systemd:
daemon_reload: yes

View File

@@ -0,0 +1,123 @@
---
#roles/install_ngs-pulsar/tasks/main.yml
#################################################################
# 01 | Pulsar Installationsverzeichnis erstellen
#################################################################
- name: "Pulsar Installationsverzeichnis erstellen"
file:
path: "{{ pulsar_install_path }}"
state: directory
mode: '0755'
owner: root
group: root
- name: "Pulsar Binary herunterladen"
get_url:
url: "{{ pulsar_binary_url }}"
dest: "{{ pulsar_install_path }}/{{ pulsar_binary_name }}"
mode: '0755'
owner: root
group: root
force: yes
#################################################################
# 02 | Init-System erkennen & prüfen
#################################################################
- name: "Init-System erkennen"
set_fact:
init_system: "{{ 'systemd' if ansible_service_mgr == 'systemd' else 'openrc' if ansible_service_mgr == 'openrc' else 'unknown' }}"
- name: "Fehler wenn Init-System nicht unterstützt wird"
fail:
msg: "Nicht unterstütztes Init-System: {{ ansible_service_mgr }}"
when: init_system == 'unknown'
#################################################################
# 03 | Service-Dateien erstellen
#################################################################
- name: "SystemD Service-Datei erstellen"
template:
src: pulsar.systemd.j2
dest: /etc/systemd/system/ngs-pulsar.service
mode: '0644'
owner: root
group: root
when: init_system == 'systemd'
notify: "SystemD Daemon neu laden"
- name: "OpenRC Service-Datei erstellen"
template:
src: pulsar.openrc.j2
dest: /etc/init.d/ngs-pulsar
mode: '0755'
owner: root
group: root
when: init_system == 'openrc'
#################################################################
# 04 | Weitere Dateien & Verzeichnisse
#################################################################
- name: "Uninstall-Skript erstellen"
template:
src: uninstall.sh.j2
dest: "{{ pulsar_install_path }}/uninstall.sh"
mode: '0755'
owner: root
group: root
- name: "Log-Verzeichnis für Enginsight erstellen"
file:
path: /var/log/enginsight
state: directory
mode: '0755'
owner: root
group: root
#################################################################
# 05 | Pulsar installieren
#################################################################
- name: "Pulsar Initial-Konfiguration ausführen"
command: >
{{ pulsar_install_path }}/{{ pulsar_binary_name }}
-install=true
-license={{ pulsar_license_type }}
-accessKeyId={{ vault_pulsar_access_key_id }}
-accessKeySecret={{ vault_pulsar_access_key_secret }}
-api={{ pulsar_api_url }}
args:
chdir: "{{ pulsar_install_path }}"
register: pulsar_install_result
changed_when: true
#################################################################
# 06 | Dienst aktivieren & starten
#################################################################
- name: "Pulsar Service aktivieren und starten (SystemD)"
systemd:
name: ngs-pulsar
enabled: yes
state: started
daemon_reload: yes
when: init_system == 'systemd'
- name: "Pulsar Service aktivieren und starten (OpenRC)"
block:
- name: "OpenRC Service zu Runlevel hinzufügen"
command: rc-update add ngs-pulsar default
register: rc_update_result
changed_when: rc_update_result.rc == 0
failed_when: false
- name: "OpenRC Service starten"
service:
name: ngs-pulsar
state: started
when: init_system == 'openrc'
#################################################################
# Abschlussmeldung
#################################################################
- name: "Installation erfolgreich abgeschlossen"
debug:
msg: "Enginsight Pulsar wurde erfolgreich installiert und konfiguriert"

View File

@@ -0,0 +1,26 @@
#!/sbin/openrc-run
name="ngs-pulsar"
description="Enginsight Pulsar Service"
command="{{ pulsar_install_path }}/{{ pulsar_binary_name }}"
command_args=">> /var/log/enginsight/pulsar.log 2>&1"
command_background="yes"
pidfile="/var/run/${name}.pid"
command_user="root:root"
directory="{{ pulsar_install_path }}"
depend() {
need net
use logger
after firewall
}
start_pre() {
checkpath --directory --owner root:root --mode 0755 /var/log/enginsight
checkpath --file --owner root:root --mode 0644 /var/log/enginsight/pulsar.log
[ -x "{{ pulsar_install_path }}/{{ pulsar_binary_name }}" ] || {
eerror "Binary not executable: {{ pulsar_install_path }}/{{ pulsar_binary_name }}"
return 1
}
}

View File

@@ -0,0 +1,25 @@
# roles/install_ngs-pulsar/templates/pulsar.service.j2
[Unit]
Description=NGS-Pulsar
ConditionPathExists={{ pulsar_install_path }}/
After=network-online.target
Wants=network-online.target
[Service]
Type=simple
User=root
WorkingDirectory={{ pulsar_install_path }}/
ExecStartPre=/bin/mkdir -p /var/log/enginsight
ExecStart={{ pulsar_install_path }}/{{ pulsar_binary_name }}
ExecStopPost={{ pulsar_install_path }}/{{ pulsar_binary_name }} -clear-shield
KillMode=process
Restart=on-failure
RestartSec=3
StartLimitInterval=600
StartLimitBurst=5
StandardOutput=journal
StandardError=journal
SyslogIdentifier=pulsar-m8
[Install]
WantedBy=multi-user.target

View File

@@ -0,0 +1,71 @@
# roles/install_ngs-pulsar/templates/uninstall.sh.j2
#!/bin/bash
# Enginsight Pulsar Deinstallations-Skript
echo "Stoppe Enginsight Pulsar Service..."
# Init-System erkennen und Service stoppen
if command -v systemctl >/dev/null 2>&1; then
# SystemD
echo "SystemD erkannt - stoppe und deaktiviere Service..."
# Erst clear-shield ausführen, solange die Binary noch existiert
if [ -x "{{ pulsar_install_path }}/{{ pulsar_binary_name }}" ]; then
echo "Führe clear-shield aus..."
{{ pulsar_install_path }}/{{ pulsar_binary_name }} -clear-shield 2>/dev/null || true
fi
systemctl stop enginsight-pulsar 2>/dev/null || true
systemctl disable enginsight-pulsar 2>/dev/null || true
rm -f /etc/systemd/system/enginsight-pulsar.service
systemctl daemon-reload
systemctl reset-failed enginsight-pulsar 2>/dev/null || true
elif command -v rc-service >/dev/null 2>&1; then
# OpenRC
echo "OpenRC erkannt - stoppe und deaktiviere Service..."
# Erst clear-shield ausführen, solange die Binary noch existiert
if [ -x "{{ pulsar_install_path }}/{{ pulsar_binary_name }}" ]; then
echo "Führe clear-shield aus..."
{{ pulsar_install_path }}/{{ pulsar_binary_name }} -clear-shield 2>/dev/null || true
fi
rc-service enginsight-pulsar stop 2>/dev/null || true
rc-update del enginsight-pulsar 2>/dev/null || true
rm -f /etc/init.d/enginsight-pulsar
elif command -v service >/dev/null 2>&1; then
# SysV Init oder andere
echo "Legacy Init-System erkannt - stoppe Service..."
# Erst clear-shield ausführen, solange die Binary noch existiert
if [ -x "{{ pulsar_install_path }}/{{ pulsar_binary_name }}" ]; then
echo "Führe clear-shield aus..."
{{ pulsar_install_path }}/{{ pulsar_binary_name }} -clear-shield 2>/dev/null || true
fi
service enginsight-pulsar stop 2>/dev/null || true
update-rc.d -f enginsight-pulsar remove 2>/dev/null || true
chkconfig enginsight-pulsar off 2>/dev/null || true
rm -f /etc/init.d/enginsight-pulsar
else
echo "Warnung: Konnte Init-System nicht erkennen. Manuelles Stoppen des Services erforderlich."
# Trotzdem clear-shield versuchen
if [ -x "{{ pulsar_install_path }}/{{ pulsar_binary_name }}" ]; then
echo "Führe clear-shield aus..."
{{ pulsar_install_path }}/{{ pulsar_binary_name }} -clear-shield 2>/dev/null || true
fi
fi
echo "Lösche Installationsverzeichnis..."
rm -rf "{{ pulsar_install_path }}"
echo "Lösche übergeordnetes Enginsight-Verzeichnis falls leer..."
rmdir /opt/enginsight 2>/dev/null || true
echo "Lösche Log-Verzeichnis..."
rm -rf /var/log/enginsight
echo "Enginsight Pulsar wurde erfolgreich deinstalliert."