NodeJS and Forever (monitoring and restarting app)

那年仲夏 提交于 2019-12-04 10:24:06

nodemon and forever are a pain to get running consistently. I would try using a shell script first. If you are on linux, just place a monitornode file in /etc/cron.d

*/1 * * * * root  /var/www/nodejs/monitornode.sh

and have a script somewhere on your machine

Try this if you are getting started, create a file /var/www/nodejs/monitornode.sh and chmod +x :

#!/bin/sh

TT_NODE="node /var/www/nodejs/node.js"

# NODEJS Watcher
if [ -z `pgrep -f -x "$TT_NODE"` ] 
then
    echo "Starting $TT_NODE."
    cmdNODE="$TT_NODE >> /var/www/logs/node.log &"
    eval $cmdNODE
fi

Check out the nodemon package to do the whole "reload on file change" thing.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!