Have a few processes that we run with Forever that I have been working on automating. Needed to be able to start them if they are not running and restart them if they are. The restart was a bit tricky. Usually you can just restart the process name, but since some of our processes have a wide variety of arguments that wasn’t always working. So, first we try to find the processId using forever list and grep. Then we can use that to determine if the process is running and what the process ID is if so. Here is what I am currently using to do so:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
- name: Check if process is running shell: "forever list | grep processName | head -1 | cut -c24-27" register: process changed_when: false - name: Restart process shell: "forever restart {{ process.stdout }}" args: executable: /bin/bash when: process.stdout != "" - name: Start process shell: "forever start processName" args: executable: /bin/bash when: process.stdout == "" |