From 95dbf935912963d870338ddce7843d92b61caf2f Mon Sep 17 00:00:00 2001
From: ngarafol <ngarafol@users.noreply.github.com>
Date: Sun, 20 Oct 2024 23:03:21 +0200
Subject: [PATCH] use pm2 with systemd to make pingvin-share survive reboots
 (#3935)

---
 ct/pingvin.sh              | 4 ++--
 install/pingvin-install.sh | 5 ++++-
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/ct/pingvin.sh b/ct/pingvin.sh
index 0cce4f60d..c9a264cbb 100644
--- a/ct/pingvin.sh
+++ b/ct/pingvin.sh
@@ -56,7 +56,7 @@ function update_script() {
 header_info
 if [[ ! -d /opt/pingvin-share ]]; then msg_error "No ${APP} Installation Found!"; exit; fi
 msg_info "Stopping Pingvin Share"
-pm2 stop pingvin-share-backend pingvin-share-frontend &>/dev/null
+systemctl stop pm2-root.service
 msg_ok "Stopped Pingvin Share"
 
 msg_info "Updating Pingvin Share"
@@ -72,7 +72,7 @@ npm run build &>/dev/null
 msg_ok "Updated Pingvin Share"
 
 msg_info "Starting Pingvin Share"
-pm2 start pingvin-share-backend pingvin-share-frontend &>/dev/null
+systemctl start pm2-root.service
 msg_ok "Started Pingvin Share"
 
 msg_ok "Updated Successfully"
diff --git a/install/pingvin-install.sh b/install/pingvin-install.sh
index 4430cc214..2997bbbcc 100644
--- a/install/pingvin-install.sh
+++ b/install/pingvin-install.sh
@@ -47,7 +47,10 @@ sed -i '/"admin.config.smtp.allow-unauthorized-certificates":\|admin.config.smtp
 $STD npm install
 $STD npm run build
 $STD pm2 start --name="pingvin-share-frontend" npm -- run start
-$STD pm2 startup
+# create and enable pm2-root systemd script
+$STD pm2 startup systemd 
+# save running pm2 processes so pingvin-share can survive reboots
+$STD pm2 save
 msg_ok "Installed Pingvin Share"
 
 motd_ssh