diff --git a/roles/svc-bkp-loc-2-usb/templates/systemctl.service.j2 b/roles/svc-bkp-loc-2-usb/templates/systemctl.service.j2 index 60a69f85..cb03a67a 100644 --- a/roles/svc-bkp-loc-2-usb/templates/systemctl.service.j2 +++ b/roles/svc-bkp-loc-2-usb/templates/systemctl.service.j2 @@ -5,7 +5,7 @@ OnFailure={{ SYS_SERVICE_ON_FAILURE_COMPOSE }} [Service] Type=oneshot -ExecStart=/bin/python {{ systemctl_id | get_service_script_path('py') }} {{ BACKUP_TO_USB_SOURCE }} {{ BACKUP_TO_USB_DESTINATION }} +ExecStart={{ systemctl_script_exec }} {{ BACKUP_TO_USB_SOURCE }} {{ BACKUP_TO_USB_DESTINATION }} ExecStartPost=/bin/systemctl start {{ SYS_SERVICE_CLEANUP_BACKUPS_OLD }} [Install] diff --git a/roles/svc-bkp-rmt-2-loc/templates/systemctl.service.j2 b/roles/svc-bkp-rmt-2-loc/templates/systemctl.service.j2 index fabc11f9..aa70931f 100644 --- a/roles/svc-bkp-rmt-2-loc/templates/systemctl.service.j2 +++ b/roles/svc-bkp-rmt-2-loc/templates/systemctl.service.j2 @@ -5,4 +5,4 @@ OnFailure={{ SYS_SERVICE_ON_FAILURE_COMPOSE }} {{ SYS_SERVICE_CLEANUP_BACKUPS_FA [Service] Type=oneshot ExecStartPre=/bin/sh -c '/usr/bin/python {{ PATH_SYSTEM_LOCK_SCRIPT }} {{ SYS_SERVICE_GROUP_MANIPULATION | join(' ') }} --ignore {{ SYS_SERVICE_GROUP_BACKUPS| join(' ') }} --timeout "{{ SYS_TIMEOUT_BACKUP_SERVICES }}"' -ExecStart=/bin/sh -c '/usr/bin/bash {{ systemctl_id | get_service_script_path('sh') }}' +ExecStart=/bin/sh -c '/usr{{ systemctl_script_exec }}' diff --git a/roles/svc-net-wireguard-plain/templates/systemctl.service.j2 b/roles/svc-net-wireguard-plain/templates/systemctl.service.j2 index 33cb906f..5bed5d2f 100644 --- a/roles/svc-net-wireguard-plain/templates/systemctl.service.j2 +++ b/roles/svc-net-wireguard-plain/templates/systemctl.service.j2 @@ -4,7 +4,7 @@ Before=wg-quick@wg0.service [Service] Type=oneshot -ExecStart=bash {{ systemctl_id | get_service_script_path('sh') }} +ExecStart={{ systemctl_script_exec }} [Install] RequiredBy=wg-quick@wg0.service \ No newline at end of file diff --git a/roles/svc-opt-keyboard-color/templates/systemctl.service.j2 b/roles/svc-opt-keyboard-color/templates/systemctl.service.j2 index a99ac87e..7694bf17 100644 --- a/roles/svc-opt-keyboard-color/templates/systemctl.service.j2 +++ b/roles/svc-opt-keyboard-color/templates/systemctl.service.j2 @@ -4,4 +4,4 @@ OnFailure={{ SYS_SERVICE_ON_FAILURE_COMPOSE }} [Service] Type=oneshot -ExecStart=/bin/python {{ systemctl_id | get_service_script_path('py') }} {{ vendor_and_product_id }} \ No newline at end of file +ExecStart={{ systemctl_script_exec }} {{ vendor_and_product_id }} \ No newline at end of file diff --git a/roles/svc-opt-ssd-hdd/templates/systemctl.service.j2 b/roles/svc-opt-ssd-hdd/templates/systemctl.service.j2 index 847a88d7..09f025a0 100644 --- a/roles/svc-opt-ssd-hdd/templates/systemctl.service.j2 +++ b/roles/svc-opt-ssd-hdd/templates/systemctl.service.j2 @@ -5,4 +5,4 @@ OnFailure={{ SYS_SERVICE_ON_FAILURE_COMPOSE }} [Service] Type=oneshot ExecStartPre=/bin/sh -c '/usr/bin/python {{ PATH_SYSTEM_LOCK_SCRIPT }} {{ SYS_SERVICE_GROUP_MANIPULATION | join(' ') }} --ignore {{ SYS_SERVICE_OPTIMIZE_DRIVE }} {{ SYS_SERVICE_BACKUP_RMT_2_LOC }} --timeout "{{ SYS_TIMEOUT_STORAGE_OPTIMIZER }}"' -ExecStart=/bin/sh -c '/usr/bin/python {{ systemctl_id | get_service_script_path('sh') }} --rapid-storage-path {{ OPT_DRIVE_RAPID_STORAGE_PATH }} --mass-storage-path {{ OPT_DRIVE_MASS_STORAGE_PATH }}' \ No newline at end of file +ExecStart=/bin/sh -c '/usr{{ systemctl_script_exec }} --mass-storage-path {{ OPT_DRIVE_MASS_STORAGE_PATH }}' \ No newline at end of file diff --git a/roles/sys-ctl-alm-email/templates/systemctl@.service.j2 b/roles/sys-ctl-alm-email/templates/systemctl@.service.j2 index e0a990d4..f04d2b70 100644 --- a/roles/sys-ctl-alm-email/templates/systemctl@.service.j2 +++ b/roles/sys-ctl-alm-email/templates/systemctl@.service.j2 @@ -3,6 +3,6 @@ Description=status email for %i to user [Service] Type=oneshot -ExecStart=/bin/bash {{ systemctl_id | get_service_script_path('sh') }} %i +ExecStart={{ systemctl_script_exec }} %i User=root Group=systemd-journal diff --git a/roles/sys-ctl-alm-telegram/templates/systemctl@.service.j2 b/roles/sys-ctl-alm-telegram/templates/systemctl@.service.j2 index 1a6c992e..b51bb2a9 100644 --- a/roles/sys-ctl-alm-telegram/templates/systemctl@.service.j2 +++ b/roles/sys-ctl-alm-telegram/templates/systemctl@.service.j2 @@ -3,6 +3,6 @@ Description=status Telegram message for %i to user [Service] Type=oneshot -ExecStart=/bin/bash {{ systemctl_id | get_service_script_path('sh') }} %i +ExecStart={{ systemctl_script_exec }} %i User=root Group=systemd-journal diff --git a/roles/sys-ctl-cln-bkps/templates/systemctl.service.j2 b/roles/sys-ctl-cln-bkps/templates/systemctl.service.j2 index c7e797ee..52093a83 100644 --- a/roles/sys-ctl-cln-bkps/templates/systemctl.service.j2 +++ b/roles/sys-ctl-cln-bkps/templates/systemctl.service.j2 @@ -5,4 +5,4 @@ OnFailure={{ SYS_SERVICE_ON_FAILURE_COMPOSE }} [Service] Type=oneshot ExecStartPre=/bin/sh -c '/usr/bin/python {{ PATH_SYSTEM_LOCK_SCRIPT }} {{ SYS_SERVICE_GROUP_MANIPULATION | join(' ') }} --ignore {{ SYS_SERVICE_GROUP_CLEANUP| join(' ') }} --timeout "{{ SYS_TIMEOUT_BACKUP_SERVICES }}"' -ExecStart=/bin/sh -c '/usr/bin/python {{ systemctl_id | get_service_script_path('sh') }} --backups-folder-path {{ BACKUPS_FOLDER_PATH }} --maximum-backup-size-percent {{SIZE_PERCENT_MAXIMUM_BACKUP}}' \ No newline at end of file +ExecStart=/bin/sh -c '/usr{{ systemctl_script_exec }} --backups-folder-path {{ BACKUPS_FOLDER_PATH }} --maximum-backup-size-percent {{SIZE_PERCENT_MAXIMUM_BACKUP}}' \ No newline at end of file diff --git a/roles/sys-ctl-cln-disc-space/templates/script.sh.j2 b/roles/sys-ctl-cln-disc-space/templates/script.sh.j2 index e4b5f9a3..f4e07183 100644 --- a/roles/sys-ctl-cln-disc-space/templates/script.sh.j2 +++ b/roles/sys-ctl-cln-disc-space/templates/script.sh.j2 @@ -24,7 +24,7 @@ if [ "$force_freeing" = true ]; then {% if BACKUPS_FOLDER_PATH is defined and SIZE_PERCENT_MAXIMUM_BACKUP is defined %} echo "cleaning up backups" && - python {{ 'sys-ctl-cln-backups' | get_service_script_path('sh') }} --backups-folder-path {{ BACKUPS_FOLDER_PATH }} --maximum-backup-size-percent {{SIZE_PERCENT_MAXIMUM_BACKUP}} || exit 2 + python {{ 'sys-ctl-cln-backups' | get_service_script_path('sh') }} --backups-folder-path {{ BACKUPS_FOLDER_PATH }} --maximum-backup-size-percent {{ SIZE_PERCENT_MAXIMUM_BACKUP }} || exit 2 {% endif %} if pacman -Qs $package > /dev/null ; then diff --git a/roles/sys-ctl-cln-disc-space/templates/systemctl.service.j2 b/roles/sys-ctl-cln-disc-space/templates/systemctl.service.j2 index 59977936..f773cde8 100644 --- a/roles/sys-ctl-cln-disc-space/templates/systemctl.service.j2 +++ b/roles/sys-ctl-cln-disc-space/templates/systemctl.service.j2 @@ -5,4 +5,4 @@ OnFailure={{ SYS_SERVICE_ON_FAILURE_COMPOSE }} [Service] Type=oneshot ExecStartPre=/bin/sh -c '/usr/bin/python {{ PATH_SYSTEM_LOCK_SCRIPT }} {{ SYS_SERVICE_GROUP_MANIPULATION | join(' ') }} --ignore {{ SYS_SERVICE_GROUP_CLEANUP| join(' ') }} --timeout "{{ SYS_TIMEOUT_BACKUP_SERVICES }}"' -ExecStart=/bin/sh -c '/bin/bash {{ systemctl_id | get_service_script_path('sh') }} {{SIZE_PERCENT_CLEANUP_DISC_SPACE}}' \ No newline at end of file +ExecStart=/bin/sh -c '{{ systemctl_script_exec }} {{ SIZE_PERCENT_CLEANUP_DISC_SPACE }}' \ No newline at end of file diff --git a/roles/sys-ctl-hlth-csp/templates/systemctl.service.j2 b/roles/sys-ctl-hlth-csp/templates/systemctl.service.j2 index d0285bf0..870f0584 100644 --- a/roles/sys-ctl-hlth-csp/templates/systemctl.service.j2 +++ b/roles/sys-ctl-hlth-csp/templates/systemctl.service.j2 @@ -4,4 +4,4 @@ OnFailure={{ SYS_SERVICE_ON_FAILURE_COMPOSE }} [Service] Type=oneshot -ExecStart=/usr/bin/python3 {{ systemctl_id | get_service_script_path('py') }} --nginx-config-dir={{ NGINX.DIRECTORIES.HTTP.SERVERS }} \ No newline at end of file +ExecStart={{ systemctl_script_exec }} --nginx-config-dir={{ NGINX.DIRECTORIES.HTTP.SERVERS }} \ No newline at end of file diff --git a/roles/sys-ctl-hlth-docker-volumes/templates/systemctl.service.j2 b/roles/sys-ctl-hlth-docker-volumes/templates/systemctl.service.j2 index 438001b8..d8665b9c 100644 --- a/roles/sys-ctl-hlth-docker-volumes/templates/systemctl.service.j2 +++ b/roles/sys-ctl-hlth-docker-volumes/templates/systemctl.service.j2 @@ -4,4 +4,4 @@ OnFailure={{ SYS_SERVICE_ON_FAILURE_COMPOSE }} [Service] Type=oneshot -ExecStart=/bin/bash {{ systemctl_id | get_service_script_path('sh') }} "{{ DOCKER_WHITELISTET_ANON_VOLUMES | join(' ') }}" +ExecStart={{ systemctl_script_exec }} "{{ DOCKER_WHITELISTET_ANON_VOLUMES | join(' ') }}" diff --git a/roles/sys-ctl-mtn-cert-deploy/templates/systemctl.service.j2 b/roles/sys-ctl-mtn-cert-deploy/templates/systemctl.service.j2 index 74ec50c1..32ddcd12 100644 --- a/roles/sys-ctl-mtn-cert-deploy/templates/systemctl.service.j2 +++ b/roles/sys-ctl-mtn-cert-deploy/templates/systemctl.service.j2 @@ -4,4 +4,4 @@ OnFailure={{ SYS_SERVICE_ON_FAILURE_COMPOSE }} [Service] Type=oneshot -ExecStart={{ systemctl_id | get_service_script_path('sh') }} {{ ssl_cert_folder }} {{ docker_compose.directories.instance }} {{ LETSENCRYPT_LIVE_PATH }} +ExecStart={{ systemctl_script_exec }} {{ ssl_cert_folder }} {{ docker_compose.directories.instance }} {{ LETSENCRYPT_LIVE_PATH }} diff --git a/roles/sys-ctl-rpr-docker-hard/templates/systemctl.service.j2 b/roles/sys-ctl-rpr-docker-hard/templates/systemctl.service.j2 index fb502723..2ed47252 100644 --- a/roles/sys-ctl-rpr-docker-hard/templates/systemctl.service.j2 +++ b/roles/sys-ctl-rpr-docker-hard/templates/systemctl.service.j2 @@ -5,4 +5,4 @@ OnFailure={{ SYS_SERVICE_ON_FAILURE_COMPOSE }} [Service] Type=oneshot ExecStartPre=/bin/sh -c '/usr/bin/python {{ PATH_SYSTEM_LOCK_SCRIPT }} {{ SYS_SERVICE_GROUP_MANIPULATION | join(' ') }} --ignore {{ SYS_SERVICE_GROUP_CLEANUP | join(' ') }} {{ SYS_SERVICE_REPAIR_DOCKER_HARD }} --timeout "{{ SYS_TIMEOUT_RESTART_DOCKER }}"' -ExecStart=/bin/sh -c '/usr/bin/python {{ systemctl_id | get_service_script_path('py') }}' \ No newline at end of file +ExecStart=/bin/sh -c '/usr{{ systemctl_script_exec }}' \ No newline at end of file diff --git a/roles/sys-ctl-rpr-docker-soft/templates/systemctl.service.j2 b/roles/sys-ctl-rpr-docker-soft/templates/systemctl.service.j2 index 974b445a..50da52e5 100644 --- a/roles/sys-ctl-rpr-docker-soft/templates/systemctl.service.j2 +++ b/roles/sys-ctl-rpr-docker-soft/templates/systemctl.service.j2 @@ -5,4 +5,4 @@ OnFailure={{ SYS_SERVICE_ON_FAILURE_COMPOSE }} [Service] Type=oneshot ExecStartPre=/bin/sh -c '/usr/bin/python {{ PATH_SYSTEM_LOCK_SCRIPT }} {{ SYS_SERVICE_GROUP_MANIPULATION | join(' ') }} --ignore {{ SYS_SERVICE_GROUP_CLEANUP| join(' ') }} sys-ctl-rpr-docker-soft --timeout "{{ SYS_TIMEOUT_HEAL_DOCKER }}"' -ExecStart=/bin/sh -c '/bin/python {{ systemctl_id | get_service_script_path('py') }} {{ PATH_DOCKER_COMPOSE_INSTANCES }}' \ No newline at end of file +ExecStart=/bin/sh -c '{{ systemctl_script_exec }} {{ PATH_DOCKER_COMPOSE_INSTANCES }}' \ No newline at end of file diff --git a/roles/sys-systemctl/tasks/03_base.yml b/roles/sys-systemctl/tasks/03_base.yml index 054b0c03..ee537eaa 100644 --- a/roles/sys-systemctl/tasks/03_base.yml +++ b/roles/sys-systemctl/tasks/03_base.yml @@ -1,7 +1,7 @@ # roles/sys-systemctl/tasks/03_base.yml - name: "find best matching source for service script" set_fact: - service_src: >- + systemctl_script_src: >- {{ lookup('first_found', { 'files': [ @@ -20,7 +20,7 @@ include_tasks: 04_files.yml when: - systemctl_copy_files | bool - - service_src + - systemctl_script_src - name: "Load systemctl logic for '{{ systemctl_id }}'" include_tasks: 05_service.yml diff --git a/roles/sys-systemctl/tasks/04_files.yml b/roles/sys-systemctl/tasks/04_files.yml index a0dcb22b..47c6f372 100644 --- a/roles/sys-systemctl/tasks/04_files.yml +++ b/roles/sys-systemctl/tasks/04_files.yml @@ -9,15 +9,15 @@ block: - name: "render template" template: - src: "{{ service_src }}" - dest: "{{ [systemctl_script_dir, (service_src | basename | regex_replace('\\.j2$', ''))] | path_join }}" + src: "{{ systemctl_script_src }}" + dest: "{{ [systemctl_script_dir, (systemctl_script_src | basename | regex_replace('\\.j2$', ''))] | path_join }}" mode: "0755" - when: service_src.endswith('.j2') + when: systemctl_script_src.endswith('.j2') - name: "copy raw file" copy: - src: "{{ service_src }}" - dest: "{{ [systemctl_script_dir, (service_src | basename)] | path_join }}" + src: "{{ systemctl_script_src }}" + dest: "{{ [systemctl_script_dir, (systemctl_script_src | basename)] | path_join }}" mode: "0755" - when: not service_src.endswith('.j2') + when: not systemctl_script_src.endswith('.j2') when: systemctl_copy_files | bool diff --git a/roles/sys-systemctl/templates/systemctl.service.j2 b/roles/sys-systemctl/templates/systemctl.service.j2 index 1eb32fab..339a2812 100644 --- a/roles/sys-systemctl/templates/systemctl.service.j2 +++ b/roles/sys-systemctl/templates/systemctl.service.j2 @@ -4,4 +4,4 @@ OnFailure={{ SYS_SERVICE_ON_FAILURE_COMPOSE }} [Service] Type=oneshot -ExecStart=/bin/bash {{ systemctl_id | get_service_script_path( service_src | basename | regex_replace('\\.j2$', '') | filetype ) }} +ExecStart={{ systemctl_script_exec }} diff --git a/roles/sys-systemctl/vars/main.yml b/roles/sys-systemctl/vars/main.yml index c5245582..a1e73fad 100644 --- a/roles/sys-systemctl/vars/main.yml +++ b/roles/sys-systemctl/vars/main.yml @@ -8,4 +8,10 @@ systemctl_script_dir: "{{ [ PATH_SYSTEMCTL_SCRIPTS, systemctl_id ] | path_jo ## Settings systemctl_copy_files: true # When set to false file copying will be skipped systemctl_timer_enabled: false # When set to true timmer will be loaded -systemctl_state: "{{ SYS_SERVICE_DEFAULT_STATE }}" \ No newline at end of file +systemctl_state: "{{ SYS_SERVICE_DEFAULT_STATE }}" + +# Dynamic Loaded ( Just available when dependencies are loaded ) +systemctl_script_base: "{{ systemctl_script_src | basename | regex_replace('\\.j2$', '') }}" +systemctl_script_type: "{{ systemctl_script_base | filetype }}" +systemctl_script_inter: "/bin/{{ 'bash' if systemctl_script_type == 'sh' else 'python3'}}" +systemctl_script_exec: "{{ systemctl_script_inter }} {{ systemctl_id | get_service_script_path( systemctl_script_type ) }}" \ No newline at end of file diff --git a/roles/update-docker/templates/systemctl.service.j2 b/roles/update-docker/templates/systemctl.service.j2 index 079ed682..d2bf7df1 100644 --- a/roles/update-docker/templates/systemctl.service.j2 +++ b/roles/update-docker/templates/systemctl.service.j2 @@ -5,4 +5,4 @@ OnFailure={{ SYS_SERVICE_ON_FAILURE_COMPOSE }} [Service] Type=oneshot ExecStartPre=/bin/sh -c '/usr/bin/python {{ PATH_SYSTEM_LOCK_SCRIPT }} {{ SYS_SERVICE_GROUP_MANIPULATION | join(' ') }} --ignore {{ SYS_SERVICE_GROUP_CLEANUP | join(' ') }} update-docker --timeout "{{ SYS_TIMEOUT_HEAL_DOCKER }}"' -ExecStart=/bin/sh -c '/usr/bin/python {{ systemctl_id | get_service_script_path('py') }} \ No newline at end of file +ExecStart=/bin/sh -c '/usr{{ systemctl_script_exec }} \ No newline at end of file