node.js服务器开机启动失败,手动启动成功

发布于 2022-09-01 12:00:48 字数 2963 浏览 12 评论 0

用node.js搭建了一个服务器,并且写成了linux的一个service,开机运行,但是发现启动日志里面是失败的,手动运行service nodeserver start又成功了。
我的系统环境是centOS 5.7

这是/etc/init.d/nodeserver

#!/bin/bash
#
# chkconfig: 345 99 90
# description: this is a node server start script
#
# processname: node server
#
# Source function library.
. /etc/rc.d/init.d/functions
prog="node server"
RETVAL=0

log_file=/var/log/nodeserver.log
source /etc/profile

start() {
        cd /home/GitHub/fpms/
        daemon node server >> $log_file &
        action "Strating $prog" /bin/true
        return 0
}

stop() {
        echo -n "Stop $prog"
        killproc $prog
        RETVAL=$?
        echo
}

case "$1" in
start)
        if [ $# -eq 2 ];then
                export NODE_ENV=$2
                start
        else
                export NODE_ENV=production
                start
                echo "usage:$0 start [production|development|test]|stop|restart [production|development|test]|status default production"
        fi
        ;;
stop)
        stop
        ;;
restart)
        if [ $# -eq 2 ];then
                export NODE_ENV=$2
                stop
                start
        else
                echo "usage:$0 start [production|development|test]|stop|restart [production|development|test]|status"
        fi
        ;;
status)
        status $prog
        RETVAL=$?
        ;;
*)
        echo "usage:$0 start [production|development|test]|stop|restart [production|development|test]|status"
        echo 0;
esac

exit 0

下面是开机后看到的日志

Application loaded using the "production" environment configuration
{ [Error: Cannot find module '../build/Release/bson'] code: 'MODULE_NOT_FOUND' }
宿主启动...
FPMS started on port 3000 and process.env.NODE_ENV = production
^[[60G[^[[0;31mFAILED^[[0;39m]^MApplication loaded using the "production" environment configuration
Application loaded using the "production" environment configuration
Application loaded using the "production" environment configuration
Application loaded using the "production" environment configuration
Application loaded using the "production" environment configuration
Application loaded using the "production" environment configuration
Application loaded using the "production" environment configuration
Application loaded using the "production" environment configuration
Application loaded using the "production" environment configuration
Application loaded using the "production" environment configuration
Application loaded using the "production" environment configuration
Application loaded using the "production" environment configuration
Application loaded using the "production" environment configuration
Application loaded using the "production" environment configuration
Application loaded using the "production" environment configuration
Application loaded using the "production" environment configuration

日志中出现了FAILED,但是我开机后手动运行脚本并没有问题啊,求大神指导

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

那片花海 2022-09-08 12:00:48

搞定了
用npm install forever
然后修改nodeserver 那个service脚本的start函数为下面这个

start() {
        cd /home/GitHub/fpms/
        forever start server.js >> $log_file &
        action "Strating $prog" /bin/true
        return 0
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文