用于每两小时使用 Gulp 启动一个 Node.js 应用程序的 Shell 脚本

用于每两小时使用 Gulp 启动一个 Node.js 应用程序的 Shell 脚本

我是 Linux 上的 Shell 脚本新手,想编写一个每两个小时运行一次的 shell 脚本,检查端口 3001 上是否有服务正在运行,如果没有,则重新启动该服务,在本例中是一个带有 Gulp 的 Node.js 应用程序。

我需要每2小时运行一次这个shell脚本,以检查应用程序是否仍在运行,如果没有,则重新启动应用程序,因为运行应用程序的虚拟服务器环境不稳定并且不时关闭没原因。

所以Shell脚本必须包含命令“gulpserve”。它应该在 Node 应用程序的文件夹中运行,并且就像一个人在项目文件夹中通过命令行输入命令“gulpserve”一样。最好的方法是什么?任何提示和评论将不胜感激,谢谢!

这是我迄今为止发现的起点:

#!/bin/bash

###edit the following
service=Node.js
[email protected]
###stop editing

host=`hostname -f`
if (( $(ps -ef | grep -v grep | grep $service | wc -l) > 0 ))
then
echo "$service is running"
else
/etc/init.d/$service start
if (( $(ps -ef | grep -v grep | grep $service | wc -l) > 0 ))
then
subject="$service at $host has been started"
echo "$service at $host wasn't running and has been started" | mail -s "$subject" $email
else
subject="$service at $host is not running"
echo "$service at $host is stopped and cannot be started!!!" | mail -s "$subject" $email
fi
fi

相关内容