4

We are using iisnode with IIS 7.5 on a Windows 2008R2 Server. The node.js app loads some config data when it starts. From time to time the config data changes and the app needs to be restarted.

When restarting the IIS site instance by the Windows System Manager console everything works fine.

When restarting the IIS by appcmd stop and appcmd start commands the node.js-app is not launched again. It looks like iisnode does not recognize the restart of the IIS.

How can a node.js application in an iisnode environment be restarted by a command (i.e. via the command line)?

Sᴀᴍ Onᴇᴌᴀ
  • 8,218
  • 8
  • 36
  • 58
nitmws
  • 41
  • 1
  • 5

2 Answers2

8

You can automatically recycle the site through IISNode using the watchedFiles attribute on the iisnode element in your Web.config file. I know this isn't through the command line but from your question it seems like this would also solve the problem and not require any manual intervention from someone.

Using the below info, you can set IISNode to watch your config file(s) and whenever they changes IISNode will recycle the site.

Comment from IISNode Sample Config

watchedFiles - semi-colon separated list of files that will be watched for changes; a change to a file causes the application to recycle;

each entry consists of an optional directory name plus required file name which are relative to the directory where the main application entry point is located;

wild cards are allowed in the file name portion only; for example: "*.js;node_modules\foo\lib\options.json;app_data*.config.json"

Example iisnode element from Web.config that will recylce the site whenever the Web.config changes or any .js files in the top level folder of the app.

    <iisnode
        node_env="%node_env%"
        nodeProcessCountPerApplication="1"
        maxConcurrentRequestsPerProcess="1024"
        maxNamedPipeConnectionRetry="100"
        namedPipeConnectionRetryDelay="250"
        maxNamedPipeConnectionPoolSize="512"
        maxNamedPipePooledConnectionAge="30000"
        asyncCompletionThreadCount="0"
        initialRequestBufferSize="4096"
        maxRequestBufferSize="65536"
        uncFileChangesPollingInterval="5000"
        gracefulShutdownTimeout="60000"
        loggingEnabled="true"
        logDirectory="iisnode"
        debuggingEnabled="true"
        debugHeaderEnabled="false"
        debuggerPortRange="5058-6058"
        debuggerPathSegment="debug"
        maxLogFileSizeInKB="128"
        maxTotalLogFileSizeInKB="1024"
        maxLogFiles="20"
        devErrorsEnabled="true"
        flushResponse="false"
        enableXFF="false"
        promoteServerVars=""
        configOverrides="iisnode.yml"
        watchedFiles="web.config;*.js"                    
        nodeProcessCommandLine="C:\Program Files (x86)\nodejs\node.exe" />
peteb
  • 18,552
  • 9
  • 50
  • 62
  • I'm aware of the watchedFiles but its shortcoming is that it only watches files under the root folder of the web site. In our case the file which should trigger a restart is located outside this root folder. By the watchedFiles specs at https://github.com/tjanczuk/iisnode/blob/master/src/samples/configuration/web.config this location could not be watched. – nitmws Jan 22 '16 at 13:26
0

appcmd can do this for you, but you need to recycle the Application Pool, not the Site. A command I use to do this successfully in a bat file looks like:

%windir%\system32\inetsrv\appcmd recycle apppool /apppool.name:"Your Application Pool Name"