From fd8a1ffef29c1ba7c7f204d44e78b4b4ab9b8b8b Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Tue, 3 Jun 2025 11:23:26 +0200 Subject: [PATCH 1/2] Enable PM2 to auto restart applications after a reboot --- CHANGELOG.md | 8 ++++++++ roles/pm2/manage/tasks/main.yml | 16 ++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 31d062a..b475fd6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,14 @@ All changes that impact users of this module are documented in this file, in the [Common Changelog](https://common-changelog.org) format with some additional specifications defined in the CONTRIBUTING file. This codebase adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## Unreleased [minor] + +> Development of this release was supported by the [French Ministry for Foreign Affairs](https://www.diplomatie.gouv.fr/fr/politique-etrangere-de-la-france/diplomatie-numerique/) through its ministerial [State Startups incubator](https://beta.gouv.fr/startups/open-terms-archive.html) under the aegis of the Ambassador for Digital Affairs. + +### Added + +- Enable PM2 to automatically restart Open Terms Archive applications after a reboot + ## 2.0.2 - 2024-06-12 _Full changeset and discussions: [#46](https://github.com/OpenTermsArchive/deployment/pull/46)._ diff --git a/roles/pm2/manage/tasks/main.yml b/roles/pm2/manage/tasks/main.yml index 7f16ea5..54787f5 100644 --- a/roles/pm2/manage/tasks/main.yml +++ b/roles/pm2/manage/tasks/main.yml @@ -23,6 +23,13 @@ - restart - start +- name: Generate and enable PM2 startup script + ansible.builtin.command: + cmd: sudo env PATH=$PATH:/usr/bin pm2 startup systemd -u {{ ansible_user }} --hp /home/{{ ansible_user }} + tags: + - restart + - start + - name: Start Open Terms Archive applications ansible.builtin.command: cmd: pm2 startOrRestart pm2.config.cjs @@ -32,3 +39,12 @@ tags: - restart - start + +- name: Save PM2 process list for auto-restart + ansible.builtin.command: + cmd: pm2 save + chdir: /home/{{ ansible_user }}/{{ ota_directory }} + tags: + - restart + - start + - stop From a79ac81a2e0bc5bce4404fb8055a69fd1a7a865e Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Tue, 10 Jun 2025 09:41:40 +0200 Subject: [PATCH 2/2] Use long version option --- roles/pm2/manage/tasks/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/pm2/manage/tasks/main.yml b/roles/pm2/manage/tasks/main.yml index 54787f5..779ad09 100644 --- a/roles/pm2/manage/tasks/main.yml +++ b/roles/pm2/manage/tasks/main.yml @@ -25,7 +25,7 @@ - name: Generate and enable PM2 startup script ansible.builtin.command: - cmd: sudo env PATH=$PATH:/usr/bin pm2 startup systemd -u {{ ansible_user }} --hp /home/{{ ansible_user }} + cmd: sudo env PATH=$PATH:/usr/bin pm2 startup systemd --user {{ ansible_user }} --hp /home/{{ ansible_user }} tags: - restart - start