首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >当nodejs应用通过Apache托管时,如何重启nodejs服务器以应用更改

问当nodejs应用通过Apache托管时,如何重启nodejs服务器以应用更改
EN

Stack Overflow用户
提问于 2015-01-12 17:25:16
回答 1查看 597关注 0票数 0

我使用apache服务器根据特定域的请求重定向到NodeJS服务器。但是当我在js代码(服务器代码)中添加一些函数时,它显示类似于“未定义”之类的内容,甚至我试图重启apache服务器,并终止了所有与节点相关的进程。

我现在该怎么做?

EN

回答 1

Stack Overflow用户

发布于 2015-01-12 23:32:14

使用forever运行您的节点服务器。还有其他的监控库。

其想法是,当文件发生变化(可以被列入白名单)时,应用程序将重新启动。如果通过Apache传递流量,则需要此选项,因为重启Apache不会重启Node应用程序,而Node应用程序需要重启才能读取您的更改。

我使用这样的脚本在forever中启动我的应用程序,在使用node start.js进行开发期间或在生产环境中使用它,并使用一些环境变量来配置我的Node,以及一个“启动时”服务,以便它在机器启动时运行(我使用upstart)。

代码语言:javascript
复制
/*jslint node: true */
"use strict";

/**
 * File to start using forever, logs crashes, restarts on file changes, etc.
 */

var cmd = ( process.env.DBG ? "node --debug" : "node" );

var forever = require( 'forever' ),
  //exec = require('child_process').exec,
  child = new( forever.Monitor )( 'node', {
    'silent': false,
    'pidFile': 'pids/forever-app.pid',
    'watch': true,
    'command': cmd,
    'args': ['app.js' ],
    //"max" : 10,
    'watchDirectory': './', // Top-level directory to watch from.
    'watchIgnoreDotFiles': true, // whether to ignore dot files
    'watchIgnorePatterns': [ 'log/*', 'node_modules/*', 'pids/*',
                              'dbscripts/*', 'test/*',
                              'curlcookies',
                              '.svn/*', ], // array of glob patterns to ignore, merged with contents of watchDirectory + '/.foreverignore' file
    'logFile': 'log/forever.log', // Path to log output from forever process (when daemonized)
    //'outFile': 'logs/ijoin-forever.out', // Path to log output from child stdout
    'errFile': 'log/forever.err'
  } );

child.on( "exit", function() {
  console.log( 'app.js has exited!' );
} );
child.on( "restart", function() {
  console.log( 'app.js has restarted.' );
} );
child.on( 'watch:restart', function( info ) {
  console.error( 'Restaring script because ' + info.file + ' changed' );
} );

child.start();
forever.startServer( child );

process.on( 'SIGINT', function() {
  console.log( "\nGracefully shutting down \'node forever\' from SIGINT (Ctrl-C)" );
  // some other closing procedures go here
  process.exit();
} );

process.on( 'exit', function() {
  console.log( 'About to exit \'node forever\' process.' );
} );

process.on( 'uncaughtException', function( err ) {
  console.log( 'Caught exception in \'node forever\': ' + err );
} );
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27898721

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档