Update pm2 tasks to update the config correctly
Previously, if you changed the pm2 ecosystem file content, it wouldn't actually be reflected in the running services. Now it will be!
This commit is contained in:
parent
7131bc0ea9
commit
2f874653bf
1 changed files with 20 additions and 6 deletions
|
@ -65,7 +65,7 @@
|
||||||
|
|
||||||
- name: Create pm2 ecosystem file
|
- name: Create pm2 ecosystem file
|
||||||
copy:
|
copy:
|
||||||
content: >
|
content: |
|
||||||
module.exports = {
|
module.exports = {
|
||||||
apps: [
|
apps: [
|
||||||
{
|
{
|
||||||
|
@ -78,12 +78,26 @@
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
dest: "/srv/impress-2020/ecosystem.config.js"
|
dest: "~/ecosystem.config.js"
|
||||||
|
# Create a temporary backup file, so we can use it to delete the old
|
||||||
|
# version of the services. (This is important if e.g. a service is
|
||||||
|
# removed or renamed, in which case deleting from the *new* config file
|
||||||
|
# wouldn't include it.)
|
||||||
|
backup: yes
|
||||||
|
register: pm2_ecosystem_file
|
||||||
|
|
||||||
- name: Start pm2 ecosystem (even if the app isn't ready yet)
|
- name: Delete old pm2 services if config file changed
|
||||||
command:
|
command: "pm2 delete {{ pm2_ecosystem_file.backup_file | quote }}"
|
||||||
chdir: "/srv/impress-2020"
|
when: pm2_ecosystem_file is changed and pm2_ecosystem_file.backup_file is defined
|
||||||
cmd: "pm2 start ecosystem.config.js"
|
|
||||||
|
- name: Delete old pm2 config file if it changed
|
||||||
|
file:
|
||||||
|
path: "{{ pm2_ecosystem_file.backup_file }}"
|
||||||
|
state: absent
|
||||||
|
when: pm2_ecosystem_file is changed and pm2_ecosystem_file.backup_file is defined
|
||||||
|
|
||||||
|
- name: Start pm2 services
|
||||||
|
command: "pm2 start ~/ecosystem.config.js"
|
||||||
|
|
||||||
- name: Save pm2 startup script
|
- name: Save pm2 startup script
|
||||||
command: pm2 save
|
command: pm2 save
|
||||||
|
|
Loading…
Reference in a new issue