linux运维 - node.js服务器开机启动失败,手动启动成功
怪我咯
怪我咯 2017-04-17 11:45:28
[Node.js讨论组]

用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,但是我开机后手动运行脚本并没有问题啊,求大神指导

怪我咯
怪我咯

走同样的路,发现不同的人生

全部回复(1)
黄舟

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

start() {
        cd /home/GitHub/fpms/
        forever start server.js >> $log_file &
        action "Strating $prog" /bin/true
        return 0
}
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号