tech:script_shell_commande_timeout
Ceci est une ancienne révision du document !
Script shell commande timeout
Voir aussi :
A titre d'exemple. Idéalement il faut gérer le timeout avec Ansible
Exemple de code Ansible
- name: command ldap_search become: true ansible.builtin.command: | /usr/bin/timeout --kill-after=15 10 /usr/bin/ldapsearch -LLL -D cn={{ lookup('env', 'LDAP_USER') }} -b o=unixauth -y /root/.ansible/tmp-files/.ldap.txt uid={{ CDO_ACCOUNT_USER | quote }} dn changed_when: false check_mode: false register: ldapsearch environment: LANG: C failed_when: - ldapsearch.rc != 0 # OK - ldapsearch.rc != 124 # Timeout. SIGTERM - ldapsearch.rc != 137 # Timeout. SIGKILL - name: fail when timeout - SIGTERM fail: msg: "Error_Command_Timeout. Process arrêté par SIGTERM." when: ldapsearch.rc == 124 - name: fail when timeout - SIGKILL fail: msg: "Error_Command_Timeout. Process arrêté par SIGKILL." when: ldapsearch.rc == 137 - name: fail if ACME user fail: msg: | Error_ElementAlreadyUsed. Nom de compte utilisateur déjà utilisé par ACME {{ CDO_ACCOUNT_USER }}. when: - ldapsearch.stdout_lines |select('regex', '^dn:') |list is regex(',o=unixauth') - not allow_ldap_acme
Concernant Ansible voir aussi https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_async.html
async pool timeout
- play1.yml
#!/usr/bin/ansible-playbook --- - name: test hosts: localhost gather_facts: false # TIMEOUT_MAX = async # when poll != 0 # TIMEOUT_MAX = retries x delay # when poll == 0 tasks: - name: Command shell: | sleep 5 date >> /tmp/date.log poll: 0 # When pool is a positive value, the playbook will still block on the task until it either completes, fails or timeout async: 2 # if poll != 0 : fail when task is longer than async value register: cmd_sleep - name: DEBUG 10 debug: msg: "Command en cours d'execution" - name: Async_status async_status: jid: "{{ cmd_sleep.ansible_job_id }}" register: job_result until: job_result.finished retries: 3 # MAX TIMEOUT VAR delay: 2 # MAX TIMEOUT VAR - name: DEBUG 20 debug: msg: "Execution terminée"
tech/script_shell_commande_timeout.1742825205.txt.gz · Dernière modification : de 127.0.0.1
