如何使用cPanel重新启动NodeJS [英] How to restart NodeJS with cPanel

查看:124
本文介绍了如何使用cPanel重新启动NodeJS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要知道从基于cPanel的服务器的根端使用什么来重新启动NodeJS应用,例如,如果进程由于某种原因现在终止,那么在我手动启动NodeJS应用之前,它不会启动,如果服务器重新启动,则需要手动启动重新启动它.

I need to know what to use from root side of cPanel based server to restart NodeJS app, for example, if process terminated now for some reasons NodeJS app will not start until I manually start it, same if server restart I need manually to restart it.

此外,在服务器上有多个帐户的情况下,该命令应允许重新启动/启动更多应用.

Also, this is case for several accounts on server, command should allow more apps to be restarted/started.

任何帮助都会很棒

推荐答案

这是一种自动的方法:
-查找节点服务器[eq. server.js]是否正在运行.
-如果服务器未运行,请通过"nodemon server.js"重新启动.
-否则,如果服务器正在运行,则什么也不做.

Here is an automated way to do the it:
- Find if node server [eq. server.js] is running or not.
- If server is not running, restart by "nodemon server.js".
- Else if server is running, do nothing.

您可以在bash脚本中编写此代码(下面的示例代码),并在cpanel中设置一个CRON作业,以便在特定时间后运行它.

You can code this in bash script [sample code below] and set up a CRON job in your cpanel to run it after a particular time.

#!/bin/bash

NAME="server.js" # nodejs script's name here
RUN=`pgrep -f $NAME`

if [ "$RUN" == "" ]; then
  nodemon server.js
else
  echo "Script is running"
fi

这篇关于如何使用cPanel重新启动NodeJS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆