From 595c6836d9fca86664999f739fc64df333ff3805 Mon Sep 17 00:00:00 2001 From: Rajdeep Malakar Date: Wed, 6 Mar 2024 14:03:48 +0530 Subject: [PATCH] added pm2 and cron scripts Signed-off-by: Rajdeep Malakar --- check_and_restart.sh | 19 +++++++++++++++++++ ecosystem.config.js | 6 ++++++ 2 files changed, 25 insertions(+) create mode 100755 check_and_restart.sh create mode 100644 ecosystem.config.js diff --git a/check_and_restart.sh b/check_and_restart.sh new file mode 100755 index 0000000..d440edd --- /dev/null +++ b/check_and_restart.sh @@ -0,0 +1,19 @@ +#!/bin/sh +#!/bin/bash + +# pull changes from the repo +git pull + +# Set the time threshold in seconds (6 hours = 21600 seconds) +time_threshold=21600 + +# Get the timestamp of the most recent commit +last_commit_time=$(git log -1 --format="%at") + +# Check if the last commit was within the time threshold +if [[ $(( $(date +%s) - last_commit_time )) -lt $time_threshold ]]; then + echo "Restarting..." + pm2 restart ecosystem.config.js +else + echo "There has been no commit. Will not restart." +fi diff --git a/ecosystem.config.js b/ecosystem.config.js new file mode 100644 index 0000000..51d90cb --- /dev/null +++ b/ecosystem.config.js @@ -0,0 +1,6 @@ +module.exports = { + apps : [{ + name : "Xantic", + script : "./index.js", + }] +}