Jump to content

Recommended Posts

23 minutes ago, Remos said:

@MURASAKI. Please can you send the auto restart nodejs cron jobs 

 

6 minutes ago, Unicode said:

Just upload and open your url.

Cron job for restart nodejs on hosting is imposible. You can do it if using vps

Sory for late reply, i was handle to many damn request for my work.


I never using and test on cpanel on shared hosting, maybe this guide to help "auto restart nodejs cron jobs" with aaPanel based on my case:
---
1. Create Script Restart: restart-node.sh on your directory

#!/bin/bash

# Path ke direktori aplikasi Node.js
APP_DIR="/www/wwwroot/yourwebsite.com/mpwa"

# Nama file utama aplikasi Node.js (misalnya server.js)
APP_SCRIPT="yourjsfile.js"

# Ganti direktori ke aplikasi
cd $APP_DIR

# Cari PID (Process ID) dari aplikasi yang sedang berjalan
PID=$(ps aux | grep $APP_SCRIPT | grep -v grep | awk '{print $2}')

# Jika PID ditemukan, matikan proses
if [ -n "$PID" ]; then
  kill -9 $PID
  echo "Proses Node.js dengan PID $PID dihentikan."
else
  echo "Proses Node.js tidak ditemukan, aplikasi mungkin belum berjalan."
fi

# Mulai kembali aplikasi Node.js di background
nohup node $APP_SCRIPT > app.log 2>&1 &
echo "Aplikasi Node.js telah dimulai kembali."

2. Create Cron Job: restart-node.sh | Setup Every  1 Hours

/bin/bash /www/wwwroot/yourwebsite.com/yourapps/restart-node.sh

Thats it.

Is there a solution for share hosting users..?
Node.js often sleeps when there is no message activity for more than 3 minutes
therefore I have to use API to send messages to a certain number every minute to keep node.js alive

Please tell me guys

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
  • Create New...