### Start - name: Stop ActiveMQ systemd: scope: user name: "activemq.service" state: stopped listen: restart_mq - name: Remove old config backups and all activemq logs shell: | find "{{ activemq_dir }}/conf" -maxdepth 1 -type f -name 'activemq.xml.*' -printf '%T@\t%p\0' |sort -z -k 1n,1 |head -z -n -1 |cut -z -f 2- |xargs -0 rm find "{{ activemq_dir }}/data" -maxdepth 1 -type f -name 'activemq*.log*' -delete ignore_errors: true listen: restart_mq - name: Remove error log from worker command: find . -maxdepth 1 -type f -name 'activemq*.log' -delete run_once: true delegate_to: localhost listen: restart_mq - name: "Create units folder" file: path: ~/.config/systemd/user state: directory listen: restart_mq - name: Deploy new unit template: src: "activemq.service.j2" dest: "~/.config/systemd/user/activemq.service" mode: 0660 listen: restart_mq ### Restore # 1. Stop # 2. Copy error log and restore config - name: Copy log and restore config shell: | cp "{{ activemq_log }}" "{{ activemq_error_log }}" cp $(find "{{ activemq_dir }}/conf" -name 'activemq.xml.*' |sort |tail -n1) "{{ activemq_conf }}" # listen: restore_mq # 3. Copy error log to worker - name: Copy error log to worker fetch: src: "{{ activemq_error_log }}" dest: "./activemq_error_{{ inventory_hostname }}.log" flat: true # 4. Start ### - name: Start ActiveMQ systemd: scope: user name: "activemq.service" state: started daemon_reload: true enabled: true listen: restart_mq - name: Wait pause: seconds: "{{ wait_sec }}" listen: restart_mq - name: Add fake fail to log lineinfile: dest: "{{ activemq_log }}" line: 'Failed: ERROR' when: fake_fail |bool == true listen: restart_mq - name: Check ActiveMQ status shell: "{{ activemq_bin }} status" ignore_errors: true register: amq_status # It must contain "ActiveMQ is running" changed_when: '"is running" not in amq_status.stdout_lines |lower' listen: restart_mq notify: - Stop ActiveMQ - Copy log and restore config - Copy error log to worker - Start ActiveMQ - name: Check ActiveMQ logs command: cat "{{ activemq_log }}" register: log_status changed_when: '"failed" in log_status.stdout_lines |lower' listen: restart_mq notify: - Stop ActiveMQ - Copy log and restore config - Copy error log to worker - Start ActiveMQ